@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at recaptime-dev/main 98 lines 2.7 kB view raw
1<?php 2 3final class DrydockObjectAuthorizationView extends AphrontView { 4 5 private $objectPHID; 6 private $blueprintPHIDs; 7 8 public function setObjectPHID($object_phid) { 9 $this->objectPHID = $object_phid; 10 return $this; 11 } 12 13 public function getObjectPHID() { 14 return $this->objectPHID; 15 } 16 17 public function setBlueprintPHIDs(array $blueprint_phids) { 18 $this->blueprintPHIDs = $blueprint_phids; 19 return $this; 20 } 21 22 public function getBlueprintPHIDs() { 23 return $this->blueprintPHIDs; 24 } 25 26 public function render() { 27 $viewer = $this->getUser(); 28 $blueprint_phids = $this->getBlueprintPHIDs(); 29 $object_phid = $this->getObjectPHID(); 30 31 // NOTE: We're intentionally letting you see the authorization state on 32 // blueprints you can't see because this has a tremendous potential to 33 // be extremely confusing otherwise. You still can't see the blueprints 34 // themselves, but you can know if the object is authorized on something. 35 36 if ($blueprint_phids) { 37 $handles = $viewer->loadHandles($blueprint_phids); 38 39 $authorizations = id(new DrydockAuthorizationQuery()) 40 ->setViewer(PhabricatorUser::getOmnipotentUser()) 41 ->withObjectPHIDs(array($object_phid)) 42 ->withBlueprintPHIDs($blueprint_phids) 43 ->execute(); 44 $authorizations = mpull($authorizations, null, 'getBlueprintPHID'); 45 } else { 46 $handles = array(); 47 $authorizations = array(); 48 } 49 50 $warnings = array(); 51 $items = array(); 52 foreach ($blueprint_phids as $phid) { 53 $authorization = idx($authorizations, $phid); 54 if (!$authorization) { 55 continue; 56 } 57 58 $handle = $handles[$phid]; 59 60 $item = id(new PHUIStatusItemView()) 61 ->setTarget($handle->renderLink()); 62 63 $state = $authorization->getBlueprintAuthorizationState(); 64 $item->setIcon( 65 DrydockAuthorization::getBlueprintStateIcon($state), 66 null, 67 DrydockAuthorization::getBlueprintStateName($state)); 68 69 switch ($state) { 70 case DrydockAuthorization::BLUEPRINTAUTH_REQUESTED: 71 case DrydockAuthorization::BLUEPRINTAUTH_DECLINED: 72 $warnings[] = $authorization; 73 break; 74 } 75 76 $items[] = $item; 77 } 78 79 $status = new PHUIStatusListView(); 80 81 if ($warnings) { 82 $status->addItem( 83 id(new PHUIStatusItemView()) 84 ->setIcon('fa-exclamation-triangle', 'pink') 85 ->setTarget( 86 pht( 87 'WARNING: There are %s unapproved authorization(s)!', 88 new PhutilNumber(count($warnings))))); 89 } 90 91 foreach ($items as $item) { 92 $status->addItem($item); 93 } 94 95 return $status; 96 } 97 98}