mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-01 01:18:22 +01:00
69cc5df645
Summary: Ref T4712. Thus far, it seems that most "non-standard" things can be done pretty easily in the controller. Aside from deploying, this diff had to fix a few bugs / missing implementations of stuff. (Notably, PhabricatorAuthProviderConfig, HeraldRule, PhabricatorSlowvotePoll, and AlmanacNetwork needed to implement PhabricatorApplicationTransactionInterface, PhabricatorAuthAuthProviderPHIDType had to be added, and a rendering bug in transactions of type PhabricatorOAuth2AuthProvider had to be fixed.) Test Plan: Almanac - looked at binding, device, network, and service view controllers and verified timeline displayed properly. Herald - looked at a rule and verified timeline. Slowvote - looked at a vote and verified timeline. Auth - looked at an auth provider (Facebook) and verified proper display of transactions within timeline. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T4712 Differential Revision: https://secure.phabricator.com/D10921
141 lines
3.7 KiB
PHP
141 lines
3.7 KiB
PHP
<?php
|
|
|
|
final class AlmanacServiceViewController
|
|
extends AlmanacServiceController {
|
|
|
|
public function shouldAllowPublic() {
|
|
return true;
|
|
}
|
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
$viewer = $request->getViewer();
|
|
|
|
$name = $request->getURIData('name');
|
|
|
|
$service = id(new AlmanacServiceQuery())
|
|
->setViewer($viewer)
|
|
->withNames(array($name))
|
|
->executeOne();
|
|
if (!$service) {
|
|
return new Aphront404Response();
|
|
}
|
|
|
|
$title = pht('Service %s', $service->getName());
|
|
|
|
$property_list = $this->buildPropertyList($service);
|
|
$action_list = $this->buildActionList($service);
|
|
$property_list->setActionList($action_list);
|
|
|
|
$header = id(new PHUIHeaderView())
|
|
->setUser($viewer)
|
|
->setHeader($service->getName())
|
|
->setPolicyObject($service);
|
|
|
|
$box = id(new PHUIObjectBoxView())
|
|
->setHeader($header)
|
|
->addPropertyList($property_list);
|
|
|
|
$bindings = $this->buildBindingList($service);
|
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
$crumbs->addTextCrumb($service->getName());
|
|
|
|
$timeline = $this->buildTransactionTimeline(
|
|
$service,
|
|
new AlmanacServiceTransactionQuery());
|
|
$timeline->setShouldTerminate(true);
|
|
|
|
return $this->buildApplicationPage(
|
|
array(
|
|
$crumbs,
|
|
$box,
|
|
$bindings,
|
|
$this->buildAlmanacPropertiesTable($service),
|
|
$timeline,
|
|
),
|
|
array(
|
|
'title' => $title,
|
|
));
|
|
}
|
|
|
|
private function buildPropertyList(AlmanacService $service) {
|
|
$viewer = $this->getViewer();
|
|
|
|
$properties = id(new PHUIPropertyListView())
|
|
->setUser($viewer)
|
|
->setObject($service);
|
|
|
|
return $properties;
|
|
}
|
|
|
|
private function buildActionList(AlmanacService $service) {
|
|
$viewer = $this->getViewer();
|
|
$id = $service->getID();
|
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
$viewer,
|
|
$service,
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
$actions = id(new PhabricatorActionListView())
|
|
->setUser($viewer);
|
|
|
|
$actions->addAction(
|
|
id(new PhabricatorActionView())
|
|
->setIcon('fa-pencil')
|
|
->setName(pht('Edit Service'))
|
|
->setHref($this->getApplicationURI("service/edit/{$id}/"))
|
|
->setWorkflow(!$can_edit)
|
|
->setDisabled(!$can_edit));
|
|
|
|
return $actions;
|
|
}
|
|
|
|
private function buildBindingList(AlmanacService $service) {
|
|
$viewer = $this->getViewer();
|
|
$id = $service->getID();
|
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
$viewer,
|
|
$service,
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
$bindings = id(new AlmanacBindingQuery())
|
|
->setViewer($viewer)
|
|
->withServicePHIDs(array($service->getPHID()))
|
|
->execute();
|
|
|
|
$phids = array();
|
|
foreach ($bindings as $binding) {
|
|
$phids[] = $binding->getServicePHID();
|
|
$phids[] = $binding->getDevicePHID();
|
|
$phids[] = $binding->getInterface()->getNetworkPHID();
|
|
}
|
|
$handles = $this->loadViewerHandles($phids);
|
|
|
|
$table = id(new AlmanacBindingTableView())
|
|
->setNoDataString(
|
|
pht('This service has not been bound to any device interfaces yet.'))
|
|
->setUser($viewer)
|
|
->setBindings($bindings)
|
|
->setHandles($handles);
|
|
|
|
$header = id(new PHUIHeaderView())
|
|
->setHeader(pht('Service Bindings'))
|
|
->addActionLink(
|
|
id(new PHUIButtonView())
|
|
->setTag('a')
|
|
->setHref($this->getApplicationURI("binding/edit/?serviceID={$id}"))
|
|
->setWorkflow(!$can_edit)
|
|
->setDisabled(!$can_edit)
|
|
->setText(pht('Add Binding'))
|
|
->setIcon(
|
|
id(new PHUIIconView())
|
|
->setIconFont('fa-plus')));
|
|
|
|
return id(new PHUIObjectBoxView())
|
|
->setHeader($header)
|
|
->appendChild($table);
|
|
}
|
|
|
|
}
|