From 649f8827205aeaf6e4f8a88c41902f759f158f28 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 5 Jan 2016 08:49:10 -0800 Subject: [PATCH] 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 --- .../controller/DiffusionController.php | 13 ++++- .../DiffusionMirrorDeleteController.php | 6 +-- .../DiffusionMirrorEditController.php | 6 +-- .../DiffusionRepositoryCreateController.php | 19 +++---- .../DiffusionRepositoryDefaultController.php | 12 ++++- ...ffusionRepositoryEditActionsController.php | 37 +++++--------- ...fusionRepositoryEditActivateController.php | 36 ++++--------- ...sionRepositoryEditAutomationController.php | 36 +++++-------- ...DiffusionRepositoryEditBasicController.php | 49 +++++++----------- ...fusionRepositoryEditBranchesController.php | 37 +++++--------- ...usionRepositoryEditDangerousController.php | 35 ++++--------- ...iffusionRepositoryEditDeleteController.php | 30 ++++------- ...fusionRepositoryEditEncodingController.php | 37 +++++--------- ...ffusionRepositoryEditHostingController.php | 50 +++++++------------ .../DiffusionRepositoryEditMainController.php | 16 +++--- ...ffusionRepositoryEditStagingController.php | 39 ++++++--------- ...ffusionRepositoryEditStorageController.php | 41 ++++++--------- ...sionRepositoryEditSubversionController.php | 37 +++++--------- ...iffusionRepositoryEditUpdateController.php | 24 +++------ .../DiffusionRepositorySymbolsController.php | 41 ++++++--------- ...sionRepositoryTestAutomationController.php | 15 +----- .../diffusion/request/DiffusionRequest.php | 23 +++++++-- 22 files changed, 236 insertions(+), 403 deletions(-) diff --git a/src/applications/diffusion/controller/DiffusionController.php b/src/applications/diffusion/controller/DiffusionController.php index dc916c7e9e..63f3897b7f 100644 --- a/src/applications/diffusion/controller/DiffusionController.php +++ b/src/applications/diffusion/controller/DiffusionController.php @@ -52,7 +52,18 @@ abstract class DiffusionController extends PhabricatorController { return $this->processDiffusionRequest($request); } + protected function loadDiffusionContextForEdit() { + return $this->loadContext( + array( + 'edit' => true, + )); + } + protected function loadDiffusionContext() { + return $this->loadContext(array()); + } + + private function loadContext(array $options) { $request = $this->getRequest(); $viewer = $this->getViewer(); @@ -61,7 +72,7 @@ abstract class DiffusionController extends PhabricatorController { $identifier = (int)$request->getURIData('repositoryID'); } - $params = array( + $params = $options + array( 'repository' => $identifier, 'user' => $viewer, 'blob' => $request->getURIData('dblob'), diff --git a/src/applications/diffusion/controller/DiffusionMirrorDeleteController.php b/src/applications/diffusion/controller/DiffusionMirrorDeleteController.php index c49cdb7517..a049146cb5 100644 --- a/src/applications/diffusion/controller/DiffusionMirrorDeleteController.php +++ b/src/applications/diffusion/controller/DiffusionMirrorDeleteController.php @@ -33,16 +33,12 @@ final class DiffusionMirrorDeleteController return id(new AphrontReloadResponse())->setURI($edit_uri); } - $dialog = id(new AphrontDialogView()) - ->setUser($viewer) + return $this->newDialog() ->setTitle(pht('Really delete mirror?')) ->appendChild( pht('Phabricator will stop pushing updates to this mirror.')) ->addSubmitButton(pht('Delete Mirror')) ->addCancelButton($edit_uri); - - return id(new AphrontDialogResponse()) - ->setDialog($dialog); } diff --git a/src/applications/diffusion/controller/DiffusionMirrorEditController.php b/src/applications/diffusion/controller/DiffusionMirrorEditController.php index f5793f2afe..d438a9e6d2 100644 --- a/src/applications/diffusion/controller/DiffusionMirrorEditController.php +++ b/src/applications/diffusion/controller/DiffusionMirrorEditController.php @@ -117,17 +117,13 @@ final class DiffusionMirrorEditController ->setError($e_credentials) ->setOptions($credentials)); - $dialog = id(new AphrontDialogView()) - ->setUser($viewer) + return $this->newDialog() ->setTitle($title) ->setWidth(AphrontDialogView::WIDTH_FORM) ->appendChild($form_errors) ->appendChild($form) ->addSubmitButton($submit) ->addCancelButton($edit_uri); - - return id(new AphrontDialogResponse()) - ->setDialog($dialog); } diff --git a/src/applications/diffusion/controller/DiffusionRepositoryCreateController.php b/src/applications/diffusion/controller/DiffusionRepositoryCreateController.php index 79c617f220..c6e2796fc1 100644 --- a/src/applications/diffusion/controller/DiffusionRepositoryCreateController.php +++ b/src/applications/diffusion/controller/DiffusionRepositoryCreateController.php @@ -6,7 +6,7 @@ final class DiffusionRepositoryCreateController private $edit; private $repository; - protected function processDiffusionRequest(AphrontRequest $request) { + public function handleRequest(AphrontRequest $request) { $viewer = $request->getUser(); $this->edit = $request->getURIData('edit'); @@ -19,6 +19,11 @@ final class DiffusionRepositoryCreateController switch ($this->edit) { case 'remote': case 'policy': + $response = $this->loadDiffusionContextForEdit(); + if ($response) { + return $response; + } + $repository = $this->getDiffusionRequest()->getRepository(); // Make sure we have CAN_EDIT. @@ -275,14 +280,10 @@ final class DiffusionRepositoryCreateController $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb($title); - return $this->buildApplicationPage( - array( - $crumbs, - $form, - ), - array( - 'title' => $title, - )); + return $this->newPage() + ->setTitle($title) + ->setCrumbs($crumbs) + ->appendChild($form); } diff --git a/src/applications/diffusion/controller/DiffusionRepositoryDefaultController.php b/src/applications/diffusion/controller/DiffusionRepositoryDefaultController.php index 9b72c66eea..efebd12c6f 100644 --- a/src/applications/diffusion/controller/DiffusionRepositoryDefaultController.php +++ b/src/applications/diffusion/controller/DiffusionRepositoryDefaultController.php @@ -2,7 +2,12 @@ final class DiffusionRepositoryDefaultController extends DiffusionController { - protected function processDiffusionRequest(AphrontRequest $request) { + public function handleRequest(AphrontRequest $request) { + $response = $this->loadDiffusionContext(); + if ($response) { + return $response; + } + // NOTE: This controller is just here to make sure we call // willBeginExecution() on any /diffusion/X/ URI, so we can intercept // `git`, `hg` and `svn` HTTP protocol requests. @@ -11,7 +16,10 @@ final class DiffusionRepositoryDefaultController extends DiffusionController { // clone URI with "/anything.git" at the end into their web browser. // Send them to the canonical repository URI. + $drequest = $this->getDiffusionRequest(); + $repository = $drequest->getRepository(); + return id(new AphrontRedirectResponse()) - ->setURI($this->getDiffusionRequest()->getRepository()->getURI()); + ->setURI($repository->getURI()); } } diff --git a/src/applications/diffusion/controller/DiffusionRepositoryEditActionsController.php b/src/applications/diffusion/controller/DiffusionRepositoryEditActionsController.php index 2b0bc674be..8459498374 100644 --- a/src/applications/diffusion/controller/DiffusionRepositoryEditActionsController.php +++ b/src/applications/diffusion/controller/DiffusionRepositoryEditActionsController.php @@ -3,25 +3,16 @@ final class DiffusionRepositoryEditActionsController extends DiffusionRepositoryEditController { - protected function processDiffusionRequest(AphrontRequest $request) { - $viewer = $request->getUser(); - $drequest = $this->diffusionRequest; - $repository = $drequest->getRepository(); - - $repository = id(new PhabricatorRepositoryQuery()) - ->setViewer($viewer) - ->requireCapabilities( - array( - PhabricatorPolicyCapability::CAN_VIEW, - PhabricatorPolicyCapability::CAN_EDIT, - )) - ->withIDs(array($repository->getID())) - ->executeOne(); - - if (!$repository) { - return new Aphront404Response(); + public function handleRequest(AphrontRequest $request) { + $response = $this->loadDiffusionContextForEdit(); + if ($response) { + return $response; } + $viewer = $this->getViewer(); + $drequest = $this->getDiffusionRequest(); + $repository = $drequest->getRepository(); + $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); // NOTE: We're inverting these here, because the storage is silly. @@ -109,14 +100,10 @@ final class DiffusionRepositoryEditActionsController ->setHeaderText($title) ->setForm($form); - return $this->buildApplicationPage( - array( - $crumbs, - $form_box, - ), - array( - 'title' => $title, - )); + return $this->newPage() + ->setTitle($title) + ->setCrumbs($crumbs) + ->appendChild($form_box); } } diff --git a/src/applications/diffusion/controller/DiffusionRepositoryEditActivateController.php b/src/applications/diffusion/controller/DiffusionRepositoryEditActivateController.php index 2342530195..c8428833ee 100644 --- a/src/applications/diffusion/controller/DiffusionRepositoryEditActivateController.php +++ b/src/applications/diffusion/controller/DiffusionRepositoryEditActivateController.php @@ -3,25 +3,16 @@ final class DiffusionRepositoryEditActivateController extends DiffusionRepositoryEditController { - protected function processDiffusionRequest(AphrontRequest $request) { - $viewer = $request->getUser(); - $drequest = $this->diffusionRequest; - $repository = $drequest->getRepository(); - - $repository = id(new PhabricatorRepositoryQuery()) - ->setViewer($viewer) - ->requireCapabilities( - array( - PhabricatorPolicyCapability::CAN_VIEW, - PhabricatorPolicyCapability::CAN_EDIT, - )) - ->withIDs(array($repository->getID())) - ->executeOne(); - - if (!$repository) { - return new Aphront404Response(); + public function handleRequest(AphrontRequest $request) { + $response = $this->loadDiffusionContextForEdit(); + if ($response) { + return $response; } + $viewer = $this->getViewer(); + $drequest = $this->getDiffusionRequest(); + $repository = $drequest->getRepository(); + $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); if ($request->isFormPost()) { @@ -38,28 +29,21 @@ final class DiffusionRepositoryEditActivateController return id(new AphrontReloadResponse())->setURI($edit_uri); } - $dialog = id(new AphrontDialogView()) - ->setUser($viewer); - if ($repository->isTracked()) { - $dialog + return $this->newDialog() ->setTitle(pht('Deactivate Repository?')) ->appendChild( pht('Deactivate this repository?')) ->addSubmitButton(pht('Deactivate Repository')) ->addCancelButton($edit_uri); } else { - $dialog + return $this->newDialog() ->setTitle(pht('Activate Repository?')) ->appendChild( pht('Activate this repository?')) ->addSubmitButton(pht('Activate Repository')) ->addCancelButton($edit_uri); } - - return id(new AphrontDialogResponse()) - ->setDialog($dialog); } - } diff --git a/src/applications/diffusion/controller/DiffusionRepositoryEditAutomationController.php b/src/applications/diffusion/controller/DiffusionRepositoryEditAutomationController.php index 8fe5b70f97..e47bde3902 100644 --- a/src/applications/diffusion/controller/DiffusionRepositoryEditAutomationController.php +++ b/src/applications/diffusion/controller/DiffusionRepositoryEditAutomationController.php @@ -3,24 +3,16 @@ final class DiffusionRepositoryEditAutomationController extends DiffusionRepositoryEditController { - protected function processDiffusionRequest(AphrontRequest $request) { - $viewer = $this->getViewer(); - $drequest = $this->diffusionRequest; - $repository = $drequest->getRepository(); - - $repository = id(new PhabricatorRepositoryQuery()) - ->setViewer($viewer) - ->requireCapabilities( - array( - PhabricatorPolicyCapability::CAN_VIEW, - PhabricatorPolicyCapability::CAN_EDIT, - )) - ->withIDs(array($repository->getID())) - ->executeOne(); - if (!$repository) { - return new Aphront404Response(); + public function handleRequest(AphrontRequest $request) { + $response = $this->loadDiffusionContextForEdit(); + if ($response) { + return $response; } + $viewer = $this->getViewer(); + $drequest = $this->getDiffusionRequest(); + $repository = $drequest->getRepository(); + if (!$repository->supportsAutomation()) { return new Aphront404Response(); } @@ -81,14 +73,10 @@ final class DiffusionRepositoryEditAutomationController ->setHeaderText($title) ->setForm($form); - return $this->buildApplicationPage( - array( - $crumbs, - $object_box, - ), - array( - 'title' => $title, - )); + return $this->newPage() + ->setTitle($title) + ->setCrumbs($crumbs) + ->appendChild($object_box); } } diff --git a/src/applications/diffusion/controller/DiffusionRepositoryEditBasicController.php b/src/applications/diffusion/controller/DiffusionRepositoryEditBasicController.php index 80771f65c4..5b4429b61a 100644 --- a/src/applications/diffusion/controller/DiffusionRepositoryEditBasicController.php +++ b/src/applications/diffusion/controller/DiffusionRepositoryEditBasicController.php @@ -3,31 +3,24 @@ final class DiffusionRepositoryEditBasicController extends DiffusionRepositoryEditController { - protected function processDiffusionRequest(AphrontRequest $request) { - $user = $request->getUser(); - $drequest = $this->diffusionRequest; - $repository = $drequest->getRepository(); - - $repository = id(new PhabricatorRepositoryQuery()) - ->setViewer($user) - ->requireCapabilities( - array( - PhabricatorPolicyCapability::CAN_VIEW, - PhabricatorPolicyCapability::CAN_EDIT, - )) - ->needProjectPHIDs(true) - ->withIDs(array($repository->getID())) - ->executeOne(); - - if (!$repository) { - return new Aphront404Response(); + public function handleRequest(AphrontRequest $request) { + $response = $this->loadDiffusionContextForEdit(); + if ($response) { + return $response; } + $viewer = $request->getUser(); + $drequest = $this->getDiffusionRequest(); + $repository = $drequest->getRepository(); + $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); $v_name = $repository->getName(); $v_desc = $repository->getDetail('description'); $v_clone_name = $repository->getDetail('clone-name'); + $v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs( + $repository->getPHID(), + PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); $e_name = true; $errors = array(); @@ -81,7 +74,7 @@ final class DiffusionRepositoryEditBasicController id(new PhabricatorRepositoryEditor()) ->setContinueOnNoEffect(true) ->setContentSourceFromRequest($request) - ->setActor($user) + ->setActor($viewer) ->applyTransactions($repository, $xactions); return id(new AphrontRedirectResponse())->setURI($edit_uri); @@ -94,7 +87,7 @@ final class DiffusionRepositoryEditBasicController $title = pht('Edit %s', $repository->getName()); $form = id(new AphrontFormView()) - ->setUser($user) + ->setUser($viewer) ->appendChild( id(new AphrontFormTextControl()) ->setName('name') @@ -118,7 +111,7 @@ final class DiffusionRepositoryEditBasicController $form ->appendChild( id(new PhabricatorRemarkupControl()) - ->setUser($user) + ->setUser($viewer) ->setName('description') ->setLabel(pht('Description')) ->setValue($v_desc)) @@ -127,7 +120,7 @@ final class DiffusionRepositoryEditBasicController ->setDatasource(new PhabricatorProjectDatasource()) ->setName('projectPHIDs') ->setLabel(pht('Projects')) - ->setValue($repository->getProjectPHIDs())) + ->setValue($v_projects)) ->appendChild( id(new AphrontFormSubmitControl()) ->setValue(pht('Save')) @@ -140,14 +133,10 @@ final class DiffusionRepositoryEditBasicController ->setForm($form) ->setFormErrors($errors); - return $this->buildApplicationPage( - array( - $crumbs, - $object_box, - ), - array( - 'title' => $title, - )); + return $this->newPage() + ->setTitle($title) + ->setCrumbs($crumbs) + ->appendChild($object_box); } private function getReadmeInstructions() { diff --git a/src/applications/diffusion/controller/DiffusionRepositoryEditBranchesController.php b/src/applications/diffusion/controller/DiffusionRepositoryEditBranchesController.php index a175fba941..c256336ec2 100644 --- a/src/applications/diffusion/controller/DiffusionRepositoryEditBranchesController.php +++ b/src/applications/diffusion/controller/DiffusionRepositoryEditBranchesController.php @@ -3,25 +3,16 @@ final class DiffusionRepositoryEditBranchesController extends DiffusionRepositoryEditController { - protected function processDiffusionRequest(AphrontRequest $request) { - $request = $this->getRequest(); - $viewer = $request->getUser(); - $drequest = $this->diffusionRequest; - $repository = $drequest->getRepository(); - - $repository = id(new PhabricatorRepositoryQuery()) - ->setViewer($viewer) - ->requireCapabilities( - array( - PhabricatorPolicyCapability::CAN_VIEW, - PhabricatorPolicyCapability::CAN_EDIT, - )) - ->withIDs(array($repository->getID())) - ->executeOne(); - if (!$repository) { - return new Aphront404Response(); + public function handleRequest(AphrontRequest $request) { + $response = $this->loadDiffusionContextForEdit(); + if ($response) { + return $response; } + $viewer = $this->getViewer(); + $drequest = $this->getDiffusionRequest(); + $repository = $drequest->getRepository(); + $is_git = false; $is_hg = false; @@ -226,14 +217,10 @@ final class DiffusionRepositoryEditBranchesController ->setHeaderText($title) ->setForm($form); - return $this->buildApplicationPage( - array( - $crumbs, - $form_box, - ), - array( - 'title' => $title, - )); + return $this->newPage() + ->setTitle($title) + ->setCrumbs($crumbs) + ->appendChild($form_box); } private function processBranches($string) { diff --git a/src/applications/diffusion/controller/DiffusionRepositoryEditDangerousController.php b/src/applications/diffusion/controller/DiffusionRepositoryEditDangerousController.php index 076c2580e5..26d8b57f33 100644 --- a/src/applications/diffusion/controller/DiffusionRepositoryEditDangerousController.php +++ b/src/applications/diffusion/controller/DiffusionRepositoryEditDangerousController.php @@ -3,25 +3,16 @@ final class DiffusionRepositoryEditDangerousController extends DiffusionRepositoryEditController { - protected function processDiffusionRequest(AphrontRequest $request) { - $viewer = $request->getUser(); - $drequest = $this->diffusionRequest; - $repository = $drequest->getRepository(); - - $repository = id(new PhabricatorRepositoryQuery()) - ->setViewer($viewer) - ->requireCapabilities( - array( - PhabricatorPolicyCapability::CAN_VIEW, - PhabricatorPolicyCapability::CAN_EDIT, - )) - ->withIDs(array($repository->getID())) - ->executeOne(); - - if (!$repository) { - return new Aphront404Response(); + public function handleRequest(AphrontRequest $request) { + $response = $this->loadDiffusionContextForEdit(); + if ($response) { + return $response; } + $viewer = $this->getViewer(); + $drequest = $this->getDiffusionRequest(); + $repository = $drequest->getRepository(); + if (!$repository->canAllowDangerousChanges()) { return new Aphront400Response(); } @@ -42,13 +33,10 @@ final class DiffusionRepositoryEditDangerousController return id(new AphrontReloadResponse())->setURI($edit_uri); } - $dialog = id(new AphrontDialogView()) - ->setUser($viewer); - $force = phutil_tag('tt', array(), '--force'); if ($repository->shouldAllowDangerousChanges()) { - $dialog + return $this->newDialog() ->setTitle(pht('Prevent Dangerous changes?')) ->appendChild( pht( @@ -58,7 +46,7 @@ final class DiffusionRepositoryEditDangerousController ->addSubmitButton(pht('Prevent Dangerous Changes')) ->addCancelButton($edit_uri); } else { - $dialog + return $this->newDialog() ->setTitle(pht('Allow Dangerous Changes?')) ->appendChild( pht( @@ -69,9 +57,6 @@ final class DiffusionRepositoryEditDangerousController ->addSubmitButton(pht('Allow Dangerous Changes')) ->addCancelButton($edit_uri); } - - return id(new AphrontDialogResponse()) - ->setDialog($dialog); } } diff --git a/src/applications/diffusion/controller/DiffusionRepositoryEditDeleteController.php b/src/applications/diffusion/controller/DiffusionRepositoryEditDeleteController.php index f39708fe1b..074e79445b 100644 --- a/src/applications/diffusion/controller/DiffusionRepositoryEditDeleteController.php +++ b/src/applications/diffusion/controller/DiffusionRepositoryEditDeleteController.php @@ -3,24 +3,16 @@ final class DiffusionRepositoryEditDeleteController extends DiffusionRepositoryEditController { - protected function processDiffusionRequest(AphrontRequest $request) { - $viewer = $request->getUser(); - $drequest = $this->diffusionRequest; - $repository = $drequest->getRepository(); - - $repository = id(new PhabricatorRepositoryQuery()) - ->setViewer($viewer) - ->requireCapabilities( - array( - PhabricatorPolicyCapability::CAN_VIEW, - PhabricatorPolicyCapability::CAN_EDIT, - )) - ->withIDs(array($repository->getID())) - ->executeOne(); - if (!$repository) { - return new Aphront404Response(); + public function handleRequest(AphrontRequest $request) { + $response = $this->loadDiffusionContextForEdit(); + if ($response) { + return $response; } + $viewer = $this->getViewer(); + $drequest = $this->getDiffusionRequest(); + $repository = $drequest->getRepository(); + $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); $dialog = new AphrontDialogView(); @@ -45,14 +37,10 @@ final class DiffusionRepositoryEditDeleteController phutil_tag('p', array(), $text_2), )); - $dialog = id(new AphrontDialogView()) - ->setUser($request->getUser()) + return $this->newDialog() ->setTitle(pht('Really want to delete the repository?')) ->appendChild($body) ->addCancelButton($edit_uri, pht('Okay')); - - return id(new AphrontDialogResponse())->setDialog($dialog); } - } diff --git a/src/applications/diffusion/controller/DiffusionRepositoryEditEncodingController.php b/src/applications/diffusion/controller/DiffusionRepositoryEditEncodingController.php index f71516e6ca..0059c9d6c0 100644 --- a/src/applications/diffusion/controller/DiffusionRepositoryEditEncodingController.php +++ b/src/applications/diffusion/controller/DiffusionRepositoryEditEncodingController.php @@ -3,25 +3,16 @@ final class DiffusionRepositoryEditEncodingController extends DiffusionRepositoryEditController { - protected function processDiffusionRequest(AphrontRequest $request) { - $user = $request->getUser(); - $drequest = $this->diffusionRequest; - $repository = $drequest->getRepository(); - - $repository = id(new PhabricatorRepositoryQuery()) - ->setViewer($user) - ->requireCapabilities( - array( - PhabricatorPolicyCapability::CAN_VIEW, - PhabricatorPolicyCapability::CAN_EDIT, - )) - ->withIDs(array($repository->getID())) - ->executeOne(); - - if (!$repository) { - return new Aphront404Response(); + public function handleRequest(AphrontRequest $request) { + $response = $this->loadDiffusionContextForEdit(); + if ($response) { + return $response; } + $user = $this->getViewer(); + $drequest = $this->getDiffusionRequest(); + $repository = $drequest->getRepository(); + $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); $v_encoding = $repository->getDetail('encoding'); @@ -79,14 +70,10 @@ final class DiffusionRepositoryEditEncodingController ->setForm($form) ->setFormErrors($errors); - return $this->buildApplicationPage( - array( - $crumbs, - $object_box, - ), - array( - 'title' => $title, - )); + return $this->newPage() + ->setTitle($title) + ->setCrumbs($crumbs) + ->appendChild($object_box); } private function getEncodingInstructions() { diff --git a/src/applications/diffusion/controller/DiffusionRepositoryEditHostingController.php b/src/applications/diffusion/controller/DiffusionRepositoryEditHostingController.php index 1fcf366967..be40b794b3 100644 --- a/src/applications/diffusion/controller/DiffusionRepositoryEditHostingController.php +++ b/src/applications/diffusion/controller/DiffusionRepositoryEditHostingController.php @@ -5,25 +5,17 @@ final class DiffusionRepositoryEditHostingController private $serve; - protected function processDiffusionRequest(AphrontRequest $request) { - $user = $request->getUser(); - $drequest = $this->diffusionRequest; - $repository = $drequest->getRepository(); - $this->serve = $request->getURIData('serve'); - - $repository = id(new PhabricatorRepositoryQuery()) - ->setViewer($user) - ->requireCapabilities( - array( - PhabricatorPolicyCapability::CAN_VIEW, - PhabricatorPolicyCapability::CAN_EDIT, - )) - ->withIDs(array($repository->getID())) - ->executeOne(); - if (!$repository) { - return new Aphront404Response(); + public function handleRequest(AphrontRequest $request) { + $response = $this->loadDiffusionContextForEdit(); + if ($response) { + return $response; } + $drequest = $this->getDiffusionRequest(); + $repository = $drequest->getRepository(); + + $this->serve = $request->getURIData('serve'); + if (!$this->serve) { return $this->handleHosting($repository); } else { @@ -107,14 +99,10 @@ final class DiffusionRepositoryEditHostingController ->setHeaderText($title) ->setForm($form); - return $this->buildApplicationPage( - array( - $crumbs, - $object_box, - ), - array( - 'title' => $title, - )); + return $this->newPage() + ->setTitle($title) + ->setCrumbs($crumbs) + ->appendChild($object_box); } public function handleProtocols(PhabricatorRepository $repository) { @@ -272,14 +260,10 @@ final class DiffusionRepositoryEditHostingController ->setHeaderText($title) ->setForm($form); - return $this->buildApplicationPage( - array( - $crumbs, - $object_box, - ), - array( - 'title' => $title, - )); + return $this->newPage() + ->setTitle($title) + ->setCrumbs($crumbs) + ->appendChild($object_box); } } diff --git a/src/applications/diffusion/controller/DiffusionRepositoryEditMainController.php b/src/applications/diffusion/controller/DiffusionRepositoryEditMainController.php index 780e83d089..1e19d45e7c 100644 --- a/src/applications/diffusion/controller/DiffusionRepositoryEditMainController.php +++ b/src/applications/diffusion/controller/DiffusionRepositoryEditMainController.php @@ -3,15 +3,15 @@ final class DiffusionRepositoryEditMainController extends DiffusionRepositoryEditController { - protected function processDiffusionRequest(AphrontRequest $request) { - $viewer = $request->getUser(); - $drequest = $this->diffusionRequest; - $repository = $drequest->getRepository(); + public function handleRequest(AphrontRequest $request) { + $response = $this->loadDiffusionContextForEdit(); + if ($response) { + return $response; + } - PhabricatorPolicyFilter::requireCapability( - $viewer, - $repository, - PhabricatorPolicyCapability::CAN_EDIT); + $viewer = $this->getViewer(); + $drequest = $this->getDiffusionRequest(); + $repository = $drequest->getRepository(); $is_svn = false; $is_git = false; diff --git a/src/applications/diffusion/controller/DiffusionRepositoryEditStagingController.php b/src/applications/diffusion/controller/DiffusionRepositoryEditStagingController.php index 9fcfd767c0..deb8fad669 100644 --- a/src/applications/diffusion/controller/DiffusionRepositoryEditStagingController.php +++ b/src/applications/diffusion/controller/DiffusionRepositoryEditStagingController.php @@ -3,23 +3,16 @@ final class DiffusionRepositoryEditStagingController extends DiffusionRepositoryEditController { - protected function processDiffusionRequest(AphrontRequest $request) { - $user = $request->getUser(); - $drequest = $this->diffusionRequest; + public function handleRequest(AphrontRequest $request) { + $response = $this->loadDiffusionContextForEdit(); + if ($response) { + return $response; + } + + $viewer = $this->getViewer(); + $drequest = $this->getDiffusionRequest(); $repository = $drequest->getRepository(); - $repository = id(new PhabricatorRepositoryQuery()) - ->setViewer($user) - ->requireCapabilities( - array( - PhabricatorPolicyCapability::CAN_VIEW, - PhabricatorPolicyCapability::CAN_EDIT, - )) - ->withIDs(array($repository->getID())) - ->executeOne(); - if (!$repository) { - return new Aphront404Response(); - } if (!$repository->supportsStaging()) { return new Aphront404Response(); @@ -43,7 +36,7 @@ final class DiffusionRepositoryEditStagingController id(new PhabricatorRepositoryEditor()) ->setContinueOnNoEffect(true) ->setContentSourceFromRequest($request) - ->setActor($user) + ->setActor($viewer) ->applyTransactions($repository, $xactions); return id(new AphrontRedirectResponse())->setURI($edit_uri); @@ -55,7 +48,7 @@ final class DiffusionRepositoryEditStagingController $title = pht('Edit %s', $repository->getName()); $form = id(new AphrontFormView()) - ->setUser($user) + ->setUser($viewer) ->appendRemarkupInstructions( pht( "To make it easier to run integration tests and builds on code ". @@ -79,14 +72,10 @@ final class DiffusionRepositoryEditStagingController ->setHeaderText($title) ->setForm($form); - return $this->buildApplicationPage( - array( - $crumbs, - $object_box, - ), - array( - 'title' => $title, - )); + return $this->newPage() + ->setTitle($title) + ->setCrumbs($crumbs) + ->appendChild($object_box); } } diff --git a/src/applications/diffusion/controller/DiffusionRepositoryEditStorageController.php b/src/applications/diffusion/controller/DiffusionRepositoryEditStorageController.php index 4afa594ed9..711844188a 100644 --- a/src/applications/diffusion/controller/DiffusionRepositoryEditStorageController.php +++ b/src/applications/diffusion/controller/DiffusionRepositoryEditStorageController.php @@ -3,25 +3,16 @@ final class DiffusionRepositoryEditStorageController extends DiffusionRepositoryEditController { - protected function processDiffusionRequest(AphrontRequest $request) { - $user = $request->getUser(); - $drequest = $this->diffusionRequest; - $repository = $drequest->getRepository(); - - $repository = id(new PhabricatorRepositoryQuery()) - ->setViewer($user) - ->requireCapabilities( - array( - PhabricatorPolicyCapability::CAN_VIEW, - PhabricatorPolicyCapability::CAN_EDIT, - )) - ->withIDs(array($repository->getID())) - ->executeOne(); - - if (!$repository) { - return new Aphront404Response(); + public function handleRequest(AphrontRequest $request) { + $response = $this->loadDiffusionContextForEdit(); + if ($response) { + return $response; } + $viewer = $this->getViewer(); + $drequest = $this->getDiffusionRequest(); + $repository = $drequest->getRepository(); + $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); $v_local = $repository->getHumanReadableDetail('local-path'); @@ -44,7 +35,7 @@ final class DiffusionRepositoryEditStorageController } $form = id(new AphrontFormView()) - ->setUser($user) + ->setUser($viewer) ->appendChild( id(new AphrontFormMarkupControl()) ->setLabel(pht('Storage Service')) @@ -61,7 +52,7 @@ final class DiffusionRepositoryEditStorageController sprintf( 'phabricator/ $ ./bin/repository edit %s --as %s --local-path ...', $repository->getMonogram(), - $user->getUsername()))) + $viewer->getUsername()))) ->appendChild( id(new AphrontFormSubmitControl()) ->addCancelButton($edit_uri, pht('Done'))); @@ -71,14 +62,10 @@ final class DiffusionRepositoryEditStorageController ->setForm($form) ->setFormErrors($errors); - return $this->buildApplicationPage( - array( - $crumbs, - $object_box, - ), - array( - 'title' => $title, - )); + return $this->newPage() + ->setTitle($title) + ->setCrumbs($crumbs) + ->appendChild($object_box); } } diff --git a/src/applications/diffusion/controller/DiffusionRepositoryEditSubversionController.php b/src/applications/diffusion/controller/DiffusionRepositoryEditSubversionController.php index b125f26cae..93b9193f14 100644 --- a/src/applications/diffusion/controller/DiffusionRepositoryEditSubversionController.php +++ b/src/applications/diffusion/controller/DiffusionRepositoryEditSubversionController.php @@ -3,25 +3,16 @@ final class DiffusionRepositoryEditSubversionController extends DiffusionRepositoryEditController { - protected function processDiffusionRequest(AphrontRequest $request) { - $viewer = $request->getUser(); - $drequest = $this->diffusionRequest; - $repository = $drequest->getRepository(); - - $repository = id(new PhabricatorRepositoryQuery()) - ->setViewer($viewer) - ->requireCapabilities( - array( - PhabricatorPolicyCapability::CAN_VIEW, - PhabricatorPolicyCapability::CAN_EDIT, - )) - ->withIDs(array($repository->getID())) - ->executeOne(); - - if (!$repository) { - return new Aphront404Response(); + public function handleRequest(AphrontRequest $request) { + $response = $this->loadDiffusionContextForEdit(); + if ($response) { + return $response; } + $viewer = $this->getViewer(); + $drequest = $this->getDiffusionRequest(); + $repository = $drequest->getRepository(); + switch ($repository->getVersionControlSystem()) { case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: @@ -108,14 +99,10 @@ final class DiffusionRepositoryEditSubversionController ->setHeaderText($title) ->setForm($form); - return $this->buildApplicationPage( - array( - $crumbs, - $form_box, - ), - array( - 'title' => $title, - )); + return $this->newPage() + ->setTitle($title) + ->setCrumbs($crumbs) + ->appendChild($form_box); } } diff --git a/src/applications/diffusion/controller/DiffusionRepositoryEditUpdateController.php b/src/applications/diffusion/controller/DiffusionRepositoryEditUpdateController.php index 74df9c488b..303959d098 100644 --- a/src/applications/diffusion/controller/DiffusionRepositoryEditUpdateController.php +++ b/src/applications/diffusion/controller/DiffusionRepositoryEditUpdateController.php @@ -3,24 +3,16 @@ final class DiffusionRepositoryEditUpdateController extends DiffusionRepositoryEditController { - protected function processDiffusionRequest(AphrontRequest $request) { - $viewer = $request->getUser(); - $drequest = $this->diffusionRequest; - $repository = $drequest->getRepository(); - - $repository = id(new PhabricatorRepositoryQuery()) - ->setViewer($viewer) - ->requireCapabilities( - array( - PhabricatorPolicyCapability::CAN_VIEW, - PhabricatorPolicyCapability::CAN_EDIT, - )) - ->withIDs(array($repository->getID())) - ->executeOne(); - if (!$repository) { - return new Aphront404Response(); + public function handleRequest(AphrontRequest $request) { + $response = $this->loadDiffusionContextForEdit(); + if ($response) { + return $response; } + $viewer = $this->getViewer(); + $drequest = $this->getDiffusionRequest(); + $repository = $drequest->getRepository(); + $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); if ($request->isFormPost()) { diff --git a/src/applications/diffusion/controller/DiffusionRepositorySymbolsController.php b/src/applications/diffusion/controller/DiffusionRepositorySymbolsController.php index 133ee38813..6076d2df65 100644 --- a/src/applications/diffusion/controller/DiffusionRepositorySymbolsController.php +++ b/src/applications/diffusion/controller/DiffusionRepositorySymbolsController.php @@ -3,25 +3,16 @@ final class DiffusionRepositorySymbolsController extends DiffusionRepositoryEditController { - protected function processDiffusionRequest(AphrontRequest $request) { - $user = $request->getUser(); - $drequest = $this->diffusionRequest; - $repository = $drequest->getRepository(); - - $repository = id(new PhabricatorRepositoryQuery()) - ->setViewer($user) - ->requireCapabilities( - array( - PhabricatorPolicyCapability::CAN_VIEW, - PhabricatorPolicyCapability::CAN_EDIT, - )) - ->withIDs(array($repository->getID())) - ->executeOne(); - - if (!$repository) { - return new Aphront404Response(); + public function handleRequest(AphrontRequest $request) { + $response = $this->loadDiffusionContextForEdit(); + if ($response) { + return $response; } + $viewer = $this->getViewer(); + $drequest = $this->getDiffusionRequest(); + $repository = $drequest->getRepository(); + $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); $v_sources = $repository->getSymbolSources(); @@ -55,7 +46,7 @@ final class DiffusionRepositorySymbolsController id(new PhabricatorRepositoryEditor()) ->setContinueOnNoEffect(true) ->setContentSourceFromRequest($request) - ->setActor($user) + ->setActor($viewer) ->applyTransactions($repository, $xactions); return id(new AphrontRedirectResponse())->setURI($edit_uri); @@ -71,7 +62,7 @@ final class DiffusionRepositorySymbolsController $title = pht('Edit %s', $repository->getName()); $form = id(new AphrontFormView()) - ->setUser($user) + ->setUser($viewer) ->appendRemarkupInstructions($this->getInstructions()) ->appendChild( id(new AphrontFormTextControl()) @@ -99,14 +90,10 @@ final class DiffusionRepositorySymbolsController ->setForm($form) ->setFormErrors($errors); - return $this->buildApplicationPage( - array( - $crumbs, - $object_box, - ), - array( - 'title' => $title, - )); + return $this->newPage() + ->setTitle($title) + ->setCrumbs($crumbs) + ->appendChild($object_box); } private function getInstructions() { diff --git a/src/applications/diffusion/controller/DiffusionRepositoryTestAutomationController.php b/src/applications/diffusion/controller/DiffusionRepositoryTestAutomationController.php index 691564c68e..c52b0a14e9 100644 --- a/src/applications/diffusion/controller/DiffusionRepositoryTestAutomationController.php +++ b/src/applications/diffusion/controller/DiffusionRepositoryTestAutomationController.php @@ -4,7 +4,7 @@ final class DiffusionRepositoryTestAutomationController extends DiffusionRepositoryEditController { public function handleRequest(AphrontRequest $request) { - $response = $this->loadDiffusionContext(); + $response = $this->loadDiffusionContextForEdit(); if ($response) { return $response; } @@ -13,19 +13,6 @@ final class DiffusionRepositoryTestAutomationController $drequest = $this->getDiffusionRequest(); $repository = $drequest->getRepository(); - $repository = id(new PhabricatorRepositoryQuery()) - ->setViewer($viewer) - ->requireCapabilities( - array( - PhabricatorPolicyCapability::CAN_VIEW, - PhabricatorPolicyCapability::CAN_EDIT, - )) - ->withIDs(array($repository->getID())) - ->executeOne(); - if (!$repository) { - return new Aphront404Response(); - } - $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); if (!$repository->canPerformAutomation()) { diff --git a/src/applications/diffusion/request/DiffusionRequest.php b/src/applications/diffusion/request/DiffusionRequest.php index 08b7c876c2..72c911f5bb 100644 --- a/src/applications/diffusion/request/DiffusionRequest.php +++ b/src/applications/diffusion/request/DiffusionRequest.php @@ -100,7 +100,10 @@ abstract class DiffusionRequest extends Phobject { } if ($identifier !== null) { - $object = self::newFromIdentifier($identifier, $data[$viewer_key]); + $object = self::newFromIdentifier( + $identifier, + $data[$viewer_key], + idx($data, 'edit')); } else { $object = self::newFromRepository($repository); } @@ -171,12 +174,22 @@ abstract class DiffusionRequest extends Phobject { */ final private static function newFromIdentifier( $identifier, - PhabricatorUser $viewer) { + PhabricatorUser $viewer, + $need_edit = false) { - $repository = id(new PhabricatorRepositoryQuery()) + $query = id(new PhabricatorRepositoryQuery()) ->setViewer($viewer) - ->withIdentifiers(array($identifier)) - ->executeOne(); + ->withIdentifiers(array($identifier)); + + if ($need_edit) { + $query->requireCapabilities( + array( + PhabricatorPolicyCapability::CAN_VIEW, + PhabricatorPolicyCapability::CAN_EDIT, + )); + } + + $repository = $query->executeOne(); if (!$repository) { return null;