@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at recaptime-dev/main 192 lines 5.9 kB view raw
1<?php 2 3final class PhabricatorSpacesEditController 4 extends PhabricatorSpacesController { 5 6 public function handleRequest(AphrontRequest $request) { 7 $viewer = $request->getUser(); 8 9 $make_default = false; 10 11 $id = $request->getURIData('id'); 12 if ($id) { 13 $space = id(new PhabricatorSpacesNamespaceQuery()) 14 ->setViewer($viewer) 15 ->withIDs(array($id)) 16 ->requireCapabilities( 17 array( 18 PhabricatorPolicyCapability::CAN_VIEW, 19 PhabricatorPolicyCapability::CAN_EDIT, 20 )) 21 ->executeOne(); 22 if (!$space) { 23 return new Aphront404Response(); 24 } 25 26 $is_new = false; 27 $cancel_uri = '/'.$space->getMonogram(); 28 29 $header_text = pht('Edit %s', $space->getNamespaceName()); 30 $title = pht('Edit Space'); 31 $button_text = pht('Save Changes'); 32 } else { 33 $this->requireApplicationCapability( 34 PhabricatorSpacesCapabilityCreateSpaces::CAPABILITY); 35 36 $space = PhabricatorSpacesNamespace::initializeNewNamespace($viewer); 37 38 $is_new = true; 39 $cancel_uri = $this->getApplicationURI(); 40 41 $header_text = pht('Create Space'); 42 $title = pht('Create Space'); 43 $button_text = pht('Create Space'); 44 45 $default = id(new PhabricatorSpacesNamespaceQuery()) 46 ->setViewer(PhabricatorUser::getOmnipotentUser()) 47 ->withIsDefaultNamespace(true) 48 ->execute(); 49 if (!$default) { 50 $make_default = true; 51 } 52 } 53 54 $validation_exception = null; 55 $e_name = true; 56 $v_name = $space->getNamespaceName(); 57 $v_desc = $space->getDescription(); 58 $v_view = $space->getViewPolicy(); 59 $v_edit = $space->getEditPolicy(); 60 61 if ($request->isFormPost()) { 62 $xactions = array(); 63 $e_name = null; 64 65 $v_name = $request->getStr('name'); 66 $v_desc = $request->getStr('description'); 67 $v_view = $request->getStr('viewPolicy'); 68 $v_edit = $request->getStr('editPolicy'); 69 70 $type_name = 71 PhabricatorSpacesNamespaceNameTransaction::TRANSACTIONTYPE; 72 $type_desc = 73 PhabricatorSpacesNamespaceDescriptionTransaction::TRANSACTIONTYPE; 74 $type_default = 75 PhabricatorSpacesNamespaceDefaultTransaction::TRANSACTIONTYPE; 76 $type_view = PhabricatorTransactions::TYPE_VIEW_POLICY; 77 $type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY; 78 79 $xactions[] = id(new PhabricatorSpacesNamespaceTransaction()) 80 ->setTransactionType($type_name) 81 ->setNewValue($v_name); 82 83 $xactions[] = id(new PhabricatorSpacesNamespaceTransaction()) 84 ->setTransactionType($type_desc) 85 ->setNewValue($v_desc); 86 87 $xactions[] = id(new PhabricatorSpacesNamespaceTransaction()) 88 ->setTransactionType($type_view) 89 ->setNewValue($v_view); 90 91 $xactions[] = id(new PhabricatorSpacesNamespaceTransaction()) 92 ->setTransactionType($type_edit) 93 ->setNewValue($v_edit); 94 95 if ($make_default) { 96 $xactions[] = id(new PhabricatorSpacesNamespaceTransaction()) 97 ->setTransactionType($type_default) 98 ->setNewValue(1); 99 } 100 101 $editor = id(new PhabricatorSpacesNamespaceEditor()) 102 ->setActor($viewer) 103 ->setContinueOnNoEffect(true) 104 ->setContentSourceFromRequest($request); 105 106 try { 107 $editor->applyTransactions($space, $xactions); 108 109 return id(new AphrontRedirectResponse()) 110 ->setURI('/'.$space->getMonogram()); 111 } catch (PhabricatorApplicationTransactionValidationException $ex) { 112 $validation_exception = $ex; 113 114 $e_name = $ex->getShortMessage($type_name); 115 } 116 } 117 118 $policies = id(new PhabricatorPolicyQuery()) 119 ->setViewer($viewer) 120 ->setObject($space) 121 ->execute(); 122 123 $form = id(new AphrontFormView()) 124 ->setViewer($viewer); 125 126 if ($make_default) { 127 $form->appendRemarkupInstructions( 128 pht( 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.')); 132 } 133 134 $form 135 ->appendChild( 136 id(new AphrontFormTextControl()) 137 ->setLabel(pht('Name')) 138 ->setName('name') 139 ->setValue($v_name) 140 ->setError($e_name)) 141 ->appendControl( 142 id(new PhabricatorRemarkupControl()) 143 ->setLabel(pht('Description')) 144 ->setName('description') 145 ->setValue($v_desc)) 146 ->appendChild( 147 id(new AphrontFormPolicyControl()) 148 ->setViewer($viewer) 149 ->setCapability(PhabricatorPolicyCapability::CAN_VIEW) 150 ->setPolicyObject($space) 151 ->setPolicies($policies) 152 ->setValue($v_view) 153 ->setName('viewPolicy')) 154 ->appendChild( 155 id(new AphrontFormPolicyControl()) 156 ->setViewer($viewer) 157 ->setCapability(PhabricatorPolicyCapability::CAN_EDIT) 158 ->setPolicyObject($space) 159 ->setPolicies($policies) 160 ->setValue($v_edit) 161 ->setName('editPolicy')) 162 ->appendChild( 163 id(new AphrontFormSubmitControl()) 164 ->setValue($button_text) 165 ->addCancelButton($cancel_uri)); 166 167 $box = id(new PHUIObjectBoxView()) 168 ->setHeaderText($title) 169 ->setBackground(PHUIObjectBoxView::WHITE_CONFIG) 170 ->setValidationException($validation_exception) 171 ->appendChild($form); 172 173 $crumbs = $this->buildApplicationCrumbs(); 174 if (!$is_new) { 175 $crumbs->addTextCrumb( 176 $space->getMonogram(), 177 $cancel_uri); 178 } 179 $crumbs->addTextCrumb($title); 180 $crumbs->setBorder(true); 181 182 $view = id(new PHUITwoColumnView()) 183 ->setFooter(array( 184 $box, 185 )); 186 187 return $this->newPage() 188 ->setTitle($title) 189 ->setCrumbs($crumbs) 190 ->appendChild($view); 191 } 192}