@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Allow filtering tokens given by type of token

Summary:
Adds a new filter to the page /token/given/ to specify the type of token awarded.

Closes T15988

Test Plan:
Visited /token/ to see it works as before.

Specified a token type in the search menu, and checked that the results only include that token type.

Activate DarkConsole and inspect the Services tab to check the query with "burminate" has sense, and you see this:

SELECT * FROM `token_given` WHERE (tokenPHID IN ('PHID-TOKN-misc-4')) ORDER BY `id` DESC LIMIT 101

Removed the token type in the search menu, the results still include everything, like before.

Reviewers: O1 Blessed Committers, valerio.bozzolan

Reviewed By: O1 Blessed Committers, valerio.bozzolan

Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T15988

Differential Revision: https://we.phorge.it/D25865

+94 -2
+4
src/__phutil_library_map__.php
··· 5040 5040 'PhabricatorTokenCount' => 'applications/tokens/storage/PhabricatorTokenCount.php', 5041 5041 'PhabricatorTokenCountQuery' => 'applications/tokens/query/PhabricatorTokenCountQuery.php', 5042 5042 'PhabricatorTokenDAO' => 'applications/tokens/storage/PhabricatorTokenDAO.php', 5043 + 'PhabricatorTokenDatasource' => 'applications/tokens/typeahead/PhabricatorTokenDatasource.php', 5043 5044 'PhabricatorTokenDestructionEngineExtension' => 'applications/tokens/engineextension/PhabricatorTokenDestructionEngineExtension.php', 5044 5045 'PhabricatorTokenGiveController' => 'applications/tokens/controller/PhabricatorTokenGiveController.php', 5045 5046 'PhabricatorTokenGiven' => 'applications/tokens/storage/PhabricatorTokenGiven.php', ··· 5052 5053 'PhabricatorTokenQuery' => 'applications/tokens/query/PhabricatorTokenQuery.php', 5053 5054 'PhabricatorTokenReceiverInterface' => 'applications/tokens/interface/PhabricatorTokenReceiverInterface.php', 5054 5055 'PhabricatorTokenReceiverQuery' => 'applications/tokens/query/PhabricatorTokenReceiverQuery.php', 5056 + 'PhabricatorTokenSearchField' => 'applications/tokens/field/PhabricatorTokenSearchField.php', 5055 5057 'PhabricatorTokenTokenPHIDType' => 'applications/tokens/phid/PhabricatorTokenTokenPHIDType.php', 5056 5058 'PhabricatorTokenUIEventListener' => 'applications/tokens/event/PhabricatorTokenUIEventListener.php', 5057 5059 'PhabricatorTokenizerEditField' => 'applications/transactions/editfield/PhabricatorTokenizerEditField.php', ··· 11795 11797 'PhabricatorTokenCount' => 'PhabricatorTokenDAO', 11796 11798 'PhabricatorTokenCountQuery' => 'PhabricatorOffsetPagedQuery', 11797 11799 'PhabricatorTokenDAO' => 'PhabricatorLiskDAO', 11800 + 'PhabricatorTokenDatasource' => 'PhabricatorTypeaheadDatasource', 11798 11801 'PhabricatorTokenDestructionEngineExtension' => 'PhabricatorDestructionEngineExtension', 11799 11802 'PhabricatorTokenGiveController' => 'PhabricatorTokenController', 11800 11803 'PhabricatorTokenGiven' => array( ··· 11809 11812 'PhabricatorTokenLeaderController' => 'PhabricatorTokenController', 11810 11813 'PhabricatorTokenQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 11811 11814 'PhabricatorTokenReceiverQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 11815 + 'PhabricatorTokenSearchField' => 'PhabricatorSearchTokenizerField', 11812 11816 'PhabricatorTokenTokenPHIDType' => 'PhabricatorPHIDType', 11813 11817 'PhabricatorTokenUIEventListener' => 'PhabricatorEventListener', 11814 11818 'PhabricatorTokenizerEditField' => 'PhabricatorPHIDListEditField',
+34
src/applications/tokens/field/PhabricatorTokenSearchField.php
··· 1 + <?php 2 + 3 + final class PhabricatorTokenSearchField 4 + extends PhabricatorSearchTokenizerField { 5 + 6 + protected function getDefaultValue() { 7 + return array(); 8 + } 9 + 10 + protected function newDatasource() { 11 + return new PhabricatorTokenDatasource(); 12 + } 13 + 14 + protected function getValueFromRequest(AphrontRequest $request, $key) { 15 + $list = $this->getListFromRequest($request, $key); 16 + 17 + $phids = array(); 18 + $slugs = array(); 19 + $token_type = PhabricatorTokenTokenPHIDType::TYPECONST; 20 + foreach ($list as $item) { 21 + $type = phid_get_type($item); 22 + if ($type == $token_type) { 23 + $phids[] = $item; 24 + } 25 + } 26 + 27 + return $phids; 28 + } 29 + 30 + protected function newConduitParameterType() { 31 + return new ConduitPHIDListParameterType(); 32 + } 33 + 34 + }
+14 -2
src/applications/tokens/query/PhabricatorTokenGivenSearchEngine.php
··· 16 16 } 17 17 18 18 protected function buildCustomSearchFields() { 19 - return array(); 19 + return array( 20 + id(new PhabricatorTokenSearchField()) 21 + ->setLabel(pht('Token used')) 22 + ->setKey('tokenPHIDs') 23 + ->setConduitKey('tokens') 24 + ->setAliases(array('token', 'tokens')), 25 + ); 20 26 } 21 27 22 28 protected function buildQueryFromParameters(array $map) { 23 - return $this->newQuery(); 29 + $query = $this->newQuery(); 30 + 31 + if ($map['tokenPHIDs']) { 32 + $query->withTokenPHIDs($map['tokenPHIDs']); 33 + } 34 + 35 + return $query; 24 36 } 25 37 26 38 protected function getRequiredHandlePHIDsForResultList(
+42
src/applications/tokens/typeahead/PhabricatorTokenDatasource.php
··· 1 + <?php 2 + 3 + final class PhabricatorTokenDatasource 4 + extends PhabricatorTypeaheadDatasource { 5 + 6 + public function getPlaceholderText() { 7 + return pht('Type a Token name...'); 8 + } 9 + 10 + public function getBrowseTitle() { 11 + return pht('Browse Tokens'); 12 + } 13 + 14 + public function getDatasourceApplicationClass() { 15 + return PhabricatorTokensApplication::class; 16 + } 17 + 18 + public function loadResults() { 19 + $viewer = $this->getViewer(); 20 + 21 + $tokens = id(new PhabricatorTokenQuery()) 22 + ->setViewer($viewer) 23 + ->execute(); 24 + 25 + $handles = id(new PhabricatorHandleQuery()) 26 + ->setViewer($viewer) 27 + ->withPHIDs(mpull($tokens, 'getPHID')) 28 + ->execute(); 29 + 30 + $results = array(); 31 + foreach ($tokens as $token) { 32 + $handle = $handles[$token->getPHID()]; 33 + 34 + $result = id(new PhabricatorTypeaheadResult()) 35 + ->setName($handle->getFullName()) 36 + ->setPHID($handle->getPHID()); 37 + $results[] = $result; 38 + } 39 + 40 + return $results; 41 + } 42 + }