@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 159 lines 4.3 kB view raw
1<?php 2 3final class AlmanacBindingViewController 4 extends AlmanacServiceController { 5 6 public function shouldAllowPublic() { 7 return true; 8 } 9 10 public function handleRequest(AphrontRequest $request) { 11 $viewer = $request->getViewer(); 12 13 $id = $request->getURIData('id'); 14 15 $binding = id(new AlmanacBindingQuery()) 16 ->setViewer($viewer) 17 ->withIDs(array($id)) 18 ->needProperties(true) 19 ->executeOne(); 20 if (!$binding) { 21 return new Aphront404Response(); 22 } 23 24 $service = $binding->getService(); 25 $service_uri = $service->getURI(); 26 27 $title = pht('Binding %s', $binding->getID()); 28 29 $properties = $this->buildPropertyList($binding); 30 $details = $this->buildPropertySection($binding); 31 $curtain = $this->buildCurtain($binding); 32 33 $header = id(new PHUIHeaderView()) 34 ->setUser($viewer) 35 ->setHeader($title) 36 ->setPolicyObject($binding) 37 ->setHeaderIcon('fa-object-group'); 38 39 if ($binding->getIsDisabled()) { 40 $header->setStatus('fa-ban', 'red', pht('Disabled')); 41 } 42 43 $issue = null; 44 if ($binding->getService()->isClusterService()) { 45 $issue = $this->addClusterMessage( 46 pht('The service for this binding is a cluster service.'), 47 pht( 48 'The service for this binding is a cluster service. You do not '. 49 'have permission to manage cluster services, so this binding can '. 50 'not be edited.')); 51 } 52 53 $crumbs = $this->buildApplicationCrumbs(); 54 $crumbs->addTextCrumb($service->getName(), $service_uri); 55 $crumbs->addTextCrumb($title); 56 $crumbs->setBorder(true); 57 58 $timeline = $this->buildTransactionTimeline( 59 $binding, 60 new AlmanacBindingTransactionQuery()); 61 $timeline->setShouldTerminate(true); 62 63 $view = id(new PHUITwoColumnView()) 64 ->setHeader($header) 65 ->setCurtain($curtain) 66 ->setMainColumn(array( 67 $issue, 68 $this->buildAlmanacPropertiesTable($binding), 69 $timeline, 70 )) 71 ->addPropertySection(pht('Details'), $details); 72 73 return $this->newPage() 74 ->setTitle($title) 75 ->setCrumbs($crumbs) 76 ->appendChild( 77 array( 78 $view, 79 )); 80 } 81 82 private function buildPropertySection(AlmanacBinding $binding) { 83 $viewer = $this->getViewer(); 84 85 $properties = id(new PHUIPropertyListView()) 86 ->setUser($viewer); 87 88 $properties->addProperty( 89 pht('Service'), 90 $viewer->renderHandle($binding->getServicePHID())); 91 92 $properties->addProperty( 93 pht('Device'), 94 $viewer->renderHandle($binding->getDevicePHID())); 95 96 $properties->addProperty( 97 pht('Network'), 98 $viewer->renderHandle($binding->getInterface()->getNetworkPHID())); 99 100 $properties->addProperty( 101 pht('Interface'), 102 $binding->getInterface()->renderDisplayAddress()); 103 104 return $properties; 105 } 106 107 private function buildPropertyList(AlmanacBinding $binding) { 108 $viewer = $this->getViewer(); 109 110 $properties = id(new PHUIPropertyListView()) 111 ->setUser($viewer) 112 ->setObject($binding); 113 $properties->invokeWillRenderEvent(); 114 115 return $properties; 116 } 117 118 private function buildCurtain(AlmanacBinding $binding) { 119 $viewer = $this->getViewer(); 120 121 $can_edit = PhabricatorPolicyFilter::hasCapability( 122 $viewer, 123 $binding, 124 PhabricatorPolicyCapability::CAN_EDIT); 125 126 $id = $binding->getID(); 127 $edit_uri = $this->getApplicationURI("binding/edit/{$id}/"); 128 $disable_uri = $this->getApplicationURI("binding/disable/{$id}/"); 129 130 $curtain = $this->newCurtainView($binding); 131 132 $curtain->addAction( 133 id(new PhabricatorActionView()) 134 ->setIcon('fa-pencil') 135 ->setName(pht('Edit Binding')) 136 ->setHref($edit_uri) 137 ->setWorkflow(!$can_edit) 138 ->setDisabled(!$can_edit)); 139 140 if ($binding->getIsDisabled()) { 141 $disable_icon = 'fa-check'; 142 $disable_text = pht('Enable Binding'); 143 } else { 144 $disable_icon = 'fa-ban'; 145 $disable_text = pht('Disable Binding'); 146 } 147 148 $curtain->addAction( 149 id(new PhabricatorActionView()) 150 ->setIcon($disable_icon) 151 ->setName($disable_text) 152 ->setHref($disable_uri) 153 ->setWorkflow(true) 154 ->setDisabled(!$can_edit)); 155 156 return $curtain; 157 } 158 159}