Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2951022
D25865.1738863000.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
5 KB
Referenced Files
None
Subscribers
None
D25865.1738863000.diff
View Options
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
@@ -5040,6 +5040,7 @@
'PhabricatorTokenCount' => 'applications/tokens/storage/PhabricatorTokenCount.php',
'PhabricatorTokenCountQuery' => 'applications/tokens/query/PhabricatorTokenCountQuery.php',
'PhabricatorTokenDAO' => 'applications/tokens/storage/PhabricatorTokenDAO.php',
+ 'PhabricatorTokenDatasource' => 'applications/tokens/typeahead/PhabricatorTokenDatasource.php',
'PhabricatorTokenDestructionEngineExtension' => 'applications/tokens/engineextension/PhabricatorTokenDestructionEngineExtension.php',
'PhabricatorTokenGiveController' => 'applications/tokens/controller/PhabricatorTokenGiveController.php',
'PhabricatorTokenGiven' => 'applications/tokens/storage/PhabricatorTokenGiven.php',
@@ -5052,6 +5053,7 @@
'PhabricatorTokenQuery' => 'applications/tokens/query/PhabricatorTokenQuery.php',
'PhabricatorTokenReceiverInterface' => 'applications/tokens/interface/PhabricatorTokenReceiverInterface.php',
'PhabricatorTokenReceiverQuery' => 'applications/tokens/query/PhabricatorTokenReceiverQuery.php',
+ 'PhabricatorTokenSearchField' => 'applications/tokens/field/PhabricatorTokenSearchField.php',
'PhabricatorTokenTokenPHIDType' => 'applications/tokens/phid/PhabricatorTokenTokenPHIDType.php',
'PhabricatorTokenUIEventListener' => 'applications/tokens/event/PhabricatorTokenUIEventListener.php',
'PhabricatorTokenizerEditField' => 'applications/transactions/editfield/PhabricatorTokenizerEditField.php',
@@ -11795,6 +11797,7 @@
'PhabricatorTokenCount' => 'PhabricatorTokenDAO',
'PhabricatorTokenCountQuery' => 'PhabricatorOffsetPagedQuery',
'PhabricatorTokenDAO' => 'PhabricatorLiskDAO',
+ 'PhabricatorTokenDatasource' => 'PhabricatorTypeaheadDatasource',
'PhabricatorTokenDestructionEngineExtension' => 'PhabricatorDestructionEngineExtension',
'PhabricatorTokenGiveController' => 'PhabricatorTokenController',
'PhabricatorTokenGiven' => array(
@@ -11809,6 +11812,7 @@
'PhabricatorTokenLeaderController' => 'PhabricatorTokenController',
'PhabricatorTokenQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorTokenReceiverQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
+ 'PhabricatorTokenSearchField' => 'PhabricatorSearchTokenizerField',
'PhabricatorTokenTokenPHIDType' => 'PhabricatorPHIDType',
'PhabricatorTokenUIEventListener' => 'PhabricatorEventListener',
'PhabricatorTokenizerEditField' => 'PhabricatorPHIDListEditField',
diff --git a/src/applications/tokens/field/PhabricatorTokenSearchField.php b/src/applications/tokens/field/PhabricatorTokenSearchField.php
new file mode 100644
--- /dev/null
+++ b/src/applications/tokens/field/PhabricatorTokenSearchField.php
@@ -0,0 +1,34 @@
+<?php
+
+final class PhabricatorTokenSearchField
+ extends PhabricatorSearchTokenizerField {
+
+ protected function getDefaultValue() {
+ return array();
+ }
+
+ protected function newDatasource() {
+ return new PhabricatorTokenDatasource();
+ }
+
+ protected function getValueFromRequest(AphrontRequest $request, $key) {
+ $list = $this->getListFromRequest($request, $key);
+
+ $phids = array();
+ $slugs = array();
+ $token_type = PhabricatorTokenTokenPHIDType::TYPECONST;
+ foreach ($list as $item) {
+ $type = phid_get_type($item);
+ if ($type == $token_type) {
+ $phids[] = $item;
+ }
+ }
+
+ return $phids;
+ }
+
+ protected function newConduitParameterType() {
+ return new ConduitPHIDListParameterType();
+ }
+
+}
diff --git a/src/applications/tokens/query/PhabricatorTokenGivenSearchEngine.php b/src/applications/tokens/query/PhabricatorTokenGivenSearchEngine.php
--- a/src/applications/tokens/query/PhabricatorTokenGivenSearchEngine.php
+++ b/src/applications/tokens/query/PhabricatorTokenGivenSearchEngine.php
@@ -16,11 +16,23 @@
}
protected function buildCustomSearchFields() {
- return array();
+ return array(
+ id(new PhabricatorTokenSearchField())
+ ->setLabel(pht('Token used'))
+ ->setKey('tokenPHIDs')
+ ->setConduitKey('tokens')
+ ->setAliases(array('token', 'tokens')),
+ );
}
protected function buildQueryFromParameters(array $map) {
- return $this->newQuery();
+ $query = $this->newQuery();
+
+ if ($map['tokenPHIDs']) {
+ $query->withTokenPHIDs($map['tokenPHIDs']);
+ }
+
+ return $query;
}
protected function getRequiredHandlePHIDsForResultList(
diff --git a/src/applications/tokens/typeahead/PhabricatorTokenDatasource.php b/src/applications/tokens/typeahead/PhabricatorTokenDatasource.php
new file mode 100644
--- /dev/null
+++ b/src/applications/tokens/typeahead/PhabricatorTokenDatasource.php
@@ -0,0 +1,42 @@
+<?php
+
+final class PhabricatorTokenDatasource
+ extends PhabricatorTypeaheadDatasource {
+
+ public function getPlaceholderText() {
+ return pht('Type a Token name...');
+ }
+
+ public function getBrowseTitle() {
+ return pht('Browse Tokens');
+ }
+
+ public function getDatasourceApplicationClass() {
+ return PhabricatorTokensApplication::class;
+ }
+
+ public function loadResults() {
+ $viewer = $this->getViewer();
+
+ $tokens = id(new PhabricatorTokenQuery())
+ ->setViewer($viewer)
+ ->execute();
+
+ $handles = id(new PhabricatorHandleQuery())
+ ->setViewer($viewer)
+ ->withPHIDs(mpull($tokens, 'getPHID'))
+ ->execute();
+
+ $results = array();
+ foreach ($tokens as $token) {
+ $handle = $handles[$token->getPHID()];
+
+ $result = id(new PhabricatorTypeaheadResult())
+ ->setName($handle->getFullName())
+ ->setPHID($handle->getPHID());
+ $results[] = $result;
+ }
+
+ return $results;
+ }
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Feb 6, 17:30 (18 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1157819
Default Alt Text
D25865.1738863000.diff (5 KB)
Attached To
Mode
D25865: Allow filtering tokens given by list of token
Attached
Detach File
Event Timeline
Log In to Comment