@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.

Fix an exception in Tokens if a bad object was given a token

Summary:
Fixes T10057. Root issue is:

- In the past, you could give tokens to objects of type X (here, Ponder answers).
- Now, you can't.
- If you try to load a token on an object of type X, we do a bad call to attach it and fatal.

Instead, make sure objects implement the proper interface before we attach them, and just pretend the token does not exist otherwise.

Test Plan: Faked the exception in T10057, applied patch, got clean tokens page.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10057

Differential Revision: https://secure.phabricator.com/D14905

+26 -32
+26 -32
src/applications/tokens/query/PhabricatorTokenGivenQuery.php
··· 22 22 return $this; 23 23 } 24 24 25 - protected function loadPage() { 26 - $table = new PhabricatorTokenGiven(); 27 - $conn_r = $table->establishConnection('r'); 25 + public function newResultObject() { 26 + return new PhabricatorTokenGiven(); 27 + } 28 28 29 - $rows = queryfx_all( 30 - $conn_r, 31 - 'SELECT * FROM %T %Q %Q %Q', 32 - $table->getTableName(), 33 - $this->buildWhereClause($conn_r), 34 - $this->buildOrderClause($conn_r), 35 - $this->buildLimitClause($conn_r)); 36 - 37 - return $table->loadAllFromArray($rows); 29 + protected function loadPage() { 30 + return $this->loadStandardPage($this->newResultObject()); 38 31 } 39 32 40 - protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { 41 - $where = array(); 33 + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 34 + $where = parent::buildWhereClauseParts($conn); 42 35 43 - if ($this->authorPHIDs) { 36 + if ($this->authorPHIDs !== null) { 44 37 $where[] = qsprintf( 45 - $conn_r, 38 + $conn, 46 39 'authorPHID IN (%Ls)', 47 40 $this->authorPHIDs); 48 41 } 49 42 50 - if ($this->objectPHIDs) { 43 + if ($this->objectPHIDs !== null) { 51 44 $where[] = qsprintf( 52 - $conn_r, 45 + $conn, 53 46 'objectPHID IN (%Ls)', 54 47 $this->objectPHIDs); 55 48 } 56 49 57 - if ($this->tokenPHIDs) { 50 + if ($this->tokenPHIDs !== null) { 58 51 $where[] = qsprintf( 59 - $conn_r, 52 + $conn, 60 53 'tokenPHID IN (%Ls)', 61 54 $this->tokenPHIDs); 62 55 } 63 56 64 - $where[] = $this->buildPagingClause($conn_r); 65 - 66 - return $this->formatWhereClause($where); 57 + return $where; 67 58 } 68 59 69 60 protected function willFilterPage(array $results) { 70 - $object_phids = array_filter(mpull($results, 'getObjectPHID')); 71 - if (!$object_phids) { 72 - return array(); 73 - } 61 + $object_phids = mpull($results, 'getObjectPHID'); 74 62 75 63 $objects = id(new PhabricatorObjectQuery()) 76 64 ->setViewer($this->getViewer()) 77 65 ->withPHIDs($object_phids) 78 66 ->execute(); 67 + $objects = mpull($objects, null, 'getPHID'); 79 68 80 69 foreach ($results as $key => $result) { 81 - $phid = $result->getObjectPHID(); 82 - if (empty($objects[$phid])) { 83 - unset($results[$key]); 84 - } else { 85 - $result->attachObject($objects[$phid]); 70 + $object = idx($objects, $result->getObjectPHID()); 71 + 72 + if ($object) { 73 + if ($object instanceof PhabricatorTokenReceiverInterface) { 74 + $result->attachObject($object); 75 + continue; 76 + } 86 77 } 78 + 79 + $this->didRejectResult($result); 80 + unset($results[$key]); 87 81 } 88 82 89 83 return $results;