Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/auth/query/PhabricatorAuthFactorConfigQuery.php
12262 views
1
<?php
2
3
final class PhabricatorAuthFactorConfigQuery
4
extends PhabricatorCursorPagedPolicyAwareQuery {
5
6
private $ids;
7
private $phids;
8
private $userPHIDs;
9
private $factorProviderPHIDs;
10
private $factorProviderStatuses;
11
12
public function withIDs(array $ids) {
13
$this->ids = $ids;
14
return $this;
15
}
16
17
public function withPHIDs(array $phids) {
18
$this->phids = $phids;
19
return $this;
20
}
21
22
public function withUserPHIDs(array $user_phids) {
23
$this->userPHIDs = $user_phids;
24
return $this;
25
}
26
27
public function withFactorProviderPHIDs(array $provider_phids) {
28
$this->factorProviderPHIDs = $provider_phids;
29
return $this;
30
}
31
32
public function withFactorProviderStatuses(array $statuses) {
33
$this->factorProviderStatuses = $statuses;
34
return $this;
35
}
36
37
public function newResultObject() {
38
return new PhabricatorAuthFactorConfig();
39
}
40
41
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
42
$where = parent::buildWhereClauseParts($conn);
43
44
if ($this->ids !== null) {
45
$where[] = qsprintf(
46
$conn,
47
'config.id IN (%Ld)',
48
$this->ids);
49
}
50
51
if ($this->phids !== null) {
52
$where[] = qsprintf(
53
$conn,
54
'config.phid IN (%Ls)',
55
$this->phids);
56
}
57
58
if ($this->userPHIDs !== null) {
59
$where[] = qsprintf(
60
$conn,
61
'config.userPHID IN (%Ls)',
62
$this->userPHIDs);
63
}
64
65
if ($this->factorProviderPHIDs !== null) {
66
$where[] = qsprintf(
67
$conn,
68
'config.factorProviderPHID IN (%Ls)',
69
$this->factorProviderPHIDs);
70
}
71
72
if ($this->factorProviderStatuses !== null) {
73
$where[] = qsprintf(
74
$conn,
75
'provider.status IN (%Ls)',
76
$this->factorProviderStatuses);
77
}
78
79
return $where;
80
}
81
82
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
83
$joins = parent::buildJoinClauseParts($conn);
84
85
if ($this->factorProviderStatuses !== null) {
86
$joins[] = qsprintf(
87
$conn,
88
'JOIN %R provider ON config.factorProviderPHID = provider.phid',
89
new PhabricatorAuthFactorProvider());
90
}
91
92
return $joins;
93
}
94
95
protected function willFilterPage(array $configs) {
96
$provider_phids = mpull($configs, 'getFactorProviderPHID');
97
98
$providers = id(new PhabricatorAuthFactorProviderQuery())
99
->setViewer($this->getViewer())
100
->withPHIDs($provider_phids)
101
->execute();
102
$providers = mpull($providers, null, 'getPHID');
103
104
foreach ($configs as $key => $config) {
105
$provider = idx($providers, $config->getFactorProviderPHID());
106
107
if (!$provider) {
108
unset($configs[$key]);
109
$this->didRejectResult($config);
110
continue;
111
}
112
113
$config->attachFactorProvider($provider);
114
}
115
116
return $configs;
117
}
118
119
protected function getPrimaryTableAlias() {
120
return 'config';
121
}
122
123
public function getQueryApplicationClass() {
124
return 'PhabricatorAuthApplication';
125
}
126
127
}
128
129