Differential D15593 Diff 37613 src/applications/oauthserver/query/PhabricatorOAuthClientAuthorizationQuery.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/oauthserver/query/PhabricatorOAuthClientAuthorizationQuery.php
<?php | <?php | ||||
final class PhabricatorOAuthClientAuthorizationQuery | final class PhabricatorOAuthClientAuthorizationQuery | ||||
extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
private $phids; | private $phids; | ||||
private $userPHIDs; | private $userPHIDs; | ||||
private $clientPHIDs; | private $clientPHIDs; | ||||
public function witHPHIDs(array $phids) { | public function withPHIDs(array $phids) { | ||||
$this->phids = $phids; | $this->phids = $phids; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withUserPHIDs(array $phids) { | public function withUserPHIDs(array $phids) { | ||||
$this->userPHIDs = $phids; | $this->userPHIDs = $phids; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withClientPHIDs(array $phids) { | public function withClientPHIDs(array $phids) { | ||||
$this->clientPHIDs = $phids; | $this->clientPHIDs = $phids; | ||||
return $this; | return $this; | ||||
} | } | ||||
protected function loadPage() { | public function newResultObject() { | ||||
$table = new PhabricatorOAuthClientAuthorization(); | return new PhabricatorOAuthClientAuthorization(); | ||||
$conn_r = $table->establishConnection('r'); | } | ||||
$data = queryfx_all( | |||||
$conn_r, | |||||
'SELECT * FROM %T auth %Q %Q %Q', | |||||
$table->getTableName(), | |||||
$this->buildWhereClause($conn_r), | |||||
$this->buildOrderClause($conn_r), | |||||
$this->buildLimitClause($conn_r)); | |||||
return $table->loadAllFromArray($data); | protected function loadPage() { | ||||
return $this->loadStandardPage($this->newResultObject()); | |||||
} | } | ||||
protected function willFilterPage(array $authorizations) { | protected function willFilterPage(array $authorizations) { | ||||
$client_phids = mpull($authorizations, 'getClientPHID'); | $client_phids = mpull($authorizations, 'getClientPHID'); | ||||
$clients = id(new PhabricatorOAuthServerClientQuery()) | $clients = id(new PhabricatorOAuthServerClientQuery()) | ||||
->setViewer($this->getViewer()) | ->setViewer($this->getViewer()) | ||||
->setParentQuery($this) | ->setParentQuery($this) | ||||
->withPHIDs($client_phids) | ->withPHIDs($client_phids) | ||||
->execute(); | ->execute(); | ||||
$clients = mpull($clients, null, 'getPHID'); | $clients = mpull($clients, null, 'getPHID'); | ||||
foreach ($authorizations as $key => $authorization) { | foreach ($authorizations as $key => $authorization) { | ||||
$client = idx($clients, $authorization->getClientPHID()); | $client = idx($clients, $authorization->getClientPHID()); | ||||
if (!$client) { | if (!$client) { | ||||
$this->didRejectResult($authorization); | |||||
unset($authorizations[$key]); | unset($authorizations[$key]); | ||||
continue; | continue; | ||||
} | } | ||||
$authorization->attachClient($client); | $authorization->attachClient($client); | ||||
} | } | ||||
return $authorizations; | return $authorizations; | ||||
} | } | ||||
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { | protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | ||||
$where = array(); | $where = parent::buildWhereClauseParts($conn); | ||||
if ($this->phids) { | if ($this->phids !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'phid IN (%Ls)', | 'phid IN (%Ls)', | ||||
$this->phids); | $this->phids); | ||||
} | } | ||||
if ($this->userPHIDs) { | if ($this->userPHIDs !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'userPHID IN (%Ls)', | 'userPHID IN (%Ls)', | ||||
$this->userPHIDs); | $this->userPHIDs); | ||||
} | } | ||||
if ($this->clientPHIDs) { | if ($this->clientPHIDs !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'clientPHID IN (%Ls)', | 'clientPHID IN (%Ls)', | ||||
$this->clientPHIDs); | $this->clientPHIDs); | ||||
} | } | ||||
$where[] = $this->buildPagingClause($conn_r); | return $where; | ||||
return $this->formatWhereClause($where); | |||||
} | } | ||||
public function getQueryApplicationClass() { | public function getQueryApplicationClass() { | ||||
return 'PhabricatorOAuthServerApplication'; | return 'PhabricatorOAuthServerApplication'; | ||||
} | } | ||||
} | } |