mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Use a policy-aware query in PhabricatorSearchSelectController
Summary: Ref T603. This didn't impact policies anyway, but using PhabricatorObjectQuery is far simpler and more general. Test Plan: Used "Attach" dialog to find mocks, tasks, and revisions by "Dxx", "Mxx", etc. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T603 Differential Revision: https://secure.phabricator.com/D7195
This commit is contained in:
parent
ea5bc2efac
commit
901bdda6b1
1 changed files with 7 additions and 49 deletions
|
@ -62,57 +62,15 @@ final class PhabricatorSearchSelectController
|
||||||
}
|
}
|
||||||
|
|
||||||
private function queryObjectNames($query) {
|
private function queryObjectNames($query) {
|
||||||
|
$viewer = $this->getRequest()->getUser();
|
||||||
|
|
||||||
$pattern = null;
|
$objects = id(new PhabricatorObjectQuery())
|
||||||
switch ($this->type) {
|
->setViewer($viewer)
|
||||||
case ManiphestPHIDTypeTask::TYPECONST:
|
->withTypes(array($this->type))
|
||||||
$pattern = '/\bT(\d+)\b/i';
|
->withNames(array($query))
|
||||||
break;
|
->execute();
|
||||||
case DifferentialPHIDTypeRevision::TYPECONST:
|
|
||||||
$pattern = '/\bD(\d+)\b/i';
|
|
||||||
break;
|
|
||||||
case PholioPHIDTypeMock::TYPECONST:
|
|
||||||
$pattern = '/\bM(\d+)\b/i';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$pattern) {
|
return mpull($objects, 'getPHID');
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
$matches = array();
|
|
||||||
preg_match_all($pattern, $query, $matches);
|
|
||||||
if (!$matches) {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
$object_ids = $matches[1];
|
|
||||||
if (!$object_ids) {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ($this->type) {
|
|
||||||
case DifferentialPHIDTypeRevision::TYPECONST:
|
|
||||||
// TODO: (T603) See below. This whole thing needs cleanup.
|
|
||||||
$objects = id(new DifferentialRevision())->loadAllWhere(
|
|
||||||
'id IN (%Ld)',
|
|
||||||
$object_ids);
|
|
||||||
break;
|
|
||||||
case ManiphestPHIDTypeTask::TYPECONST:
|
|
||||||
// TODO: (T603) Clean this up. This should probably all run through
|
|
||||||
// ObjectQuery?
|
|
||||||
$objects = id(new ManiphestTask())->loadAllWhere(
|
|
||||||
'id IN (%Ld)',
|
|
||||||
$object_ids);
|
|
||||||
break;
|
|
||||||
case PholioPHIDTypeMock::TYPECONST:
|
|
||||||
$objects = id(new PholioMock())->loadAllWhere(
|
|
||||||
'id IN (%Ld)',
|
|
||||||
$object_ids);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return array_fill_keys(mpull($objects, 'getPHID'), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue