@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.

Slightly modernize all Diffusion edit endpoints

Summary: Ref T4245. Prepares edit endpoints for more flexible repository identifiers.

Test Plan:
- Added, edited, deleted mirror.
- Created repository.
- Edited basic repository information.
- Edited policies for a repository.
- Activated/deactivated repository.
- Updated a repository.
- Hit "Delete" dialog for a repository.
- Edited hosting.
- Toggled dangerous changes.
- Edited branches.
- Edited automation.
- Tested automation.
- Edited storage.
- Edited staging.
- Edited encoding.
- Edited symbols.
- Edited branches.
- Edited actions.
- Tried to do edits as an unprivileged user.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T4245

Differential Revision: https://secure.phabricator.com/D14945

+234 -401
+12 -1
src/applications/diffusion/controller/DiffusionController.php
··· 52 52 return $this->processDiffusionRequest($request); 53 53 } 54 54 55 + protected function loadDiffusionContextForEdit() { 56 + return $this->loadContext( 57 + array( 58 + 'edit' => true, 59 + )); 60 + } 61 + 55 62 protected function loadDiffusionContext() { 63 + return $this->loadContext(array()); 64 + } 65 + 66 + private function loadContext(array $options) { 56 67 $request = $this->getRequest(); 57 68 $viewer = $this->getViewer(); 58 69 ··· 61 72 $identifier = (int)$request->getURIData('repositoryID'); 62 73 } 63 74 64 - $params = array( 75 + $params = $options + array( 65 76 'repository' => $identifier, 66 77 'user' => $viewer, 67 78 'blob' => $request->getURIData('dblob'),
+1 -5
src/applications/diffusion/controller/DiffusionMirrorDeleteController.php
··· 33 33 return id(new AphrontReloadResponse())->setURI($edit_uri); 34 34 } 35 35 36 - $dialog = id(new AphrontDialogView()) 37 - ->setUser($viewer) 36 + return $this->newDialog() 38 37 ->setTitle(pht('Really delete mirror?')) 39 38 ->appendChild( 40 39 pht('Phabricator will stop pushing updates to this mirror.')) 41 40 ->addSubmitButton(pht('Delete Mirror')) 42 41 ->addCancelButton($edit_uri); 43 - 44 - return id(new AphrontDialogResponse()) 45 - ->setDialog($dialog); 46 42 } 47 43 48 44
+1 -5
src/applications/diffusion/controller/DiffusionMirrorEditController.php
··· 117 117 ->setError($e_credentials) 118 118 ->setOptions($credentials)); 119 119 120 - $dialog = id(new AphrontDialogView()) 121 - ->setUser($viewer) 120 + return $this->newDialog() 122 121 ->setTitle($title) 123 122 ->setWidth(AphrontDialogView::WIDTH_FORM) 124 123 ->appendChild($form_errors) 125 124 ->appendChild($form) 126 125 ->addSubmitButton($submit) 127 126 ->addCancelButton($edit_uri); 128 - 129 - return id(new AphrontDialogResponse()) 130 - ->setDialog($dialog); 131 127 } 132 128 133 129
+10 -9
src/applications/diffusion/controller/DiffusionRepositoryCreateController.php
··· 6 6 private $edit; 7 7 private $repository; 8 8 9 - protected function processDiffusionRequest(AphrontRequest $request) { 9 + public function handleRequest(AphrontRequest $request) { 10 10 $viewer = $request->getUser(); 11 11 $this->edit = $request->getURIData('edit'); 12 12 ··· 19 19 switch ($this->edit) { 20 20 case 'remote': 21 21 case 'policy': 22 + $response = $this->loadDiffusionContextForEdit(); 23 + if ($response) { 24 + return $response; 25 + } 26 + 22 27 $repository = $this->getDiffusionRequest()->getRepository(); 23 28 24 29 // Make sure we have CAN_EDIT. ··· 275 280 $crumbs = $this->buildApplicationCrumbs(); 276 281 $crumbs->addTextCrumb($title); 277 282 278 - return $this->buildApplicationPage( 279 - array( 280 - $crumbs, 281 - $form, 282 - ), 283 - array( 284 - 'title' => $title, 285 - )); 283 + return $this->newPage() 284 + ->setTitle($title) 285 + ->setCrumbs($crumbs) 286 + ->appendChild($form); 286 287 } 287 288 288 289
+10 -2
src/applications/diffusion/controller/DiffusionRepositoryDefaultController.php
··· 2 2 3 3 final class DiffusionRepositoryDefaultController extends DiffusionController { 4 4 5 - protected function processDiffusionRequest(AphrontRequest $request) { 5 + public function handleRequest(AphrontRequest $request) { 6 + $response = $this->loadDiffusionContext(); 7 + if ($response) { 8 + return $response; 9 + } 10 + 6 11 // NOTE: This controller is just here to make sure we call 7 12 // willBeginExecution() on any /diffusion/X/ URI, so we can intercept 8 13 // `git`, `hg` and `svn` HTTP protocol requests. ··· 11 16 // clone URI with "/anything.git" at the end into their web browser. 12 17 // Send them to the canonical repository URI. 13 18 19 + $drequest = $this->getDiffusionRequest(); 20 + $repository = $drequest->getRepository(); 21 + 14 22 return id(new AphrontRedirectResponse()) 15 - ->setURI($this->getDiffusionRequest()->getRepository()->getURI()); 23 + ->setURI($repository->getURI()); 16 24 } 17 25 }
+12 -25
src/applications/diffusion/controller/DiffusionRepositoryEditActionsController.php
··· 3 3 final class DiffusionRepositoryEditActionsController 4 4 extends DiffusionRepositoryEditController { 5 5 6 - protected function processDiffusionRequest(AphrontRequest $request) { 7 - $viewer = $request->getUser(); 8 - $drequest = $this->diffusionRequest; 6 + public function handleRequest(AphrontRequest $request) { 7 + $response = $this->loadDiffusionContextForEdit(); 8 + if ($response) { 9 + return $response; 10 + } 11 + 12 + $viewer = $this->getViewer(); 13 + $drequest = $this->getDiffusionRequest(); 9 14 $repository = $drequest->getRepository(); 10 - 11 - $repository = id(new PhabricatorRepositoryQuery()) 12 - ->setViewer($viewer) 13 - ->requireCapabilities( 14 - array( 15 - PhabricatorPolicyCapability::CAN_VIEW, 16 - PhabricatorPolicyCapability::CAN_EDIT, 17 - )) 18 - ->withIDs(array($repository->getID())) 19 - ->executeOne(); 20 - 21 - if (!$repository) { 22 - return new Aphront404Response(); 23 - } 24 15 25 16 $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); 26 17 ··· 109 100 ->setHeaderText($title) 110 101 ->setForm($form); 111 102 112 - return $this->buildApplicationPage( 113 - array( 114 - $crumbs, 115 - $form_box, 116 - ), 117 - array( 118 - 'title' => $title, 119 - )); 103 + return $this->newPage() 104 + ->setTitle($title) 105 + ->setCrumbs($crumbs) 106 + ->appendChild($form_box); 120 107 } 121 108 122 109 }
+10 -26
src/applications/diffusion/controller/DiffusionRepositoryEditActivateController.php
··· 3 3 final class DiffusionRepositoryEditActivateController 4 4 extends DiffusionRepositoryEditController { 5 5 6 - protected function processDiffusionRequest(AphrontRequest $request) { 7 - $viewer = $request->getUser(); 8 - $drequest = $this->diffusionRequest; 9 - $repository = $drequest->getRepository(); 10 - 11 - $repository = id(new PhabricatorRepositoryQuery()) 12 - ->setViewer($viewer) 13 - ->requireCapabilities( 14 - array( 15 - PhabricatorPolicyCapability::CAN_VIEW, 16 - PhabricatorPolicyCapability::CAN_EDIT, 17 - )) 18 - ->withIDs(array($repository->getID())) 19 - ->executeOne(); 20 - 21 - if (!$repository) { 22 - return new Aphront404Response(); 6 + public function handleRequest(AphrontRequest $request) { 7 + $response = $this->loadDiffusionContextForEdit(); 8 + if ($response) { 9 + return $response; 23 10 } 11 + 12 + $viewer = $this->getViewer(); 13 + $drequest = $this->getDiffusionRequest(); 14 + $repository = $drequest->getRepository(); 24 15 25 16 $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); 26 17 ··· 38 29 return id(new AphrontReloadResponse())->setURI($edit_uri); 39 30 } 40 31 41 - $dialog = id(new AphrontDialogView()) 42 - ->setUser($viewer); 43 - 44 32 if ($repository->isTracked()) { 45 - $dialog 33 + return $this->newDialog() 46 34 ->setTitle(pht('Deactivate Repository?')) 47 35 ->appendChild( 48 36 pht('Deactivate this repository?')) 49 37 ->addSubmitButton(pht('Deactivate Repository')) 50 38 ->addCancelButton($edit_uri); 51 39 } else { 52 - $dialog 40 + return $this->newDialog() 53 41 ->setTitle(pht('Activate Repository?')) 54 42 ->appendChild( 55 43 pht('Activate this repository?')) 56 44 ->addSubmitButton(pht('Activate Repository')) 57 45 ->addCancelButton($edit_uri); 58 46 } 59 - 60 - return id(new AphrontDialogResponse()) 61 - ->setDialog($dialog); 62 47 } 63 - 64 48 65 49 }
+11 -23
src/applications/diffusion/controller/DiffusionRepositoryEditAutomationController.php
··· 3 3 final class DiffusionRepositoryEditAutomationController 4 4 extends DiffusionRepositoryEditController { 5 5 6 - protected function processDiffusionRequest(AphrontRequest $request) { 6 + public function handleRequest(AphrontRequest $request) { 7 + $response = $this->loadDiffusionContextForEdit(); 8 + if ($response) { 9 + return $response; 10 + } 11 + 7 12 $viewer = $this->getViewer(); 8 - $drequest = $this->diffusionRequest; 13 + $drequest = $this->getDiffusionRequest(); 9 14 $repository = $drequest->getRepository(); 10 - 11 - $repository = id(new PhabricatorRepositoryQuery()) 12 - ->setViewer($viewer) 13 - ->requireCapabilities( 14 - array( 15 - PhabricatorPolicyCapability::CAN_VIEW, 16 - PhabricatorPolicyCapability::CAN_EDIT, 17 - )) 18 - ->withIDs(array($repository->getID())) 19 - ->executeOne(); 20 - if (!$repository) { 21 - return new Aphront404Response(); 22 - } 23 15 24 16 if (!$repository->supportsAutomation()) { 25 17 return new Aphront404Response(); ··· 81 73 ->setHeaderText($title) 82 74 ->setForm($form); 83 75 84 - return $this->buildApplicationPage( 85 - array( 86 - $crumbs, 87 - $object_box, 88 - ), 89 - array( 90 - 'title' => $title, 91 - )); 76 + return $this->newPage() 77 + ->setTitle($title) 78 + ->setCrumbs($crumbs) 79 + ->appendChild($object_box); 92 80 } 93 81 94 82 }
+19 -30
src/applications/diffusion/controller/DiffusionRepositoryEditBasicController.php
··· 3 3 final class DiffusionRepositoryEditBasicController 4 4 extends DiffusionRepositoryEditController { 5 5 6 - protected function processDiffusionRequest(AphrontRequest $request) { 7 - $user = $request->getUser(); 8 - $drequest = $this->diffusionRequest; 6 + public function handleRequest(AphrontRequest $request) { 7 + $response = $this->loadDiffusionContextForEdit(); 8 + if ($response) { 9 + return $response; 10 + } 11 + 12 + $viewer = $request->getUser(); 13 + $drequest = $this->getDiffusionRequest(); 9 14 $repository = $drequest->getRepository(); 10 15 11 - $repository = id(new PhabricatorRepositoryQuery()) 12 - ->setViewer($user) 13 - ->requireCapabilities( 14 - array( 15 - PhabricatorPolicyCapability::CAN_VIEW, 16 - PhabricatorPolicyCapability::CAN_EDIT, 17 - )) 18 - ->needProjectPHIDs(true) 19 - ->withIDs(array($repository->getID())) 20 - ->executeOne(); 21 - 22 - if (!$repository) { 23 - return new Aphront404Response(); 24 - } 25 - 26 16 $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); 27 17 28 18 $v_name = $repository->getName(); 29 19 $v_desc = $repository->getDetail('description'); 30 20 $v_clone_name = $repository->getDetail('clone-name'); 21 + $v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs( 22 + $repository->getPHID(), 23 + PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); 31 24 $e_name = true; 32 25 $errors = array(); 33 26 ··· 81 74 id(new PhabricatorRepositoryEditor()) 82 75 ->setContinueOnNoEffect(true) 83 76 ->setContentSourceFromRequest($request) 84 - ->setActor($user) 77 + ->setActor($viewer) 85 78 ->applyTransactions($repository, $xactions); 86 79 87 80 return id(new AphrontRedirectResponse())->setURI($edit_uri); ··· 94 87 $title = pht('Edit %s', $repository->getName()); 95 88 96 89 $form = id(new AphrontFormView()) 97 - ->setUser($user) 90 + ->setUser($viewer) 98 91 ->appendChild( 99 92 id(new AphrontFormTextControl()) 100 93 ->setName('name') ··· 118 111 $form 119 112 ->appendChild( 120 113 id(new PhabricatorRemarkupControl()) 121 - ->setUser($user) 114 + ->setUser($viewer) 122 115 ->setName('description') 123 116 ->setLabel(pht('Description')) 124 117 ->setValue($v_desc)) ··· 127 120 ->setDatasource(new PhabricatorProjectDatasource()) 128 121 ->setName('projectPHIDs') 129 122 ->setLabel(pht('Projects')) 130 - ->setValue($repository->getProjectPHIDs())) 123 + ->setValue($v_projects)) 131 124 ->appendChild( 132 125 id(new AphrontFormSubmitControl()) 133 126 ->setValue(pht('Save')) ··· 140 133 ->setForm($form) 141 134 ->setFormErrors($errors); 142 135 143 - return $this->buildApplicationPage( 144 - array( 145 - $crumbs, 146 - $object_box, 147 - ), 148 - array( 149 - 'title' => $title, 150 - )); 136 + return $this->newPage() 137 + ->setTitle($title) 138 + ->setCrumbs($crumbs) 139 + ->appendChild($object_box); 151 140 } 152 141 153 142 private function getReadmeInstructions() {
+12 -25
src/applications/diffusion/controller/DiffusionRepositoryEditBranchesController.php
··· 3 3 final class DiffusionRepositoryEditBranchesController 4 4 extends DiffusionRepositoryEditController { 5 5 6 - protected function processDiffusionRequest(AphrontRequest $request) { 7 - $request = $this->getRequest(); 8 - $viewer = $request->getUser(); 9 - $drequest = $this->diffusionRequest; 6 + public function handleRequest(AphrontRequest $request) { 7 + $response = $this->loadDiffusionContextForEdit(); 8 + if ($response) { 9 + return $response; 10 + } 11 + 12 + $viewer = $this->getViewer(); 13 + $drequest = $this->getDiffusionRequest(); 10 14 $repository = $drequest->getRepository(); 11 - 12 - $repository = id(new PhabricatorRepositoryQuery()) 13 - ->setViewer($viewer) 14 - ->requireCapabilities( 15 - array( 16 - PhabricatorPolicyCapability::CAN_VIEW, 17 - PhabricatorPolicyCapability::CAN_EDIT, 18 - )) 19 - ->withIDs(array($repository->getID())) 20 - ->executeOne(); 21 - if (!$repository) { 22 - return new Aphront404Response(); 23 - } 24 15 25 16 $is_git = false; 26 17 $is_hg = false; ··· 226 217 ->setHeaderText($title) 227 218 ->setForm($form); 228 219 229 - return $this->buildApplicationPage( 230 - array( 231 - $crumbs, 232 - $form_box, 233 - ), 234 - array( 235 - 'title' => $title, 236 - )); 220 + return $this->newPage() 221 + ->setTitle($title) 222 + ->setCrumbs($crumbs) 223 + ->appendChild($form_box); 237 224 } 238 225 239 226 private function processBranches($string) {
+10 -25
src/applications/diffusion/controller/DiffusionRepositoryEditDangerousController.php
··· 3 3 final class DiffusionRepositoryEditDangerousController 4 4 extends DiffusionRepositoryEditController { 5 5 6 - protected function processDiffusionRequest(AphrontRequest $request) { 7 - $viewer = $request->getUser(); 8 - $drequest = $this->diffusionRequest; 6 + public function handleRequest(AphrontRequest $request) { 7 + $response = $this->loadDiffusionContextForEdit(); 8 + if ($response) { 9 + return $response; 10 + } 11 + 12 + $viewer = $this->getViewer(); 13 + $drequest = $this->getDiffusionRequest(); 9 14 $repository = $drequest->getRepository(); 10 15 11 - $repository = id(new PhabricatorRepositoryQuery()) 12 - ->setViewer($viewer) 13 - ->requireCapabilities( 14 - array( 15 - PhabricatorPolicyCapability::CAN_VIEW, 16 - PhabricatorPolicyCapability::CAN_EDIT, 17 - )) 18 - ->withIDs(array($repository->getID())) 19 - ->executeOne(); 20 - 21 - if (!$repository) { 22 - return new Aphront404Response(); 23 - } 24 - 25 16 if (!$repository->canAllowDangerousChanges()) { 26 17 return new Aphront400Response(); 27 18 } ··· 42 33 return id(new AphrontReloadResponse())->setURI($edit_uri); 43 34 } 44 35 45 - $dialog = id(new AphrontDialogView()) 46 - ->setUser($viewer); 47 - 48 36 $force = phutil_tag('tt', array(), '--force'); 49 37 50 38 if ($repository->shouldAllowDangerousChanges()) { 51 - $dialog 39 + return $this->newDialog() 52 40 ->setTitle(pht('Prevent Dangerous changes?')) 53 41 ->appendChild( 54 42 pht( ··· 58 46 ->addSubmitButton(pht('Prevent Dangerous Changes')) 59 47 ->addCancelButton($edit_uri); 60 48 } else { 61 - $dialog 49 + return $this->newDialog() 62 50 ->setTitle(pht('Allow Dangerous Changes?')) 63 51 ->appendChild( 64 52 pht( ··· 69 57 ->addSubmitButton(pht('Allow Dangerous Changes')) 70 58 ->addCancelButton($edit_uri); 71 59 } 72 - 73 - return id(new AphrontDialogResponse()) 74 - ->setDialog($dialog); 75 60 } 76 61 77 62 }
+9 -21
src/applications/diffusion/controller/DiffusionRepositoryEditDeleteController.php
··· 3 3 final class DiffusionRepositoryEditDeleteController 4 4 extends DiffusionRepositoryEditController { 5 5 6 - protected function processDiffusionRequest(AphrontRequest $request) { 7 - $viewer = $request->getUser(); 8 - $drequest = $this->diffusionRequest; 9 - $repository = $drequest->getRepository(); 10 - 11 - $repository = id(new PhabricatorRepositoryQuery()) 12 - ->setViewer($viewer) 13 - ->requireCapabilities( 14 - array( 15 - PhabricatorPolicyCapability::CAN_VIEW, 16 - PhabricatorPolicyCapability::CAN_EDIT, 17 - )) 18 - ->withIDs(array($repository->getID())) 19 - ->executeOne(); 20 - if (!$repository) { 21 - return new Aphront404Response(); 6 + public function handleRequest(AphrontRequest $request) { 7 + $response = $this->loadDiffusionContextForEdit(); 8 + if ($response) { 9 + return $response; 22 10 } 11 + 12 + $viewer = $this->getViewer(); 13 + $drequest = $this->getDiffusionRequest(); 14 + $repository = $drequest->getRepository(); 23 15 24 16 $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); 25 17 ··· 45 37 phutil_tag('p', array(), $text_2), 46 38 )); 47 39 48 - $dialog = id(new AphrontDialogView()) 49 - ->setUser($request->getUser()) 40 + return $this->newDialog() 50 41 ->setTitle(pht('Really want to delete the repository?')) 51 42 ->appendChild($body) 52 43 ->addCancelButton($edit_uri, pht('Okay')); 53 - 54 - return id(new AphrontDialogResponse())->setDialog($dialog); 55 44 } 56 - 57 45 58 46 }
+12 -25
src/applications/diffusion/controller/DiffusionRepositoryEditEncodingController.php
··· 3 3 final class DiffusionRepositoryEditEncodingController 4 4 extends DiffusionRepositoryEditController { 5 5 6 - protected function processDiffusionRequest(AphrontRequest $request) { 7 - $user = $request->getUser(); 8 - $drequest = $this->diffusionRequest; 6 + public function handleRequest(AphrontRequest $request) { 7 + $response = $this->loadDiffusionContextForEdit(); 8 + if ($response) { 9 + return $response; 10 + } 11 + 12 + $user = $this->getViewer(); 13 + $drequest = $this->getDiffusionRequest(); 9 14 $repository = $drequest->getRepository(); 10 - 11 - $repository = id(new PhabricatorRepositoryQuery()) 12 - ->setViewer($user) 13 - ->requireCapabilities( 14 - array( 15 - PhabricatorPolicyCapability::CAN_VIEW, 16 - PhabricatorPolicyCapability::CAN_EDIT, 17 - )) 18 - ->withIDs(array($repository->getID())) 19 - ->executeOne(); 20 - 21 - if (!$repository) { 22 - return new Aphront404Response(); 23 - } 24 15 25 16 $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); 26 17 ··· 79 70 ->setForm($form) 80 71 ->setFormErrors($errors); 81 72 82 - return $this->buildApplicationPage( 83 - array( 84 - $crumbs, 85 - $object_box, 86 - ), 87 - array( 88 - 'title' => $title, 89 - )); 73 + return $this->newPage() 74 + ->setTitle($title) 75 + ->setCrumbs($crumbs) 76 + ->appendChild($object_box); 90 77 } 91 78 92 79 private function getEncodingInstructions() {
+16 -32
src/applications/diffusion/controller/DiffusionRepositoryEditHostingController.php
··· 5 5 6 6 private $serve; 7 7 8 - protected function processDiffusionRequest(AphrontRequest $request) { 9 - $user = $request->getUser(); 10 - $drequest = $this->diffusionRequest; 8 + public function handleRequest(AphrontRequest $request) { 9 + $response = $this->loadDiffusionContextForEdit(); 10 + if ($response) { 11 + return $response; 12 + } 13 + 14 + $drequest = $this->getDiffusionRequest(); 11 15 $repository = $drequest->getRepository(); 12 - $this->serve = $request->getURIData('serve'); 13 16 14 - $repository = id(new PhabricatorRepositoryQuery()) 15 - ->setViewer($user) 16 - ->requireCapabilities( 17 - array( 18 - PhabricatorPolicyCapability::CAN_VIEW, 19 - PhabricatorPolicyCapability::CAN_EDIT, 20 - )) 21 - ->withIDs(array($repository->getID())) 22 - ->executeOne(); 23 - if (!$repository) { 24 - return new Aphront404Response(); 25 - } 17 + $this->serve = $request->getURIData('serve'); 26 18 27 19 if (!$this->serve) { 28 20 return $this->handleHosting($repository); ··· 107 99 ->setHeaderText($title) 108 100 ->setForm($form); 109 101 110 - return $this->buildApplicationPage( 111 - array( 112 - $crumbs, 113 - $object_box, 114 - ), 115 - array( 116 - 'title' => $title, 117 - )); 102 + return $this->newPage() 103 + ->setTitle($title) 104 + ->setCrumbs($crumbs) 105 + ->appendChild($object_box); 118 106 } 119 107 120 108 public function handleProtocols(PhabricatorRepository $repository) { ··· 272 260 ->setHeaderText($title) 273 261 ->setForm($form); 274 262 275 - return $this->buildApplicationPage( 276 - array( 277 - $crumbs, 278 - $object_box, 279 - ), 280 - array( 281 - 'title' => $title, 282 - )); 263 + return $this->newPage() 264 + ->setTitle($title) 265 + ->setCrumbs($crumbs) 266 + ->appendChild($object_box); 283 267 } 284 268 285 269 }
+8 -8
src/applications/diffusion/controller/DiffusionRepositoryEditMainController.php
··· 3 3 final class DiffusionRepositoryEditMainController 4 4 extends DiffusionRepositoryEditController { 5 5 6 - protected function processDiffusionRequest(AphrontRequest $request) { 7 - $viewer = $request->getUser(); 8 - $drequest = $this->diffusionRequest; 9 - $repository = $drequest->getRepository(); 6 + public function handleRequest(AphrontRequest $request) { 7 + $response = $this->loadDiffusionContextForEdit(); 8 + if ($response) { 9 + return $response; 10 + } 10 11 11 - PhabricatorPolicyFilter::requireCapability( 12 - $viewer, 13 - $repository, 14 - PhabricatorPolicyCapability::CAN_EDIT); 12 + $viewer = $this->getViewer(); 13 + $drequest = $this->getDiffusionRequest(); 14 + $repository = $drequest->getRepository(); 15 15 16 16 $is_svn = false; 17 17 $is_git = false;
+14 -25
src/applications/diffusion/controller/DiffusionRepositoryEditStagingController.php
··· 3 3 final class DiffusionRepositoryEditStagingController 4 4 extends DiffusionRepositoryEditController { 5 5 6 - protected function processDiffusionRequest(AphrontRequest $request) { 7 - $user = $request->getUser(); 8 - $drequest = $this->diffusionRequest; 6 + public function handleRequest(AphrontRequest $request) { 7 + $response = $this->loadDiffusionContextForEdit(); 8 + if ($response) { 9 + return $response; 10 + } 11 + 12 + $viewer = $this->getViewer(); 13 + $drequest = $this->getDiffusionRequest(); 9 14 $repository = $drequest->getRepository(); 10 15 11 - $repository = id(new PhabricatorRepositoryQuery()) 12 - ->setViewer($user) 13 - ->requireCapabilities( 14 - array( 15 - PhabricatorPolicyCapability::CAN_VIEW, 16 - PhabricatorPolicyCapability::CAN_EDIT, 17 - )) 18 - ->withIDs(array($repository->getID())) 19 - ->executeOne(); 20 - if (!$repository) { 21 - return new Aphront404Response(); 22 - } 23 16 24 17 if (!$repository->supportsStaging()) { 25 18 return new Aphront404Response(); ··· 43 36 id(new PhabricatorRepositoryEditor()) 44 37 ->setContinueOnNoEffect(true) 45 38 ->setContentSourceFromRequest($request) 46 - ->setActor($user) 39 + ->setActor($viewer) 47 40 ->applyTransactions($repository, $xactions); 48 41 49 42 return id(new AphrontRedirectResponse())->setURI($edit_uri); ··· 55 48 $title = pht('Edit %s', $repository->getName()); 56 49 57 50 $form = id(new AphrontFormView()) 58 - ->setUser($user) 51 + ->setUser($viewer) 59 52 ->appendRemarkupInstructions( 60 53 pht( 61 54 "To make it easier to run integration tests and builds on code ". ··· 79 72 ->setHeaderText($title) 80 73 ->setForm($form); 81 74 82 - return $this->buildApplicationPage( 83 - array( 84 - $crumbs, 85 - $object_box, 86 - ), 87 - array( 88 - 'title' => $title, 89 - )); 75 + return $this->newPage() 76 + ->setTitle($title) 77 + ->setCrumbs($crumbs) 78 + ->appendChild($object_box); 90 79 } 91 80 92 81 }
+14 -27
src/applications/diffusion/controller/DiffusionRepositoryEditStorageController.php
··· 3 3 final class DiffusionRepositoryEditStorageController 4 4 extends DiffusionRepositoryEditController { 5 5 6 - protected function processDiffusionRequest(AphrontRequest $request) { 7 - $user = $request->getUser(); 8 - $drequest = $this->diffusionRequest; 6 + public function handleRequest(AphrontRequest $request) { 7 + $response = $this->loadDiffusionContextForEdit(); 8 + if ($response) { 9 + return $response; 10 + } 11 + 12 + $viewer = $this->getViewer(); 13 + $drequest = $this->getDiffusionRequest(); 9 14 $repository = $drequest->getRepository(); 10 15 11 - $repository = id(new PhabricatorRepositoryQuery()) 12 - ->setViewer($user) 13 - ->requireCapabilities( 14 - array( 15 - PhabricatorPolicyCapability::CAN_VIEW, 16 - PhabricatorPolicyCapability::CAN_EDIT, 17 - )) 18 - ->withIDs(array($repository->getID())) 19 - ->executeOne(); 20 - 21 - if (!$repository) { 22 - return new Aphront404Response(); 23 - } 24 - 25 16 $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); 26 17 27 18 $v_local = $repository->getHumanReadableDetail('local-path'); ··· 44 35 } 45 36 46 37 $form = id(new AphrontFormView()) 47 - ->setUser($user) 38 + ->setUser($viewer) 48 39 ->appendChild( 49 40 id(new AphrontFormMarkupControl()) 50 41 ->setLabel(pht('Storage Service')) ··· 61 52 sprintf( 62 53 'phabricator/ $ ./bin/repository edit %s --as %s --local-path ...', 63 54 $repository->getMonogram(), 64 - $user->getUsername()))) 55 + $viewer->getUsername()))) 65 56 ->appendChild( 66 57 id(new AphrontFormSubmitControl()) 67 58 ->addCancelButton($edit_uri, pht('Done'))); ··· 71 62 ->setForm($form) 72 63 ->setFormErrors($errors); 73 64 74 - return $this->buildApplicationPage( 75 - array( 76 - $crumbs, 77 - $object_box, 78 - ), 79 - array( 80 - 'title' => $title, 81 - )); 65 + return $this->newPage() 66 + ->setTitle($title) 67 + ->setCrumbs($crumbs) 68 + ->appendChild($object_box); 82 69 } 83 70 84 71 }
+12 -25
src/applications/diffusion/controller/DiffusionRepositoryEditSubversionController.php
··· 3 3 final class DiffusionRepositoryEditSubversionController 4 4 extends DiffusionRepositoryEditController { 5 5 6 - protected function processDiffusionRequest(AphrontRequest $request) { 7 - $viewer = $request->getUser(); 8 - $drequest = $this->diffusionRequest; 6 + public function handleRequest(AphrontRequest $request) { 7 + $response = $this->loadDiffusionContextForEdit(); 8 + if ($response) { 9 + return $response; 10 + } 11 + 12 + $viewer = $this->getViewer(); 13 + $drequest = $this->getDiffusionRequest(); 9 14 $repository = $drequest->getRepository(); 10 - 11 - $repository = id(new PhabricatorRepositoryQuery()) 12 - ->setViewer($viewer) 13 - ->requireCapabilities( 14 - array( 15 - PhabricatorPolicyCapability::CAN_VIEW, 16 - PhabricatorPolicyCapability::CAN_EDIT, 17 - )) 18 - ->withIDs(array($repository->getID())) 19 - ->executeOne(); 20 - 21 - if (!$repository) { 22 - return new Aphront404Response(); 23 - } 24 15 25 16 switch ($repository->getVersionControlSystem()) { 26 17 case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: ··· 108 99 ->setHeaderText($title) 109 100 ->setForm($form); 110 101 111 - return $this->buildApplicationPage( 112 - array( 113 - $crumbs, 114 - $form_box, 115 - ), 116 - array( 117 - 'title' => $title, 118 - )); 102 + return $this->newPage() 103 + ->setTitle($title) 104 + ->setCrumbs($crumbs) 105 + ->appendChild($form_box); 119 106 } 120 107 121 108 }
+8 -16
src/applications/diffusion/controller/DiffusionRepositoryEditUpdateController.php
··· 3 3 final class DiffusionRepositoryEditUpdateController 4 4 extends DiffusionRepositoryEditController { 5 5 6 - protected function processDiffusionRequest(AphrontRequest $request) { 7 - $viewer = $request->getUser(); 8 - $drequest = $this->diffusionRequest; 9 - $repository = $drequest->getRepository(); 10 - 11 - $repository = id(new PhabricatorRepositoryQuery()) 12 - ->setViewer($viewer) 13 - ->requireCapabilities( 14 - array( 15 - PhabricatorPolicyCapability::CAN_VIEW, 16 - PhabricatorPolicyCapability::CAN_EDIT, 17 - )) 18 - ->withIDs(array($repository->getID())) 19 - ->executeOne(); 20 - if (!$repository) { 21 - return new Aphront404Response(); 6 + public function handleRequest(AphrontRequest $request) { 7 + $response = $this->loadDiffusionContextForEdit(); 8 + if ($response) { 9 + return $response; 22 10 } 11 + 12 + $viewer = $this->getViewer(); 13 + $drequest = $this->getDiffusionRequest(); 14 + $repository = $drequest->getRepository(); 23 15 24 16 $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); 25 17
+14 -27
src/applications/diffusion/controller/DiffusionRepositorySymbolsController.php
··· 3 3 final class DiffusionRepositorySymbolsController 4 4 extends DiffusionRepositoryEditController { 5 5 6 - protected function processDiffusionRequest(AphrontRequest $request) { 7 - $user = $request->getUser(); 8 - $drequest = $this->diffusionRequest; 6 + public function handleRequest(AphrontRequest $request) { 7 + $response = $this->loadDiffusionContextForEdit(); 8 + if ($response) { 9 + return $response; 10 + } 11 + 12 + $viewer = $this->getViewer(); 13 + $drequest = $this->getDiffusionRequest(); 9 14 $repository = $drequest->getRepository(); 10 15 11 - $repository = id(new PhabricatorRepositoryQuery()) 12 - ->setViewer($user) 13 - ->requireCapabilities( 14 - array( 15 - PhabricatorPolicyCapability::CAN_VIEW, 16 - PhabricatorPolicyCapability::CAN_EDIT, 17 - )) 18 - ->withIDs(array($repository->getID())) 19 - ->executeOne(); 20 - 21 - if (!$repository) { 22 - return new Aphront404Response(); 23 - } 24 - 25 16 $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); 26 17 27 18 $v_sources = $repository->getSymbolSources(); ··· 55 46 id(new PhabricatorRepositoryEditor()) 56 47 ->setContinueOnNoEffect(true) 57 48 ->setContentSourceFromRequest($request) 58 - ->setActor($user) 49 + ->setActor($viewer) 59 50 ->applyTransactions($repository, $xactions); 60 51 61 52 return id(new AphrontRedirectResponse())->setURI($edit_uri); ··· 71 62 $title = pht('Edit %s', $repository->getName()); 72 63 73 64 $form = id(new AphrontFormView()) 74 - ->setUser($user) 65 + ->setUser($viewer) 75 66 ->appendRemarkupInstructions($this->getInstructions()) 76 67 ->appendChild( 77 68 id(new AphrontFormTextControl()) ··· 99 90 ->setForm($form) 100 91 ->setFormErrors($errors); 101 92 102 - return $this->buildApplicationPage( 103 - array( 104 - $crumbs, 105 - $object_box, 106 - ), 107 - array( 108 - 'title' => $title, 109 - )); 93 + return $this->newPage() 94 + ->setTitle($title) 95 + ->setCrumbs($crumbs) 96 + ->appendChild($object_box); 110 97 } 111 98 112 99 private function getInstructions() {
+1 -14
src/applications/diffusion/controller/DiffusionRepositoryTestAutomationController.php
··· 4 4 extends DiffusionRepositoryEditController { 5 5 6 6 public function handleRequest(AphrontRequest $request) { 7 - $response = $this->loadDiffusionContext(); 7 + $response = $this->loadDiffusionContextForEdit(); 8 8 if ($response) { 9 9 return $response; 10 10 } ··· 12 12 $viewer = $this->getViewer(); 13 13 $drequest = $this->getDiffusionRequest(); 14 14 $repository = $drequest->getRepository(); 15 - 16 - $repository = id(new PhabricatorRepositoryQuery()) 17 - ->setViewer($viewer) 18 - ->requireCapabilities( 19 - array( 20 - PhabricatorPolicyCapability::CAN_VIEW, 21 - PhabricatorPolicyCapability::CAN_EDIT, 22 - )) 23 - ->withIDs(array($repository->getID())) 24 - ->executeOne(); 25 - if (!$repository) { 26 - return new Aphront404Response(); 27 - } 28 15 29 16 $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); 30 17
+18 -5
src/applications/diffusion/request/DiffusionRequest.php
··· 100 100 } 101 101 102 102 if ($identifier !== null) { 103 - $object = self::newFromIdentifier($identifier, $data[$viewer_key]); 103 + $object = self::newFromIdentifier( 104 + $identifier, 105 + $data[$viewer_key], 106 + idx($data, 'edit')); 104 107 } else { 105 108 $object = self::newFromRepository($repository); 106 109 } ··· 171 174 */ 172 175 final private static function newFromIdentifier( 173 176 $identifier, 174 - PhabricatorUser $viewer) { 177 + PhabricatorUser $viewer, 178 + $need_edit = false) { 175 179 176 - $repository = id(new PhabricatorRepositoryQuery()) 180 + $query = id(new PhabricatorRepositoryQuery()) 177 181 ->setViewer($viewer) 178 - ->withIdentifiers(array($identifier)) 179 - ->executeOne(); 182 + ->withIdentifiers(array($identifier)); 183 + 184 + if ($need_edit) { 185 + $query->requireCapabilities( 186 + array( 187 + PhabricatorPolicyCapability::CAN_VIEW, 188 + PhabricatorPolicyCapability::CAN_EDIT, 189 + )); 190 + } 191 + 192 + $repository = $query->executeOne(); 180 193 181 194 if (!$repository) { 182 195 return null;