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:
parent
e40aa8f782
commit
3ba56ceaf0
7 changed files with 119 additions and 24 deletions
|
@ -2188,6 +2188,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPasteTransactionQuery' => 'applications/paste/query/PhabricatorPasteTransactionQuery.php',
|
||||
'PhabricatorPasteViewController' => 'applications/paste/controller/PhabricatorPasteViewController.php',
|
||||
'PhabricatorPathSetupCheck' => 'applications/config/check/PhabricatorPathSetupCheck.php',
|
||||
'PhabricatorPeopleAnyOwnerDatasource' => 'applications/people/typeahead/PhabricatorPeopleAnyOwnerDatasource.php',
|
||||
'PhabricatorPeopleApplication' => 'applications/people/application/PhabricatorPeopleApplication.php',
|
||||
'PhabricatorPeopleApproveController' => 'applications/people/controller/PhabricatorPeopleApproveController.php',
|
||||
'PhabricatorPeopleCalendarController' => 'applications/people/controller/PhabricatorPeopleCalendarController.php',
|
||||
|
@ -5560,6 +5561,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPasteTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||
'PhabricatorPasteViewController' => 'PhabricatorPasteController',
|
||||
'PhabricatorPathSetupCheck' => 'PhabricatorSetupCheck',
|
||||
'PhabricatorPeopleAnyOwnerDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||
'PhabricatorPeopleApplication' => 'PhabricatorApplication',
|
||||
'PhabricatorPeopleApproveController' => 'PhabricatorPeopleController',
|
||||
'PhabricatorPeopleCalendarController' => 'PhabricatorPeopleController',
|
||||
|
|
|
@ -10,7 +10,8 @@ final class ManiphestTaskQuery extends PhabricatorCursorPagedPolicyAwareQuery {
|
|||
private $taskPHIDs = array();
|
||||
private $authorPHIDs = array();
|
||||
private $ownerPHIDs = array();
|
||||
private $includeUnowned = null;
|
||||
private $noOwner;
|
||||
private $anyOwner;
|
||||
private $subscriberPHIDs = array();
|
||||
private $dateCreatedAfter;
|
||||
private $dateCreatedBefore;
|
||||
|
@ -70,11 +71,16 @@ final class ManiphestTaskQuery extends PhabricatorCursorPagedPolicyAwareQuery {
|
|||
|
||||
public function withOwners(array $owners) {
|
||||
$no_owner = PhabricatorPeopleNoOwnerDatasource::FUNCTION_TOKEN;
|
||||
$any_owner = PhabricatorPeopleAnyOwnerDatasource::FUNCTION_TOKEN;
|
||||
|
||||
$this->includeUnowned = false;
|
||||
foreach ($owners as $k => $phid) {
|
||||
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]);
|
||||
break;
|
||||
}
|
||||
|
@ -512,31 +518,32 @@ final class ManiphestTaskQuery extends PhabricatorCursorPagedPolicyAwareQuery {
|
|||
}
|
||||
|
||||
private function buildOwnerWhereClause(AphrontDatabaseConnection $conn) {
|
||||
if (!$this->ownerPHIDs) {
|
||||
if ($this->includeUnowned === null) {
|
||||
return null;
|
||||
} else if ($this->includeUnowned) {
|
||||
return qsprintf(
|
||||
$conn,
|
||||
'task.ownerPHID IS NULL');
|
||||
} else {
|
||||
return qsprintf(
|
||||
$conn,
|
||||
'task.ownerPHID IS NOT NULL');
|
||||
}
|
||||
$subclause = array();
|
||||
|
||||
if ($this->noOwner) {
|
||||
$subclause[] = qsprintf(
|
||||
$conn,
|
||||
'task.ownerPHID IS NULL');
|
||||
}
|
||||
|
||||
if ($this->includeUnowned) {
|
||||
return qsprintf(
|
||||
if ($this->anyOwner) {
|
||||
$subclause[] = qsprintf(
|
||||
$conn,
|
||||
'task.ownerPHID IN (%Ls) OR task.ownerPHID IS NULL',
|
||||
$this->ownerPHIDs);
|
||||
} else {
|
||||
return qsprintf(
|
||||
'task.ownerPHID IS NOT NULL');
|
||||
}
|
||||
|
||||
if ($this->ownerPHIDs) {
|
||||
$subclause[] = qsprintf(
|
||||
$conn,
|
||||
'task.ownerPHID IN (%Ls)',
|
||||
$this->ownerPHIDs);
|
||||
}
|
||||
|
||||
if (!$subclause) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return '('.implode(') OR (', $subclause).')';
|
||||
}
|
||||
|
||||
private function buildFullTextWhereClause(AphrontDatabaseConnection $conn) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -15,6 +15,7 @@ final class PhabricatorPeopleOwnerDatasource
|
|||
return array(
|
||||
new PhabricatorViewerDatasource(),
|
||||
new PhabricatorPeopleNoOwnerDatasource(),
|
||||
new PhabricatorPeopleAnyOwnerDatasource(),
|
||||
new PhabricatorPeopleDatasource(),
|
||||
new PhabricatorProjectMembersDatasource(),
|
||||
);
|
||||
|
|
|
@ -125,8 +125,6 @@ final class PhabricatorSearchEngineElastic extends PhabricatorSearchEngine {
|
|||
$relationship_map = array(
|
||||
PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR =>
|
||||
$query->getParameter('authorPHIDs', array()),
|
||||
PhabricatorSearchRelationship::RELATIONSHIP_OWNER =>
|
||||
$query->getParameter('ownerPHIDs', array()),
|
||||
PhabricatorSearchRelationship::RELATIONSHIP_SUBSCRIBER =>
|
||||
$query->getParameter('subscriberPHIDs', array()),
|
||||
PhabricatorSearchRelationship::RELATIONSHIP_PROJECT =>
|
||||
|
@ -155,6 +153,14 @@ final class PhabricatorSearchEngineElastic extends PhabricatorSearchEngine {
|
|||
$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) {
|
||||
if (is_array($param) && $param) {
|
||||
$should = array();
|
||||
|
|
|
@ -231,7 +231,14 @@ final class PhabricatorSearchEngineMySQL extends PhabricatorSearchEngine {
|
|||
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(
|
||||
$conn_r,
|
||||
$query,
|
||||
|
|
|
@ -58,6 +58,10 @@ final class PhabricatorSearchApplicationSearchEngine
|
|||
$config->setParameter('withUnowned', true);
|
||||
unset($owner_phids[$key]);
|
||||
}
|
||||
if ($phid == PhabricatorPeopleAnyOwnerDatasource::FUNCTION_TOKEN) {
|
||||
$config->setParameter('withAnyOwner', true);
|
||||
unset($owner_phids[$key]);
|
||||
}
|
||||
}
|
||||
$config->setParameter('ownerPHIDs', $owner_phids);
|
||||
|
||||
|
|
Loading…
Reference in a new issue