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 @@ +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 @@ +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; + } +}