3 final class DrydockAuthorizationQuery
extends DrydockQuery
{
7 private $blueprintPHIDs;
9 private $blueprintStates;
10 private $objectStates;
12 public static function isFullyAuthorized(
14 array $blueprint_phids) {
16 if (!$blueprint_phids) {
20 $authorizations = id(new self())
21 ->setViewer(PhabricatorUser
::getOmnipotentUser())
22 ->withObjectPHIDs(array($object_phid))
23 ->withBlueprintPHIDs($blueprint_phids)
25 $authorizations = mpull($authorizations, null, 'getBlueprintPHID');
27 foreach ($blueprint_phids as $phid) {
28 $authorization = idx($authorizations, $phid);
29 if (!$authorization) {
33 if (!$authorization->isAuthorized()) {
41 public function withIDs(array $ids) {
46 public function withPHIDs(array $phids) {
47 $this->phids
= $phids;
51 public function withBlueprintPHIDs(array $phids) {
52 $this->blueprintPHIDs
= $phids;
56 public function withObjectPHIDs(array $phids) {
57 $this->objectPHIDs
= $phids;
61 public function withBlueprintStates(array $states) {
62 $this->blueprintStates
= $states;
66 public function withObjectStates(array $states) {
67 $this->objectStates
= $states;
71 public function newResultObject() {
72 return new DrydockAuthorization();
75 protected function loadPage() {
76 return $this->loadStandardPage($this->newResultObject());
79 protected function willFilterPage(array $authorizations) {
80 $blueprint_phids = mpull($authorizations, 'getBlueprintPHID');
81 if ($blueprint_phids) {
82 $blueprints = id(new DrydockBlueprintQuery())
83 ->setViewer($this->getViewer())
84 ->setParentQuery($this)
85 ->withPHIDs($blueprint_phids)
87 $blueprints = mpull($blueprints, null, 'getPHID');
89 $blueprints = array();
92 foreach ($authorizations as $key => $authorization) {
93 $blueprint = idx($blueprints, $authorization->getBlueprintPHID());
95 $this->didRejectResult($authorization);
96 unset($authorizations[$key]);
99 $authorization->attachBlueprint($blueprint);
102 $object_phids = mpull($authorizations, 'getObjectPHID');
104 $objects = id(new PhabricatorObjectQuery())
105 ->setViewer($this->getViewer())
106 ->setParentQuery($this)
107 ->withPHIDs($object_phids)
109 $objects = mpull($objects, null, 'getPHID');
114 foreach ($authorizations as $key => $authorization) {
115 $object = idx($objects, $authorization->getObjectPHID());
117 $this->didRejectResult($authorization);
118 unset($authorizations[$key]);
121 $authorization->attachObject($object);
124 return $authorizations;
127 protected function buildWhereClauseParts(AphrontDatabaseConnection
$conn) {
128 $where = parent
::buildWhereClauseParts($conn);
130 if ($this->ids
!== null) {
137 if ($this->phids
!== null) {
144 if ($this->blueprintPHIDs
!== null) {
147 'blueprintPHID IN (%Ls)',
148 $this->blueprintPHIDs
);
151 if ($this->objectPHIDs
!== null) {
154 'objectPHID IN (%Ls)',
158 if ($this->blueprintStates
!== null) {
161 'blueprintAuthorizationState IN (%Ls)',
162 $this->blueprintStates
);
165 if ($this->objectStates
!== null) {
168 'objectAuthorizationState IN (%Ls)',
169 $this->objectStates
);