2013-01-24 12:13:31 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorApplicationDetailViewController
|
|
|
|
extends PhabricatorApplicationsController{
|
|
|
|
|
|
|
|
private $application;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->application = $data['application'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
2013-10-03 12:40:08 -07:00
|
|
|
$selected = id(new PhabricatorApplicationQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withClasses(array($this->application))
|
|
|
|
->executeOne();
|
2013-01-24 12:13:31 -08:00
|
|
|
if (!$selected) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$title = $selected->getName();
|
|
|
|
|
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
2013-12-18 17:47:34 -08:00
|
|
|
$crumbs->addTextCrumb($selected->getName());
|
2013-01-24 12:13:31 -08:00
|
|
|
|
2013-09-17 09:12:37 -07:00
|
|
|
$header = id(new PHUIHeaderView())
|
2013-10-09 13:46:45 -07:00
|
|
|
->setHeader($title)
|
|
|
|
->setUser($user)
|
|
|
|
->setPolicyObject($selected);
|
2013-01-24 12:13:31 -08:00
|
|
|
|
2013-01-29 09:14:03 -08:00
|
|
|
if ($selected->isInstalled()) {
|
2013-10-23 13:28:47 -07:00
|
|
|
$header->setStatus('oh-ok', null, pht('Installed'));
|
2013-01-29 09:14:03 -08:00
|
|
|
} else {
|
2013-10-23 13:28:47 -07:00
|
|
|
$header->setStatus('policy-noone', null, pht('Uninstalled'));
|
2013-01-31 06:22:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
$actions = $this->buildActionView($user, $selected);
|
2013-10-11 07:53:56 -07:00
|
|
|
$properties = $this->buildPropertyView($selected, $actions);
|
2013-01-31 06:22:06 -08:00
|
|
|
|
2013-09-28 15:55:38 -07:00
|
|
|
$object_box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($header)
|
2013-10-11 07:53:56 -07:00
|
|
|
->addPropertyList($properties);
|
2013-09-28 15:55:38 -07:00
|
|
|
|
2013-01-31 06:22:06 -08:00
|
|
|
return $this->buildApplicationPage(
|
|
|
|
array(
|
|
|
|
$crumbs,
|
2013-09-28 15:55:38 -07:00
|
|
|
$object_box,
|
2013-01-31 06:22:06 -08:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'title' => $title,
|
|
|
|
'device' => true,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2013-10-11 07:53:56 -07:00
|
|
|
private function buildPropertyView(
|
|
|
|
PhabricatorApplication $application,
|
|
|
|
PhabricatorActionListView $actions) {
|
|
|
|
|
2013-10-03 12:40:08 -07:00
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
|
2013-10-11 07:53:56 -07:00
|
|
|
$properties = id(new PHUIPropertyListView())
|
2013-10-03 12:40:08 -07:00
|
|
|
->addProperty(pht('Description'), $application->getShortDescription());
|
2013-10-11 07:53:56 -07:00
|
|
|
$properties->setActionList($actions);
|
2013-10-03 12:40:08 -07:00
|
|
|
|
2013-10-09 13:46:45 -07:00
|
|
|
if ($application->isBeta()) {
|
|
|
|
$properties->addProperty(
|
|
|
|
pht('Release'),
|
|
|
|
pht('Beta'));
|
|
|
|
}
|
|
|
|
|
2013-10-03 12:40:08 -07:00
|
|
|
$descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions(
|
|
|
|
$viewer,
|
|
|
|
$application);
|
|
|
|
|
|
|
|
$properties->addSectionHeader(pht('Policies'));
|
|
|
|
|
|
|
|
foreach ($application->getCapabilities() as $capability) {
|
|
|
|
$properties->addProperty(
|
|
|
|
$application->getCapabilityLabel($capability),
|
|
|
|
idx($descriptions, $capability));
|
|
|
|
}
|
2013-01-24 12:13:31 -08:00
|
|
|
|
|
|
|
return $properties;
|
|
|
|
}
|
|
|
|
|
2013-01-29 09:14:03 -08:00
|
|
|
private function buildActionView(
|
2013-10-03 12:40:08 -07:00
|
|
|
PhabricatorUser $user,
|
|
|
|
PhabricatorApplication $selected) {
|
2013-01-29 09:14:03 -08:00
|
|
|
|
2013-01-30 13:32:32 -08:00
|
|
|
$view = id(new PhabricatorActionListView())
|
2013-07-12 11:39:47 -07:00
|
|
|
->setUser($user)
|
|
|
|
->setObjectURI($this->getRequest()->getRequestURI());
|
2013-01-30 13:32:32 -08:00
|
|
|
|
2013-10-03 12:40:08 -07:00
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$user,
|
|
|
|
$selected,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
|
|
|
|
$edit_uri = $this->getApplicationURI('edit/'.get_class($selected).'/');
|
|
|
|
|
|
|
|
$view->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Edit Policies'))
|
2014-05-12 10:08:32 -07:00
|
|
|
->setIcon('fa-pencil')
|
2013-10-03 12:40:08 -07:00
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(!$can_edit)
|
|
|
|
->setHref($edit_uri));
|
|
|
|
|
2013-01-29 09:14:03 -08:00
|
|
|
if ($selected->canUninstall()) {
|
|
|
|
if ($selected->isInstalled()) {
|
2013-01-30 13:32:32 -08:00
|
|
|
$view->addAction(
|
2013-10-03 12:40:08 -07:00
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Uninstall'))
|
2014-05-12 10:08:32 -07:00
|
|
|
->setIcon('fa-times')
|
2013-10-03 12:40:08 -07:00
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(true)
|
|
|
|
->setHref(
|
|
|
|
$this->getApplicationURI(get_class($selected).'/uninstall/')));
|
2013-01-29 09:14:03 -08:00
|
|
|
} else {
|
2013-04-10 14:52:20 -07:00
|
|
|
$action = id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Install'))
|
2014-05-12 10:08:32 -07:00
|
|
|
->setIcon('fa-plus')
|
2013-10-03 12:40:08 -07:00
|
|
|
->setDisabled(!$can_edit)
|
2013-04-10 14:52:20 -07:00
|
|
|
->setWorkflow(true)
|
|
|
|
->setHref(
|
2013-10-03 12:40:08 -07:00
|
|
|
$this->getApplicationURI(get_class($selected).'/install/'));
|
2013-04-10 14:52:20 -07:00
|
|
|
|
|
|
|
$beta_enabled = PhabricatorEnv::getEnvConfig(
|
|
|
|
'phabricator.show-beta-applications');
|
|
|
|
if ($selected->isBeta() && !$beta_enabled) {
|
|
|
|
$action->setDisabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
$view->addAction($action);
|
2013-01-29 09:14:03 -08:00
|
|
|
}
|
2013-01-30 13:32:32 -08:00
|
|
|
} else {
|
|
|
|
$view->addAction(
|
2013-10-03 12:40:08 -07:00
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Uninstall'))
|
2014-05-12 10:08:32 -07:00
|
|
|
->setIcon('fa-times')
|
2013-10-03 12:40:08 -07:00
|
|
|
->setWorkflow(true)
|
|
|
|
->setDisabled(true)
|
|
|
|
->setHref(
|
|
|
|
$this->getApplicationURI(get_class($selected).'/uninstall/')));
|
2013-01-29 09:14:03 -08:00
|
|
|
}
|
2013-10-03 12:40:08 -07:00
|
|
|
|
2013-01-30 13:32:32 -08:00
|
|
|
return $view;
|
2013-01-24 12:13:31 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|