Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/oauthserver/query/PhabricatorOAuthClientAuthorizationQuery.php
12242 views
1
<?php
2
3
final class PhabricatorOAuthClientAuthorizationQuery
4
extends PhabricatorCursorPagedPolicyAwareQuery {
5
6
private $phids;
7
private $userPHIDs;
8
private $clientPHIDs;
9
10
public function withPHIDs(array $phids) {
11
$this->phids = $phids;
12
return $this;
13
}
14
15
public function withUserPHIDs(array $phids) {
16
$this->userPHIDs = $phids;
17
return $this;
18
}
19
20
public function withClientPHIDs(array $phids) {
21
$this->clientPHIDs = $phids;
22
return $this;
23
}
24
25
public function newResultObject() {
26
return new PhabricatorOAuthClientAuthorization();
27
}
28
29
protected function willFilterPage(array $authorizations) {
30
$client_phids = mpull($authorizations, 'getClientPHID');
31
32
$clients = id(new PhabricatorOAuthServerClientQuery())
33
->setViewer($this->getViewer())
34
->setParentQuery($this)
35
->withPHIDs($client_phids)
36
->execute();
37
$clients = mpull($clients, null, 'getPHID');
38
39
foreach ($authorizations as $key => $authorization) {
40
$client = idx($clients, $authorization->getClientPHID());
41
42
if (!$client) {
43
$this->didRejectResult($authorization);
44
unset($authorizations[$key]);
45
continue;
46
}
47
48
$authorization->attachClient($client);
49
}
50
51
return $authorizations;
52
}
53
54
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
55
$where = parent::buildWhereClauseParts($conn);
56
57
if ($this->phids !== null) {
58
$where[] = qsprintf(
59
$conn,
60
'phid IN (%Ls)',
61
$this->phids);
62
}
63
64
if ($this->userPHIDs !== null) {
65
$where[] = qsprintf(
66
$conn,
67
'userPHID IN (%Ls)',
68
$this->userPHIDs);
69
}
70
71
if ($this->clientPHIDs !== null) {
72
$where[] = qsprintf(
73
$conn,
74
'clientPHID IN (%Ls)',
75
$this->clientPHIDs);
76
}
77
78
return $where;
79
}
80
81
public function getQueryApplicationClass() {
82
return 'PhabricatorOAuthServerApplication';
83
}
84
85
}
86
87