1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 22:10:55 +01:00

Add an anyone() typeahead function for matching any document owner

Summary: Fixes T5733.

Test Plan: Ran search and Maniphest queries.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T5733

Differential Revision: https://secure.phabricator.com/D12535
This commit is contained in:
epriestley 2015-04-23 15:44:27 -07:00
parent e40aa8f782
commit 3ba56ceaf0
7 changed files with 119 additions and 24 deletions

View file

@ -2188,6 +2188,7 @@ phutil_register_library_map(array(
'PhabricatorPasteTransactionQuery' => 'applications/paste/query/PhabricatorPasteTransactionQuery.php', 'PhabricatorPasteTransactionQuery' => 'applications/paste/query/PhabricatorPasteTransactionQuery.php',
'PhabricatorPasteViewController' => 'applications/paste/controller/PhabricatorPasteViewController.php', 'PhabricatorPasteViewController' => 'applications/paste/controller/PhabricatorPasteViewController.php',
'PhabricatorPathSetupCheck' => 'applications/config/check/PhabricatorPathSetupCheck.php', 'PhabricatorPathSetupCheck' => 'applications/config/check/PhabricatorPathSetupCheck.php',
'PhabricatorPeopleAnyOwnerDatasource' => 'applications/people/typeahead/PhabricatorPeopleAnyOwnerDatasource.php',
'PhabricatorPeopleApplication' => 'applications/people/application/PhabricatorPeopleApplication.php', 'PhabricatorPeopleApplication' => 'applications/people/application/PhabricatorPeopleApplication.php',
'PhabricatorPeopleApproveController' => 'applications/people/controller/PhabricatorPeopleApproveController.php', 'PhabricatorPeopleApproveController' => 'applications/people/controller/PhabricatorPeopleApproveController.php',
'PhabricatorPeopleCalendarController' => 'applications/people/controller/PhabricatorPeopleCalendarController.php', 'PhabricatorPeopleCalendarController' => 'applications/people/controller/PhabricatorPeopleCalendarController.php',
@ -5560,6 +5561,7 @@ phutil_register_library_map(array(
'PhabricatorPasteTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 'PhabricatorPasteTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'PhabricatorPasteViewController' => 'PhabricatorPasteController', 'PhabricatorPasteViewController' => 'PhabricatorPasteController',
'PhabricatorPathSetupCheck' => 'PhabricatorSetupCheck', 'PhabricatorPathSetupCheck' => 'PhabricatorSetupCheck',
'PhabricatorPeopleAnyOwnerDatasource' => 'PhabricatorTypeaheadDatasource',
'PhabricatorPeopleApplication' => 'PhabricatorApplication', 'PhabricatorPeopleApplication' => 'PhabricatorApplication',
'PhabricatorPeopleApproveController' => 'PhabricatorPeopleController', 'PhabricatorPeopleApproveController' => 'PhabricatorPeopleController',
'PhabricatorPeopleCalendarController' => 'PhabricatorPeopleController', 'PhabricatorPeopleCalendarController' => 'PhabricatorPeopleController',

View file

@ -10,7 +10,8 @@ final class ManiphestTaskQuery extends PhabricatorCursorPagedPolicyAwareQuery {
private $taskPHIDs = array(); private $taskPHIDs = array();
private $authorPHIDs = array(); private $authorPHIDs = array();
private $ownerPHIDs = array(); private $ownerPHIDs = array();
private $includeUnowned = null; private $noOwner;
private $anyOwner;
private $subscriberPHIDs = array(); private $subscriberPHIDs = array();
private $dateCreatedAfter; private $dateCreatedAfter;
private $dateCreatedBefore; private $dateCreatedBefore;
@ -70,11 +71,16 @@ final class ManiphestTaskQuery extends PhabricatorCursorPagedPolicyAwareQuery {
public function withOwners(array $owners) { public function withOwners(array $owners) {
$no_owner = PhabricatorPeopleNoOwnerDatasource::FUNCTION_TOKEN; $no_owner = PhabricatorPeopleNoOwnerDatasource::FUNCTION_TOKEN;
$any_owner = PhabricatorPeopleAnyOwnerDatasource::FUNCTION_TOKEN;
$this->includeUnowned = false;
foreach ($owners as $k => $phid) { foreach ($owners as $k => $phid) {
if ($phid === $no_owner || $phid === null) { if ($phid === $no_owner || $phid === null) {
$this->includeUnowned = true; $this->noOwner = true;
unset($owners[$k]);
break;
}
if ($phid === $any_owner) {
$this->anyOwner = true;
unset($owners[$k]); unset($owners[$k]);
break; break;
} }
@ -512,31 +518,32 @@ final class ManiphestTaskQuery extends PhabricatorCursorPagedPolicyAwareQuery {
} }
private function buildOwnerWhereClause(AphrontDatabaseConnection $conn) { private function buildOwnerWhereClause(AphrontDatabaseConnection $conn) {
if (!$this->ownerPHIDs) { $subclause = array();
if ($this->includeUnowned === null) {
return null; if ($this->noOwner) {
} else if ($this->includeUnowned) { $subclause[] = qsprintf(
return qsprintf( $conn,
$conn, 'task.ownerPHID IS NULL');
'task.ownerPHID IS NULL');
} else {
return qsprintf(
$conn,
'task.ownerPHID IS NOT NULL');
}
} }
if ($this->includeUnowned) { if ($this->anyOwner) {
return qsprintf( $subclause[] = qsprintf(
$conn, $conn,
'task.ownerPHID IN (%Ls) OR task.ownerPHID IS NULL', 'task.ownerPHID IS NOT NULL');
$this->ownerPHIDs); }
} else {
return qsprintf( if ($this->ownerPHIDs) {
$subclause[] = qsprintf(
$conn, $conn,
'task.ownerPHID IN (%Ls)', 'task.ownerPHID IN (%Ls)',
$this->ownerPHIDs); $this->ownerPHIDs);
} }
if (!$subclause) {
return '';
}
return '('.implode(') OR (', $subclause).')';
} }
private function buildFullTextWhereClause(AphrontDatabaseConnection $conn) { private function buildFullTextWhereClause(AphrontDatabaseConnection $conn) {

View file

@ -0,0 +1,68 @@
<?php
final class PhabricatorPeopleAnyOwnerDatasource
extends PhabricatorTypeaheadDatasource {
const FUNCTION_TOKEN = 'anyone()';
public function getBrowseTitle() {
return pht('Browse Any Owner');
}
public function getPlaceholderText() {
return pht('Type "anyone()"...');
}
public function getDatasourceApplicationClass() {
return 'PhabricatorPeopleApplication';
}
public function getDatasourceFunctions() {
return array(
'anyone' => array(
'name' => pht('Anyone'),
'summary' => pht('Find results which are assigned to anyone.'),
'description' => pht(
'This function includes results which have any owner. It excludes '.
'unassigned or unowned results.'),
),
);
}
public function loadResults() {
$results = array(
$this->buildAnyoneResult(),
);
return $this->filterResultsAgainstTokens($results);
}
protected function evaluateFunction($function, array $argv_list) {
$results = array();
foreach ($argv_list as $argv) {
$results[] = self::FUNCTION_TOKEN;
}
return $results;
}
public function renderFunctionTokens($function, array $argv_list) {
$results = array();
foreach ($argv_list as $argv) {
$results[] = PhabricatorTypeaheadTokenView::newFromTypeaheadResult(
$this->buildAnyoneResult());
}
return $results;
}
private function buildAnyoneResult() {
$name = pht('Any Owner');
return $this->newFunctionResult()
->setName($name.' anyone')
->setDisplayName($name)
->setIcon('fa-certificate')
->setPHID(self::FUNCTION_TOKEN)
->setUnique(true);
}
}

View file

@ -15,6 +15,7 @@ final class PhabricatorPeopleOwnerDatasource
return array( return array(
new PhabricatorViewerDatasource(), new PhabricatorViewerDatasource(),
new PhabricatorPeopleNoOwnerDatasource(), new PhabricatorPeopleNoOwnerDatasource(),
new PhabricatorPeopleAnyOwnerDatasource(),
new PhabricatorPeopleDatasource(), new PhabricatorPeopleDatasource(),
new PhabricatorProjectMembersDatasource(), new PhabricatorProjectMembersDatasource(),
); );

View file

@ -125,8 +125,6 @@ final class PhabricatorSearchEngineElastic extends PhabricatorSearchEngine {
$relationship_map = array( $relationship_map = array(
PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR => PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR =>
$query->getParameter('authorPHIDs', array()), $query->getParameter('authorPHIDs', array()),
PhabricatorSearchRelationship::RELATIONSHIP_OWNER =>
$query->getParameter('ownerPHIDs', array()),
PhabricatorSearchRelationship::RELATIONSHIP_SUBSCRIBER => PhabricatorSearchRelationship::RELATIONSHIP_SUBSCRIBER =>
$query->getParameter('subscriberPHIDs', array()), $query->getParameter('subscriberPHIDs', array()),
PhabricatorSearchRelationship::RELATIONSHIP_PROJECT => PhabricatorSearchRelationship::RELATIONSHIP_PROJECT =>
@ -155,6 +153,14 @@ final class PhabricatorSearchEngineElastic extends PhabricatorSearchEngine {
$relationship_map[$rel_unowned] = true; $relationship_map[$rel_unowned] = true;
} }
$rel_owner = PhabricatorSearchRelationship::RELATIONSHIP_OWNER;
if ($query->getParameter('withAnyOwner')) {
$relationship_map[$rel_owner] = true;
} else {
$owner_phids = $query->getParameter('ownerPHIDs', array());
$relationship_map[$rel_owner] = $owner_phids;
}
foreach ($relationship_map as $field => $param) { foreach ($relationship_map as $field => $param) {
if (is_array($param) && $param) { if (is_array($param) && $param) {
$should = array(); $should = array();

View file

@ -231,7 +231,14 @@ final class PhabricatorSearchEngineMySQL extends PhabricatorSearchEngine {
true); true);
} }
if ($query->getParameter('withUnowned')) { if ($query->getParameter('withAnyOwner')) {
$join[] = $this->joinRelationship(
$conn_r,
$query,
'withAnyOwner',
PhabricatorSearchRelationship::RELATIONSHIP_OWNER,
true);
} else if ($query->getParameter('withUnowned')) {
$join[] = $this->joinRelationship( $join[] = $this->joinRelationship(
$conn_r, $conn_r,
$query, $query,

View file

@ -58,6 +58,10 @@ final class PhabricatorSearchApplicationSearchEngine
$config->setParameter('withUnowned', true); $config->setParameter('withUnowned', true);
unset($owner_phids[$key]); unset($owner_phids[$key]);
} }
if ($phid == PhabricatorPeopleAnyOwnerDatasource::FUNCTION_TOKEN) {
$config->setParameter('withAnyOwner', true);
unset($owner_phids[$key]);
}
} }
$config->setParameter('ownerPHIDs', $owner_phids); $config->setParameter('ownerPHIDs', $owner_phids);