Page MenuHomePhabricator

D15951.id.diff
No OneTemporary

D15951.id.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -495,6 +495,7 @@
'DifferentialRequiredSignaturesField' => 'applications/differential/customfield/DifferentialRequiredSignaturesField.php',
'DifferentialResponsibleDatasource' => 'applications/differential/typeahead/DifferentialResponsibleDatasource.php',
'DifferentialResponsibleUserDatasource' => 'applications/differential/typeahead/DifferentialResponsibleUserDatasource.php',
+ 'DifferentialResponsibleViewerFunctionDatasource' => 'applications/differential/typeahead/DifferentialResponsibleViewerFunctionDatasource.php',
'DifferentialRevertPlanField' => 'applications/differential/customfield/DifferentialRevertPlanField.php',
'DifferentialReviewedByField' => 'applications/differential/customfield/DifferentialReviewedByField.php',
'DifferentialReviewer' => 'applications/differential/storage/DifferentialReviewer.php',
@@ -4720,6 +4721,7 @@
'DifferentialRequiredSignaturesField' => 'DifferentialCoreCustomField',
'DifferentialResponsibleDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
'DifferentialResponsibleUserDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
+ 'DifferentialResponsibleViewerFunctionDatasource' => 'PhabricatorTypeaheadDatasource',
'DifferentialRevertPlanField' => 'DifferentialStoredCustomField',
'DifferentialReviewedByField' => 'DifferentialCoreCustomField',
'DifferentialReviewer' => 'Phobject',
diff --git a/src/applications/differential/typeahead/DifferentialResponsibleDatasource.php b/src/applications/differential/typeahead/DifferentialResponsibleDatasource.php
--- a/src/applications/differential/typeahead/DifferentialResponsibleDatasource.php
+++ b/src/applications/differential/typeahead/DifferentialResponsibleDatasource.php
@@ -18,10 +18,46 @@
public function getComponentDatasources() {
return array(
new DifferentialResponsibleUserDatasource(),
+ new DifferentialResponsibleViewerFunctionDatasource(),
new DifferentialExactUserFunctionDatasource(),
new PhabricatorProjectDatasource(),
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;
+ }
+
}
diff --git a/src/applications/differential/typeahead/DifferentialResponsibleUserDatasource.php b/src/applications/differential/typeahead/DifferentialResponsibleUserDatasource.php
--- a/src/applications/differential/typeahead/DifferentialResponsibleUserDatasource.php
+++ b/src/applications/differential/typeahead/DifferentialResponsibleUserDatasource.php
@@ -22,37 +22,9 @@
}
protected function evaluateValues(array $values) {
- $viewer = $this->getViewer();
-
- $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;
+ return DifferentialResponsibleDatasource::expandResponsibleUsers(
+ $this->getViewer(),
+ $values);
}
}
diff --git a/src/applications/differential/typeahead/DifferentialResponsibleViewerFunctionDatasource.php b/src/applications/differential/typeahead/DifferentialResponsibleViewerFunctionDatasource.php
new file mode 100644
--- /dev/null
+++ b/src/applications/differential/typeahead/DifferentialResponsibleViewerFunctionDatasource.php
@@ -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);
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Fri, Mar 28, 1:11 PM (2 w, 4 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7724499
Default Alt Text
D15951.id.diff (6 KB)

Event Timeline