mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-19 21:32:43 +01:00
Typeahead - filter typeaheads that the viewer can't see in typeahead debug tool
Summary: Fixes T7255. Note however that some datasources - notably user or project - don't implement the class thing in a clean way since multiple classes apply. For now, we just show these datasources to the user. Also, I guess this could be done more efficiently by querying for all the applications at once via an application query? LMK if you want me to make that change. Test Plan: loaded /typeahead/class/ and played with it a bit with no issues Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T7255 Differential Revision: https://secure.phabricator.com/D12307
This commit is contained in:
parent
b2c23d88e8
commit
30398b6371
1 changed files with 25 additions and 12 deletions
|
@ -3,17 +3,11 @@
|
||||||
final class PhabricatorTypeaheadModularDatasourceController
|
final class PhabricatorTypeaheadModularDatasourceController
|
||||||
extends PhabricatorTypeaheadDatasourceController {
|
extends PhabricatorTypeaheadDatasourceController {
|
||||||
|
|
||||||
private $class;
|
|
||||||
|
|
||||||
public function shouldAllowPublic() {
|
public function shouldAllowPublic() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function willProcessRequest(array $data) {
|
public function handleRequest(AphrontRequest $request) {
|
||||||
$this->class = idx($data, 'class');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function processRequest() {
|
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$viewer = $request->getUser();
|
$viewer = $request->getUser();
|
||||||
$query = $request->getStr('q');
|
$query = $request->getStr('q');
|
||||||
|
@ -22,14 +16,21 @@ final class PhabricatorTypeaheadModularDatasourceController
|
||||||
$raw_query = nonempty($request->getStr('raw'), $query);
|
$raw_query = nonempty($request->getStr('raw'), $query);
|
||||||
|
|
||||||
// This makes form submission easier in the debug view.
|
// This makes form submission easier in the debug view.
|
||||||
$this->class = nonempty($request->getStr('class'), $this->class);
|
$class = nonempty($request->getURIData('class'), $request->getStr('class'));
|
||||||
|
|
||||||
$sources = id(new PhutilSymbolLoader())
|
$sources = id(new PhutilSymbolLoader())
|
||||||
->setAncestorClass('PhabricatorTypeaheadDatasource')
|
->setAncestorClass('PhabricatorTypeaheadDatasource')
|
||||||
->loadObjects();
|
->loadObjects();
|
||||||
|
if (isset($sources[$class])) {
|
||||||
|
$source = $sources[$class];
|
||||||
|
if ($source->getDatasourceApplicationClass()) {
|
||||||
|
if (!PhabricatorApplication::isClassInstalledForViewer(
|
||||||
|
$source->getDatasourceApplicationClass(),
|
||||||
|
$viewer)) {
|
||||||
|
return id(new Aphront404Response());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($sources[$this->class])) {
|
|
||||||
$source = $sources[$this->class];
|
|
||||||
$source->setParameters($request->getRequestData());
|
$source->setParameters($request->getRequestData());
|
||||||
|
|
||||||
$composite = new PhabricatorTypeaheadRuntimeCompositeDatasource();
|
$composite = new PhabricatorTypeaheadRuntimeCompositeDatasource();
|
||||||
|
@ -54,6 +55,18 @@ final class PhabricatorTypeaheadModularDatasourceController
|
||||||
// If there's a non-Ajax request to this endpoint, show results in a tabular
|
// If there's a non-Ajax request to this endpoint, show results in a tabular
|
||||||
// format to make it easier to debug typeahead output.
|
// format to make it easier to debug typeahead output.
|
||||||
|
|
||||||
|
foreach ($sources as $key => $source) {
|
||||||
|
// This can happen with composite sources like user or project, as well
|
||||||
|
// generic ones like NoOwner
|
||||||
|
if (!$source->getDatasourceApplicationClass()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!PhabricatorApplication::isClassInstalledForViewer(
|
||||||
|
$source->getDatasourceApplicationClass(),
|
||||||
|
$viewer)) {
|
||||||
|
unset($sources[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
$options = array_fuse(array_keys($sources));
|
$options = array_fuse(array_keys($sources));
|
||||||
asort($options);
|
asort($options);
|
||||||
|
|
||||||
|
@ -64,7 +77,7 @@ final class PhabricatorTypeaheadModularDatasourceController
|
||||||
id(new AphrontFormSelectControl())
|
id(new AphrontFormSelectControl())
|
||||||
->setLabel(pht('Source Class'))
|
->setLabel(pht('Source Class'))
|
||||||
->setName('class')
|
->setName('class')
|
||||||
->setValue($this->class)
|
->setValue($class)
|
||||||
->setOptions($options))
|
->setOptions($options))
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormTextControl())
|
id(new AphrontFormTextControl())
|
||||||
|
@ -101,7 +114,7 @@ final class PhabricatorTypeaheadModularDatasourceController
|
||||||
));
|
));
|
||||||
|
|
||||||
$result_box = id(new PHUIObjectBoxView())
|
$result_box = id(new PHUIObjectBoxView())
|
||||||
->setHeaderText(pht('Token Results (%s)', $this->class))
|
->setHeaderText(pht('Token Results (%s)', $class))
|
||||||
->appendChild($table);
|
->appendChild($table);
|
||||||
|
|
||||||
return $this->buildApplicationPage(
|
return $this->buildApplicationPage(
|
||||||
|
|
Loading…
Reference in a new issue