1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-20 13:52:40 +01:00

Add "Any User Projects" to Maniphest Custom Query

Summary: Added a new way of filtering projects in Maniphest custom queries. This will filter on any project that a user is associated with.

Test Plan:
- Create some tasks.
- Create a project (auto join).
- Add the project to some of the tasks.
- Run custom query, see the correct task.
- Save custom query, check the same tasks are there.
- Add the project to another task, check task was added in the custom query list view.
- Remove the project from a task and check the task disappeared from the custom query list view.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5570
This commit is contained in:
Gareth Evans 2013-04-04 10:29:40 -07:00 committed by epriestley
parent 74609d9366
commit 81377dd922
2 changed files with 74 additions and 21 deletions

View file

@ -8,16 +8,17 @@
*/
final class ManiphestTaskQuery extends PhabricatorQuery {
private $taskIDs = array();
private $taskPHIDs = array();
private $authorPHIDs = array();
private $ownerPHIDs = array();
private $includeUnowned = null;
private $projectPHIDs = array();
private $xprojectPHIDs = array();
private $subscriberPHIDs = array();
private $anyProjectPHIDs = array();
private $includeNoProject = null;
private $taskIDs = array();
private $taskPHIDs = array();
private $authorPHIDs = array();
private $ownerPHIDs = array();
private $includeUnowned = null;
private $projectPHIDs = array();
private $xprojectPHIDs = array();
private $subscriberPHIDs = array();
private $anyProjectPHIDs = array();
private $anyUserProjectPHIDs = array();
private $includeNoProject = null;
private $fullTextSearch = '';
@ -183,6 +184,11 @@ final class ManiphestTaskQuery extends PhabricatorQuery {
return $this;
}
public function withAnyUserProjects(array $users) {
$this->anyUserProjectPHIDs = $users;
return $this;
}
public function execute() {
$task_dao = new ManiphestTask();
@ -204,6 +210,7 @@ final class ManiphestTaskQuery extends PhabricatorQuery {
$where[] = $this->buildSubscriberWhereClause($conn);
$where[] = $this->buildProjectWhereClause($conn);
$where[] = $this->buildAnyProjectWhereClause($conn);
$where[] = $this->buildAnyUserProjectWhereClause($conn);
$where[] = $this->buildXProjectWhereClause($conn);
$where[] = $this->buildFullTextWhereClause($conn);
@ -475,8 +482,26 @@ final class ManiphestTaskQuery extends PhabricatorQuery {
$this->anyProjectPHIDs);
}
private function buildAnyUserProjectWhereClause(
AphrontDatabaseConnection $conn) {
if (!$this->anyUserProjectPHIDs) {
return null;
}
$projects = id(new PhabricatorProjectQuery())
->setViewer($this->viewer)
->withMemberPHIDs($this->anyUserProjectPHIDs)
->execute();
$any_user_project_phids = mpull($projects, 'getPHID');
return qsprintf(
$conn,
'anyproject.projectPHID IN (%Ls)',
$any_user_project_phids);
}
private function buildAnyProjectJoinClause(AphrontDatabaseConnection $conn) {
if (!$this->anyProjectPHIDs) {
if (!$this->anyProjectPHIDs && !$this->anyUserProjectPHIDs) {
return null;
}

View file

@ -37,16 +37,17 @@ final class ManiphestTaskListController extends ManiphestController {
$max_priority = $request->getInt('set_hpriority');
$uri = $request->getRequestURI()
->alter('users', $this->getArrToStrList('set_users'))
->alter('projects', $this->getArrToStrList('set_projects'))
->alter('aprojects', $this->getArrToStrList('set_aprojects'))
->alter('xprojects', $this->getArrToStrList('set_xprojects'))
->alter('owners', $this->getArrToStrList('set_owners'))
->alter('authors', $this->getArrToStrList('set_authors'))
->alter('lpriority', $min_priority)
->alter('hpriority', $max_priority)
->alter('tasks', $task_ids)
->alter('search', $search_text);
->alter('users', $this->getArrToStrList('set_users'))
->alter('projects', $this->getArrToStrList('set_projects'))
->alter('aprojects', $this->getArrToStrList('set_aprojects'))
->alter('useraprojects', $this->getArrToStrList('set_useraprojects'))
->alter('xprojects', $this->getArrToStrList('set_xprojects'))
->alter('owners', $this->getArrToStrList('set_owners'))
->alter('authors', $this->getArrToStrList('set_authors'))
->alter('lpriority', $min_priority)
->alter('hpriority', $max_priority)
->alter('tasks', $task_ids)
->alter('search', $search_text);
return id(new AphrontRedirectResponse())->setURI($uri);
}
@ -105,6 +106,9 @@ final class ManiphestTaskListController extends ManiphestController {
$any_project_phids = $query->getParameter(
'anyProjectPHIDs',
array());
$any_user_project_phids = $query->getParameter(
'anyUserProjectPHIDs',
array());
$exclude_project_phids = $query->getParameter(
'excludeProjectPHIDs',
array());
@ -215,6 +219,19 @@ final class ManiphestTaskListController extends ManiphestController {
->setCaption(pht('Find tasks in ANY of these projects ("OR" query).'))
->setValue($atokens));
$tokens = array();
foreach ($any_user_project_phids as $phid) {
$tokens[$phid] = $handles[$phid]->getFullName();
}
$form->appendChild(
id(new AphrontFormTokenizerControl())
->setDatasource('/typeahead/common/users/')
->setName('set_useraprojects')
->setLabel(pht('Any User Projects'))
->setCaption(
pht('Find tasks in ANY of these users\' projects ("OR" query).'))
->setValue($tokens));
$tokens = array();
foreach ($exclude_project_phids as $phid) {
$tokens[$phid] = $handles[$phid]->getFullName();
@ -427,6 +444,9 @@ final class ManiphestTaskListController extends ManiphestController {
$any_project_phids = $search_query->getParameter(
'anyProjectPHIDs',
array());
$any_user_project_phids = $search_query->getParameter(
'anyUserProjectPHIDs',
array());
$xproject_phids = $search_query->getParameter(
'excludeProjectPHIDs',
array());
@ -463,6 +483,11 @@ final class ManiphestTaskListController extends ManiphestController {
$query->withAuthors($author_phids);
}
if ($any_user_project_phids) {
$query->setViewer($viewer);
$query->withAnyUserProjects($any_user_project_phids);
}
$status = $search_query->getParameter('status', 'all');
if (!empty($status['open']) && !empty($status['closed'])) {
$query->withStatus(ManiphestTaskQuery::STATUS_ANY);
@ -740,8 +765,10 @@ final class ManiphestTaskListController extends ManiphestController {
->withMemberPHIDs($user_phids)
->execute();
$any_project_phids = mpull($projects, 'getPHID');
$any_user_project_phids = array();
} else {
$any_project_phids = $request->getStrList('aprojects');
$any_user_project_phids = $request->getStrList('useraprojects');
}
$project_phids = $request->getStrList('projects');
@ -787,6 +814,7 @@ final class ManiphestTaskListController extends ManiphestController {
'userPHIDs' => $user_phids,
'projectPHIDs' => $project_phids,
'anyProjectPHIDs' => $any_project_phids,
'anyUserProjectPHIDs' => $any_user_project_phids,
'excludeProjectPHIDs' => $exclude_project_phids,
'ownerPHIDs' => $owner_phids,
'authorPHIDs' => $author_phids,