Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / almanac / controller / AlmanacBindingViewController.php
blobd1ed2178d2bc72bf5266e114ea6960b65bb0c381
1 <?php
3 final class AlmanacBindingViewController
4 extends AlmanacServiceController {
6 public function shouldAllowPublic() {
7 return true;
10 public function handleRequest(AphrontRequest $request) {
11 $viewer = $request->getViewer();
13 $id = $request->getURIData('id');
15 $binding = id(new AlmanacBindingQuery())
16 ->setViewer($viewer)
17 ->withIDs(array($id))
18 ->needProperties(true)
19 ->executeOne();
20 if (!$binding) {
21 return new Aphront404Response();
24 $service = $binding->getService();
25 $service_uri = $service->getURI();
27 $title = pht('Binding %s', $binding->getID());
29 $properties = $this->buildPropertyList($binding);
30 $details = $this->buildPropertySection($binding);
31 $curtain = $this->buildCurtain($binding);
33 $header = id(new PHUIHeaderView())
34 ->setUser($viewer)
35 ->setHeader($title)
36 ->setPolicyObject($binding)
37 ->setHeaderIcon('fa-object-group');
39 if ($binding->getIsDisabled()) {
40 $header->setStatus('fa-ban', 'red', pht('Disabled'));
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.'));
53 $crumbs = $this->buildApplicationCrumbs();
54 $crumbs->addTextCrumb($service->getName(), $service_uri);
55 $crumbs->addTextCrumb($title);
56 $crumbs->setBorder(true);
58 $timeline = $this->buildTransactionTimeline(
59 $binding,
60 new AlmanacBindingTransactionQuery());
61 $timeline->setShouldTerminate(true);
63 $view = id(new PHUITwoColumnView())
64 ->setHeader($header)
65 ->setCurtain($curtain)
66 ->setMainColumn(array(
67 $issue,
68 $this->buildAlmanacPropertiesTable($binding),
69 $timeline,
71 ->addPropertySection(pht('Details'), $details);
73 return $this->newPage()
74 ->setTitle($title)
75 ->setCrumbs($crumbs)
76 ->appendChild(
77 array(
78 $view,
79 ));
82 private function buildPropertySection(AlmanacBinding $binding) {
83 $viewer = $this->getViewer();
85 $properties = id(new PHUIPropertyListView())
86 ->setUser($viewer);
88 $properties->addProperty(
89 pht('Service'),
90 $viewer->renderHandle($binding->getServicePHID()));
92 $properties->addProperty(
93 pht('Device'),
94 $viewer->renderHandle($binding->getDevicePHID()));
96 $properties->addProperty(
97 pht('Network'),
98 $viewer->renderHandle($binding->getInterface()->getNetworkPHID()));
100 $properties->addProperty(
101 pht('Interface'),
102 $binding->getInterface()->renderDisplayAddress());
104 return $properties;
107 private function buildPropertyList(AlmanacBinding $binding) {
108 $viewer = $this->getViewer();
110 $properties = id(new PHUIPropertyListView())
111 ->setUser($viewer)
112 ->setObject($binding);
113 $properties->invokeWillRenderEvent();
115 return $properties;
118 private function buildCurtain(AlmanacBinding $binding) {
119 $viewer = $this->getViewer();
121 $can_edit = PhabricatorPolicyFilter::hasCapability(
122 $viewer,
123 $binding,
124 PhabricatorPolicyCapability::CAN_EDIT);
126 $id = $binding->getID();
127 $edit_uri = $this->getApplicationURI("binding/edit/{$id}/");
128 $disable_uri = $this->getApplicationURI("binding/disable/{$id}/");
130 $curtain = $this->newCurtainView($binding);
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));
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');
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));
156 return $curtain;