mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-27 09:12:41 +01:00
Restore viewer() function to "Responsible Users" tokenizer in Differential
Summary: Ref T10939. This makes the `viewer()` function work again. It retains its own meaning (viewer, plus all their projects and packages). There's no `exact-viewer()` function; we could conceivably add one eventually if we need it. Test Plan: - Queried for `viewer()`, got the same results as querying by my own username. - Browsed function in token browser. - Reviewed autogenerated documentation. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10939 Differential Revision: https://secure.phabricator.com/D15951
This commit is contained in:
parent
7ae33d14ec
commit
45718268a9
4 changed files with 118 additions and 31 deletions
|
@ -495,6 +495,7 @@ phutil_register_library_map(array(
|
||||||
'DifferentialRequiredSignaturesField' => 'applications/differential/customfield/DifferentialRequiredSignaturesField.php',
|
'DifferentialRequiredSignaturesField' => 'applications/differential/customfield/DifferentialRequiredSignaturesField.php',
|
||||||
'DifferentialResponsibleDatasource' => 'applications/differential/typeahead/DifferentialResponsibleDatasource.php',
|
'DifferentialResponsibleDatasource' => 'applications/differential/typeahead/DifferentialResponsibleDatasource.php',
|
||||||
'DifferentialResponsibleUserDatasource' => 'applications/differential/typeahead/DifferentialResponsibleUserDatasource.php',
|
'DifferentialResponsibleUserDatasource' => 'applications/differential/typeahead/DifferentialResponsibleUserDatasource.php',
|
||||||
|
'DifferentialResponsibleViewerFunctionDatasource' => 'applications/differential/typeahead/DifferentialResponsibleViewerFunctionDatasource.php',
|
||||||
'DifferentialRevertPlanField' => 'applications/differential/customfield/DifferentialRevertPlanField.php',
|
'DifferentialRevertPlanField' => 'applications/differential/customfield/DifferentialRevertPlanField.php',
|
||||||
'DifferentialReviewedByField' => 'applications/differential/customfield/DifferentialReviewedByField.php',
|
'DifferentialReviewedByField' => 'applications/differential/customfield/DifferentialReviewedByField.php',
|
||||||
'DifferentialReviewer' => 'applications/differential/storage/DifferentialReviewer.php',
|
'DifferentialReviewer' => 'applications/differential/storage/DifferentialReviewer.php',
|
||||||
|
@ -4720,6 +4721,7 @@ phutil_register_library_map(array(
|
||||||
'DifferentialRequiredSignaturesField' => 'DifferentialCoreCustomField',
|
'DifferentialRequiredSignaturesField' => 'DifferentialCoreCustomField',
|
||||||
'DifferentialResponsibleDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
|
'DifferentialResponsibleDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
|
||||||
'DifferentialResponsibleUserDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
|
'DifferentialResponsibleUserDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
|
||||||
|
'DifferentialResponsibleViewerFunctionDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||||
'DifferentialRevertPlanField' => 'DifferentialStoredCustomField',
|
'DifferentialRevertPlanField' => 'DifferentialStoredCustomField',
|
||||||
'DifferentialReviewedByField' => 'DifferentialCoreCustomField',
|
'DifferentialReviewedByField' => 'DifferentialCoreCustomField',
|
||||||
'DifferentialReviewer' => 'Phobject',
|
'DifferentialReviewer' => 'Phobject',
|
||||||
|
|
|
@ -18,10 +18,46 @@ final class DifferentialResponsibleDatasource
|
||||||
public function getComponentDatasources() {
|
public function getComponentDatasources() {
|
||||||
return array(
|
return array(
|
||||||
new DifferentialResponsibleUserDatasource(),
|
new DifferentialResponsibleUserDatasource(),
|
||||||
|
new DifferentialResponsibleViewerFunctionDatasource(),
|
||||||
new DifferentialExactUserFunctionDatasource(),
|
new DifferentialExactUserFunctionDatasource(),
|
||||||
new PhabricatorProjectDatasource(),
|
new PhabricatorProjectDatasource(),
|
||||||
new PhabricatorOwnersPackageDatasource(),
|
new PhabricatorOwnersPackageDatasource(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function expandResponsibleUsers(
|
||||||
|
PhabricatorUser $viewer,
|
||||||
|
array $values) {
|
||||||
|
|
||||||
|
$phids = array();
|
||||||
|
foreach ($values as $value) {
|
||||||
|
if (phid_get_type($value) == PhabricatorPeopleUserPHIDType::TYPECONST) {
|
||||||
|
$phids[] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$phids) {
|
||||||
|
return $values;
|
||||||
|
}
|
||||||
|
|
||||||
|
$projects = id(new PhabricatorProjectQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->withMemberPHIDs($phids)
|
||||||
|
->execute();
|
||||||
|
foreach ($projects as $project) {
|
||||||
|
$phids[] = $project->getPHID();
|
||||||
|
$values[] = $project->getPHID();
|
||||||
|
}
|
||||||
|
|
||||||
|
$packages = id(new PhabricatorOwnersPackageQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->withOwnerPHIDs($phids)
|
||||||
|
->execute();
|
||||||
|
foreach ($packages as $package) {
|
||||||
|
$values[] = $package->getPHID();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $values;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,37 +22,9 @@ final class DifferentialResponsibleUserDatasource
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function evaluateValues(array $values) {
|
protected function evaluateValues(array $values) {
|
||||||
$viewer = $this->getViewer();
|
return DifferentialResponsibleDatasource::expandResponsibleUsers(
|
||||||
|
$this->getViewer(),
|
||||||
$phids = array();
|
$values);
|
||||||
foreach ($values as $value) {
|
|
||||||
if (phid_get_type($value) == PhabricatorPeopleUserPHIDType::TYPECONST) {
|
|
||||||
$phids[] = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$phids) {
|
|
||||||
return $values;
|
|
||||||
}
|
|
||||||
|
|
||||||
$projects = id(new PhabricatorProjectQuery())
|
|
||||||
->setViewer($viewer)
|
|
||||||
->withMemberPHIDs($phids)
|
|
||||||
->execute();
|
|
||||||
foreach ($projects as $project) {
|
|
||||||
$phids[] = $project->getPHID();
|
|
||||||
$values[] = $project->getPHID();
|
|
||||||
}
|
|
||||||
|
|
||||||
$packages = id(new PhabricatorOwnersPackageQuery())
|
|
||||||
->setViewer($viewer)
|
|
||||||
->withOwnerPHIDs($phids)
|
|
||||||
->execute();
|
|
||||||
foreach ($packages as $package) {
|
|
||||||
$values[] = $package->getPHID();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $values;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class DifferentialResponsibleViewerFunctionDatasource
|
||||||
|
extends PhabricatorTypeaheadDatasource {
|
||||||
|
|
||||||
|
public function getBrowseTitle() {
|
||||||
|
return pht('Browse Viewer');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPlaceholderText() {
|
||||||
|
return pht('Type viewer()...');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDatasourceApplicationClass() {
|
||||||
|
return 'PhabricatorPeopleApplication';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDatasourceFunctions() {
|
||||||
|
return array(
|
||||||
|
'viewer' => array(
|
||||||
|
'name' => pht('Current Viewer'),
|
||||||
|
'summary' => pht('Use the current viewing user.'),
|
||||||
|
'description' => pht(
|
||||||
|
'Show revisions the current viewer is responsible for. This '.
|
||||||
|
'function inclues revisions the viewer is responsible for through '.
|
||||||
|
'membership in projects and packages.'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function loadResults() {
|
||||||
|
if ($this->getViewer()->getPHID()) {
|
||||||
|
$results = array($this->renderViewerFunctionToken());
|
||||||
|
} else {
|
||||||
|
$results = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->filterResultsAgainstTokens($results);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function canEvaluateFunction($function) {
|
||||||
|
if (!$this->getViewer()->getPHID()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::canEvaluateFunction($function);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function evaluateFunction($function, array $argv_list) {
|
||||||
|
$results = array();
|
||||||
|
foreach ($argv_list as $argv) {
|
||||||
|
$results[] = $this->getViewer()->getPHID();
|
||||||
|
}
|
||||||
|
|
||||||
|
return DifferentialResponsibleDatasource::expandResponsibleUsers(
|
||||||
|
$this->getViewer(),
|
||||||
|
$results);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renderFunctionTokens($function, array $argv_list) {
|
||||||
|
$tokens = array();
|
||||||
|
foreach ($argv_list as $argv) {
|
||||||
|
$tokens[] = PhabricatorTypeaheadTokenView::newFromTypeaheadResult(
|
||||||
|
$this->renderViewerFunctionToken());
|
||||||
|
}
|
||||||
|
return $tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function renderViewerFunctionToken() {
|
||||||
|
return $this->newFunctionResult()
|
||||||
|
->setName(pht('Current Viewer'))
|
||||||
|
->setPHID('viewer()')
|
||||||
|
->setIcon('fa-user')
|
||||||
|
->setUnique(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue