@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
at recaptime-dev/main 85 lines 2.6 kB view raw
1<?php 2 3final class DrydockAuthorizationAuthorizeController 4 extends DrydockController { 5 6 public function handleRequest(AphrontRequest $request) { 7 $viewer = $request->getViewer(); 8 $id = $request->getURIData('id'); 9 10 $authorization = id(new DrydockAuthorizationQuery()) 11 ->setViewer($viewer) 12 ->withIDs(array($id)) 13 ->requireCapabilities( 14 array( 15 PhabricatorPolicyCapability::CAN_VIEW, 16 PhabricatorPolicyCapability::CAN_EDIT, 17 )) 18 ->executeOne(); 19 if (!$authorization) { 20 return new Aphront404Response(); 21 } 22 23 $authorization_uri = $this->getApplicationURI("authorization/{$id}/"); 24 $is_authorize = ($request->getURIData('action') == 'authorize'); 25 26 $state_authorized = DrydockAuthorization::BLUEPRINTAUTH_AUTHORIZED; 27 $state_declined = DrydockAuthorization::BLUEPRINTAUTH_DECLINED; 28 29 $state = $authorization->getBlueprintAuthorizationState(); 30 $can_authorize = ($state != $state_authorized); 31 $can_decline = ($state != $state_declined); 32 33 if ($is_authorize && !$can_authorize) { 34 return $this->newDialog() 35 ->setTitle(pht('Already Authorized')) 36 ->appendParagraph( 37 pht( 38 'This authorization has already been approved.')) 39 ->addCancelButton($authorization_uri); 40 } 41 42 if (!$is_authorize && !$can_decline) { 43 return $this->newDialog() 44 ->setTitle(pht('Already Declined')) 45 ->appendParagraph( 46 pht('This authorization has already been declined.')) 47 ->addCancelButton($authorization_uri); 48 } 49 50 if ($request->isFormPost()) { 51 if ($is_authorize) { 52 $new_state = $state_authorized; 53 } else { 54 $new_state = $state_declined; 55 } 56 57 $authorization 58 ->setBlueprintAuthorizationState($new_state) 59 ->save(); 60 61 return id(new AphrontRedirectResponse())->setURI($authorization_uri); 62 } 63 64 if ($is_authorize) { 65 $title = pht('Approve Authorization'); 66 $body = pht( 67 'Approve this authorization? The object will be able to lease and '. 68 'allocate resources created by this blueprint.'); 69 $button = pht('Approve Authorization'); 70 } else { 71 $title = pht('Decline Authorization'); 72 $body = pht( 73 'Decline this authorization? The object will not be able to lease '. 74 'or allocate resources created by this blueprint.'); 75 $button = pht('Decline Authorization'); 76 } 77 78 return $this->newDialog() 79 ->setTitle($title) 80 ->appendParagraph($body) 81 ->addSubmitButton($button) 82 ->addCancelButton($authorization_uri); 83 } 84 85}