3 final class PhabricatorApplicationEditController
4 extends PhabricatorApplicationsController
{
6 public function handleRequest(AphrontRequest
$request) {
7 $user = $request->getUser();
8 $application = $request->getURIData('application');
10 $application = id(new PhabricatorApplicationQuery())
12 ->withClasses(array($application))
13 ->requireCapabilities(
15 PhabricatorPolicyCapability
::CAN_VIEW
,
16 PhabricatorPolicyCapability
::CAN_EDIT
,
20 return new Aphront404Response();
23 $title = $application->getName();
25 $view_uri = $this->getApplicationURI('view/'.get_class($application).'/');
27 $policies = id(new PhabricatorPolicyQuery())
29 ->setObject($application)
32 if ($request->isFormPost()) {
35 $template = $application->getApplicationTransactionTemplate();
36 foreach ($application->getCapabilities() as $capability) {
37 if (!$application->isCapabilityEditable($capability)) {
41 $old = $application->getPolicy($capability);
42 $new = $request->getStr('policy:'.$capability);
45 // No change to the setting.
49 $xactions[] = id(clone $template)
51 PhabricatorApplicationPolicyChangeTransaction
::TRANSACTIONTYPE
)
53 PhabricatorApplicationPolicyChangeTransaction
::METADATA_ATTRIBUTE
,
58 $editor = id(new PhabricatorApplicationEditor())
60 ->setContentSourceFromRequest($request)
61 ->setContinueOnNoEffect(true)
62 ->setContinueOnMissingFields(true);
65 $editor->applyTransactions($application, $xactions);
66 return id(new AphrontRedirectResponse())->setURI($view_uri);
67 } catch (PhabricatorApplicationTransactionValidationException
$ex) {
68 $validation_exception = $ex;
71 return $this->newDialog()
72 ->setTitle(pht('Validation Failed'))
73 ->setValidationException($validation_exception)
74 ->addCancelButton($view_uri);
77 $descriptions = PhabricatorPolicyQuery
::renderPolicyDescriptions(
81 $form = id(new AphrontFormView())
84 $locked_policies = PhabricatorEnv
::getEnvConfig('policy.locked');
85 foreach ($application->getCapabilities() as $capability) {
86 $label = $application->getCapabilityLabel($capability);
87 $can_edit = $application->isCapabilityEditable($capability);
88 $locked = idx($locked_policies, $capability);
89 $caption = $application->getCapabilityCaption($capability);
91 if (!$can_edit ||
$locked) {
93 id(new AphrontFormStaticControl())
95 ->setValue(idx($descriptions, $capability))
96 ->setCaption($caption));
98 $control = id(new AphrontFormPolicyControl())
100 ->setDisabled($locked)
101 ->setCapability($capability)
102 ->setPolicyObject($application)
103 ->setPolicies($policies)
105 ->setName('policy:'.$capability)
106 ->setCaption($caption);
108 $template = $application->getCapabilityTemplatePHIDType($capability);
110 $phid_types = PhabricatorPHIDType
::getAllTypes();
111 $phid_type = idx($phid_types, $template);
113 $template_object = $phid_type->newObject();
114 if ($template_object) {
115 $template_policies = id(new PhabricatorPolicyQuery())
117 ->setObject($template_object)
120 // NOTE: We want to expose both any object template policies
121 // (like "Subscribers") and any custom policy.
122 $all_policies = $template_policies +
$policies;
124 $control->setPolicies($all_policies);
125 $control->setTemplateObject($template_object);
129 $control->setTemplatePHIDType($template);
132 $form->appendControl($control);
138 id(new AphrontFormSubmitControl())
139 ->setValue(pht('Save Policies'))
140 ->addCancelButton($view_uri));
142 $crumbs = $this->buildApplicationCrumbs();
143 $crumbs->addTextCrumb($application->getName(), $view_uri);
144 $crumbs->addTextCrumb(pht('Edit Policies'));
145 $crumbs->setBorder(true);
147 $header = id(new PHUIHeaderView())
148 ->setHeader(pht('Edit Policies: %s', $application->getName()))
149 ->setHeaderIcon('fa-pencil');
151 $object_box = id(new PHUIObjectBoxView())
152 ->setHeaderText(pht('Policies'))
153 ->setBackground(PHUIObjectBoxView
::BLUE_PROPERTY
)
156 $view = id(new PHUITwoColumnView())
162 return $this->newPage()
165 ->appendChild($view);