1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 12:00:55 +01:00

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
This commit is contained in:
epriestley 2015-12-28 12:59:38 -08:00
parent abd60eeee0
commit 33384abff7

View file

@ -22,68 +22,62 @@ final class PhabricatorTokenGivenQuery
return $this; return $this;
} }
protected function loadPage() { public function newResultObject() {
$table = new PhabricatorTokenGiven(); return new PhabricatorTokenGiven();
$conn_r = $table->establishConnection('r');
$rows = queryfx_all(
$conn_r,
'SELECT * FROM %T %Q %Q %Q',
$table->getTableName(),
$this->buildWhereClause($conn_r),
$this->buildOrderClause($conn_r),
$this->buildLimitClause($conn_r));
return $table->loadAllFromArray($rows);
} }
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { protected function loadPage() {
$where = array(); return $this->loadStandardPage($this->newResultObject());
}
if ($this->authorPHIDs) { protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
if ($this->authorPHIDs !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'authorPHID IN (%Ls)', 'authorPHID IN (%Ls)',
$this->authorPHIDs); $this->authorPHIDs);
} }
if ($this->objectPHIDs) { if ($this->objectPHIDs !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'objectPHID IN (%Ls)', 'objectPHID IN (%Ls)',
$this->objectPHIDs); $this->objectPHIDs);
} }
if ($this->tokenPHIDs) { if ($this->tokenPHIDs !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'tokenPHID IN (%Ls)', 'tokenPHID IN (%Ls)',
$this->tokenPHIDs); $this->tokenPHIDs);
} }
$where[] = $this->buildPagingClause($conn_r); return $where;
return $this->formatWhereClause($where);
} }
protected function willFilterPage(array $results) { protected function willFilterPage(array $results) {
$object_phids = array_filter(mpull($results, 'getObjectPHID')); $object_phids = mpull($results, 'getObjectPHID');
if (!$object_phids) {
return array();
}
$objects = id(new PhabricatorObjectQuery()) $objects = id(new PhabricatorObjectQuery())
->setViewer($this->getViewer()) ->setViewer($this->getViewer())
->withPHIDs($object_phids) ->withPHIDs($object_phids)
->execute(); ->execute();
$objects = mpull($objects, null, 'getPHID');
foreach ($results as $key => $result) { foreach ($results as $key => $result) {
$phid = $result->getObjectPHID(); $object = idx($objects, $result->getObjectPHID());
if (empty($objects[$phid])) {
unset($results[$key]); if ($object) {
} else { if ($object instanceof PhabricatorTokenReceiverInterface) {
$result->attachObject($objects[$phid]); $result->attachObject($object);
continue;
}
} }
$this->didRejectResult($result);
unset($results[$key]);
} }
return $results; return $results;