3 final class PhabricatorSpacesEditController
4 extends PhabricatorSpacesController
{
6 public function handleRequest(AphrontRequest
$request) {
7 $viewer = $request->getUser();
11 $id = $request->getURIData('id');
13 $space = id(new PhabricatorSpacesNamespaceQuery())
16 ->requireCapabilities(
18 PhabricatorPolicyCapability
::CAN_VIEW
,
19 PhabricatorPolicyCapability
::CAN_EDIT
,
23 return new Aphront404Response();
27 $cancel_uri = '/'.$space->getMonogram();
29 $header_text = pht('Edit %s', $space->getNamespaceName());
30 $title = pht('Edit Space');
31 $button_text = pht('Save Changes');
33 $this->requireApplicationCapability(
34 PhabricatorSpacesCapabilityCreateSpaces
::CAPABILITY
);
36 $space = PhabricatorSpacesNamespace
::initializeNewNamespace($viewer);
39 $cancel_uri = $this->getApplicationURI();
41 $header_text = pht('Create Space');
42 $title = pht('Create Space');
43 $button_text = pht('Create Space');
45 $default = id(new PhabricatorSpacesNamespaceQuery())
46 ->setViewer(PhabricatorUser
::getOmnipotentUser())
47 ->withIsDefaultNamespace(true)
54 $validation_exception = null;
56 $v_name = $space->getNamespaceName();
57 $v_desc = $space->getDescription();
58 $v_view = $space->getViewPolicy();
59 $v_edit = $space->getEditPolicy();
61 if ($request->isFormPost()) {
65 $v_name = $request->getStr('name');
66 $v_desc = $request->getStr('description');
67 $v_view = $request->getStr('viewPolicy');
68 $v_edit = $request->getStr('editPolicy');
71 PhabricatorSpacesNamespaceNameTransaction
::TRANSACTIONTYPE
;
73 PhabricatorSpacesNamespaceDescriptionTransaction
::TRANSACTIONTYPE
;
75 PhabricatorSpacesNamespaceDefaultTransaction
::TRANSACTIONTYPE
;
76 $type_view = PhabricatorTransactions
::TYPE_VIEW_POLICY
;
77 $type_edit = PhabricatorTransactions
::TYPE_EDIT_POLICY
;
79 $xactions[] = id(new PhabricatorSpacesNamespaceTransaction())
80 ->setTransactionType($type_name)
81 ->setNewValue($v_name);
83 $xactions[] = id(new PhabricatorSpacesNamespaceTransaction())
84 ->setTransactionType($type_desc)
85 ->setNewValue($v_desc);
87 $xactions[] = id(new PhabricatorSpacesNamespaceTransaction())
88 ->setTransactionType($type_view)
89 ->setNewValue($v_view);
91 $xactions[] = id(new PhabricatorSpacesNamespaceTransaction())
92 ->setTransactionType($type_edit)
93 ->setNewValue($v_edit);
96 $xactions[] = id(new PhabricatorSpacesNamespaceTransaction())
97 ->setTransactionType($type_default)
101 $editor = id(new PhabricatorSpacesNamespaceEditor())
103 ->setContinueOnNoEffect(true)
104 ->setContentSourceFromRequest($request);
107 $editor->applyTransactions($space, $xactions);
109 return id(new AphrontRedirectResponse())
110 ->setURI('/'.$space->getMonogram());
111 } catch (PhabricatorApplicationTransactionValidationException
$ex) {
112 $validation_exception = $ex;
114 $e_name = $ex->getShortMessage($type_name);
118 $policies = id(new PhabricatorPolicyQuery())
123 $form = id(new AphrontFormView())
127 $form->appendRemarkupInstructions(
129 'NOTE: You are creating the **default space**. All existing '.
130 'objects will be put into this space. You must create a default '.
131 'space before you can create other spaces.'));
136 id(new AphrontFormTextControl())
137 ->setLabel(pht('Name'))
142 id(new PhabricatorRemarkupControl())
143 ->setLabel(pht('Description'))
144 ->setName('description')
147 id(new AphrontFormPolicyControl())
149 ->setCapability(PhabricatorPolicyCapability
::CAN_VIEW
)
150 ->setPolicyObject($space)
151 ->setPolicies($policies)
153 ->setName('viewPolicy'))
155 id(new AphrontFormPolicyControl())
157 ->setCapability(PhabricatorPolicyCapability
::CAN_EDIT
)
158 ->setPolicyObject($space)
159 ->setPolicies($policies)
161 ->setName('editPolicy'))
163 id(new AphrontFormSubmitControl())
164 ->setValue($button_text)
165 ->addCancelButton($cancel_uri));
167 $box = id(new PHUIObjectBoxView())
168 ->setHeaderText($title)
169 ->setBackground(PHUIObjectBoxView
::WHITE_CONFIG
)
170 ->setValidationException($validation_exception)
171 ->appendChild($form);
173 $crumbs = $this->buildApplicationCrumbs();
175 $crumbs->addTextCrumb(
176 $space->getMonogram(),
179 $crumbs->addTextCrumb($title);
180 $crumbs->setBorder(true);
182 $view = id(new PHUITwoColumnView())
187 return $this->newPage()
190 ->appendChild($view);