1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 12:00:55 +01:00

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
This commit is contained in:
epriestley 2016-01-05 08:49:10 -08:00
parent 2bfc5ff92e
commit 649f882720
22 changed files with 236 additions and 403 deletions

View file

@ -52,7 +52,18 @@ abstract class DiffusionController extends PhabricatorController {
return $this->processDiffusionRequest($request); return $this->processDiffusionRequest($request);
} }
protected function loadDiffusionContextForEdit() {
return $this->loadContext(
array(
'edit' => true,
));
}
protected function loadDiffusionContext() { protected function loadDiffusionContext() {
return $this->loadContext(array());
}
private function loadContext(array $options) {
$request = $this->getRequest(); $request = $this->getRequest();
$viewer = $this->getViewer(); $viewer = $this->getViewer();
@ -61,7 +72,7 @@ abstract class DiffusionController extends PhabricatorController {
$identifier = (int)$request->getURIData('repositoryID'); $identifier = (int)$request->getURIData('repositoryID');
} }
$params = array( $params = $options + array(
'repository' => $identifier, 'repository' => $identifier,
'user' => $viewer, 'user' => $viewer,
'blob' => $request->getURIData('dblob'), 'blob' => $request->getURIData('dblob'),

View file

@ -33,16 +33,12 @@ final class DiffusionMirrorDeleteController
return id(new AphrontReloadResponse())->setURI($edit_uri); return id(new AphrontReloadResponse())->setURI($edit_uri);
} }
$dialog = id(new AphrontDialogView()) return $this->newDialog()
->setUser($viewer)
->setTitle(pht('Really delete mirror?')) ->setTitle(pht('Really delete mirror?'))
->appendChild( ->appendChild(
pht('Phabricator will stop pushing updates to this mirror.')) pht('Phabricator will stop pushing updates to this mirror.'))
->addSubmitButton(pht('Delete Mirror')) ->addSubmitButton(pht('Delete Mirror'))
->addCancelButton($edit_uri); ->addCancelButton($edit_uri);
return id(new AphrontDialogResponse())
->setDialog($dialog);
} }

View file

@ -117,17 +117,13 @@ final class DiffusionMirrorEditController
->setError($e_credentials) ->setError($e_credentials)
->setOptions($credentials)); ->setOptions($credentials));
$dialog = id(new AphrontDialogView()) return $this->newDialog()
->setUser($viewer)
->setTitle($title) ->setTitle($title)
->setWidth(AphrontDialogView::WIDTH_FORM) ->setWidth(AphrontDialogView::WIDTH_FORM)
->appendChild($form_errors) ->appendChild($form_errors)
->appendChild($form) ->appendChild($form)
->addSubmitButton($submit) ->addSubmitButton($submit)
->addCancelButton($edit_uri); ->addCancelButton($edit_uri);
return id(new AphrontDialogResponse())
->setDialog($dialog);
} }

View file

@ -6,7 +6,7 @@ final class DiffusionRepositoryCreateController
private $edit; private $edit;
private $repository; private $repository;
protected function processDiffusionRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$viewer = $request->getUser(); $viewer = $request->getUser();
$this->edit = $request->getURIData('edit'); $this->edit = $request->getURIData('edit');
@ -19,6 +19,11 @@ final class DiffusionRepositoryCreateController
switch ($this->edit) { switch ($this->edit) {
case 'remote': case 'remote':
case 'policy': case 'policy':
$response = $this->loadDiffusionContextForEdit();
if ($response) {
return $response;
}
$repository = $this->getDiffusionRequest()->getRepository(); $repository = $this->getDiffusionRequest()->getRepository();
// Make sure we have CAN_EDIT. // Make sure we have CAN_EDIT.
@ -275,14 +280,10 @@ final class DiffusionRepositoryCreateController
$crumbs = $this->buildApplicationCrumbs(); $crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($title); $crumbs->addTextCrumb($title);
return $this->buildApplicationPage( return $this->newPage()
array( ->setTitle($title)
$crumbs, ->setCrumbs($crumbs)
$form, ->appendChild($form);
),
array(
'title' => $title,
));
} }

View file

@ -2,7 +2,12 @@
final class DiffusionRepositoryDefaultController extends DiffusionController { 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 // NOTE: This controller is just here to make sure we call
// willBeginExecution() on any /diffusion/X/ URI, so we can intercept // willBeginExecution() on any /diffusion/X/ URI, so we can intercept
// `git`, `hg` and `svn` HTTP protocol requests. // `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. // clone URI with "/anything.git" at the end into their web browser.
// Send them to the canonical repository URI. // Send them to the canonical repository URI.
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
return id(new AphrontRedirectResponse()) return id(new AphrontRedirectResponse())
->setURI($this->getDiffusionRequest()->getRepository()->getURI()); ->setURI($repository->getURI());
} }
} }

View file

@ -3,25 +3,16 @@
final class DiffusionRepositoryEditActionsController final class DiffusionRepositoryEditActionsController
extends DiffusionRepositoryEditController { extends DiffusionRepositoryEditController {
protected function processDiffusionRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$viewer = $request->getUser(); $response = $this->loadDiffusionContextForEdit();
$drequest = $this->diffusionRequest; if ($response) {
$repository = $drequest->getRepository(); return $response;
$repository = id(new PhabricatorRepositoryQuery())
->setViewer($viewer)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->withIDs(array($repository->getID()))
->executeOne();
if (!$repository) {
return new Aphront404Response();
} }
$viewer = $this->getViewer();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/');
// NOTE: We're inverting these here, because the storage is silly. // NOTE: We're inverting these here, because the storage is silly.
@ -109,14 +100,10 @@ final class DiffusionRepositoryEditActionsController
->setHeaderText($title) ->setHeaderText($title)
->setForm($form); ->setForm($form);
return $this->buildApplicationPage( return $this->newPage()
array( ->setTitle($title)
$crumbs, ->setCrumbs($crumbs)
$form_box, ->appendChild($form_box);
),
array(
'title' => $title,
));
} }
} }

View file

@ -3,25 +3,16 @@
final class DiffusionRepositoryEditActivateController final class DiffusionRepositoryEditActivateController
extends DiffusionRepositoryEditController { extends DiffusionRepositoryEditController {
protected function processDiffusionRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$viewer = $request->getUser(); $response = $this->loadDiffusionContextForEdit();
$drequest = $this->diffusionRequest; if ($response) {
$repository = $drequest->getRepository(); return $response;
$repository = id(new PhabricatorRepositoryQuery())
->setViewer($viewer)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->withIDs(array($repository->getID()))
->executeOne();
if (!$repository) {
return new Aphront404Response();
} }
$viewer = $this->getViewer();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/');
if ($request->isFormPost()) { if ($request->isFormPost()) {
@ -38,28 +29,21 @@ final class DiffusionRepositoryEditActivateController
return id(new AphrontReloadResponse())->setURI($edit_uri); return id(new AphrontReloadResponse())->setURI($edit_uri);
} }
$dialog = id(new AphrontDialogView())
->setUser($viewer);
if ($repository->isTracked()) { if ($repository->isTracked()) {
$dialog return $this->newDialog()
->setTitle(pht('Deactivate Repository?')) ->setTitle(pht('Deactivate Repository?'))
->appendChild( ->appendChild(
pht('Deactivate this repository?')) pht('Deactivate this repository?'))
->addSubmitButton(pht('Deactivate Repository')) ->addSubmitButton(pht('Deactivate Repository'))
->addCancelButton($edit_uri); ->addCancelButton($edit_uri);
} else { } else {
$dialog return $this->newDialog()
->setTitle(pht('Activate Repository?')) ->setTitle(pht('Activate Repository?'))
->appendChild( ->appendChild(
pht('Activate this repository?')) pht('Activate this repository?'))
->addSubmitButton(pht('Activate Repository')) ->addSubmitButton(pht('Activate Repository'))
->addCancelButton($edit_uri); ->addCancelButton($edit_uri);
} }
return id(new AphrontDialogResponse())
->setDialog($dialog);
} }
} }

View file

@ -3,24 +3,16 @@
final class DiffusionRepositoryEditAutomationController final class DiffusionRepositoryEditAutomationController
extends DiffusionRepositoryEditController { extends DiffusionRepositoryEditController {
protected function processDiffusionRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer(); $response = $this->loadDiffusionContextForEdit();
$drequest = $this->diffusionRequest; if ($response) {
$repository = $drequest->getRepository(); return $response;
$repository = id(new PhabricatorRepositoryQuery())
->setViewer($viewer)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->withIDs(array($repository->getID()))
->executeOne();
if (!$repository) {
return new Aphront404Response();
} }
$viewer = $this->getViewer();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
if (!$repository->supportsAutomation()) { if (!$repository->supportsAutomation()) {
return new Aphront404Response(); return new Aphront404Response();
} }
@ -81,14 +73,10 @@ final class DiffusionRepositoryEditAutomationController
->setHeaderText($title) ->setHeaderText($title)
->setForm($form); ->setForm($form);
return $this->buildApplicationPage( return $this->newPage()
array( ->setTitle($title)
$crumbs, ->setCrumbs($crumbs)
$object_box, ->appendChild($object_box);
),
array(
'title' => $title,
));
} }
} }

View file

@ -3,31 +3,24 @@
final class DiffusionRepositoryEditBasicController final class DiffusionRepositoryEditBasicController
extends DiffusionRepositoryEditController { extends DiffusionRepositoryEditController {
protected function processDiffusionRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$user = $request->getUser(); $response = $this->loadDiffusionContextForEdit();
$drequest = $this->diffusionRequest; if ($response) {
$repository = $drequest->getRepository(); return $response;
$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();
} }
$viewer = $request->getUser();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/');
$v_name = $repository->getName(); $v_name = $repository->getName();
$v_desc = $repository->getDetail('description'); $v_desc = $repository->getDetail('description');
$v_clone_name = $repository->getDetail('clone-name'); $v_clone_name = $repository->getDetail('clone-name');
$v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs(
$repository->getPHID(),
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST);
$e_name = true; $e_name = true;
$errors = array(); $errors = array();
@ -81,7 +74,7 @@ final class DiffusionRepositoryEditBasicController
id(new PhabricatorRepositoryEditor()) id(new PhabricatorRepositoryEditor())
->setContinueOnNoEffect(true) ->setContinueOnNoEffect(true)
->setContentSourceFromRequest($request) ->setContentSourceFromRequest($request)
->setActor($user) ->setActor($viewer)
->applyTransactions($repository, $xactions); ->applyTransactions($repository, $xactions);
return id(new AphrontRedirectResponse())->setURI($edit_uri); return id(new AphrontRedirectResponse())->setURI($edit_uri);
@ -94,7 +87,7 @@ final class DiffusionRepositoryEditBasicController
$title = pht('Edit %s', $repository->getName()); $title = pht('Edit %s', $repository->getName());
$form = id(new AphrontFormView()) $form = id(new AphrontFormView())
->setUser($user) ->setUser($viewer)
->appendChild( ->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())
->setName('name') ->setName('name')
@ -118,7 +111,7 @@ final class DiffusionRepositoryEditBasicController
$form $form
->appendChild( ->appendChild(
id(new PhabricatorRemarkupControl()) id(new PhabricatorRemarkupControl())
->setUser($user) ->setUser($viewer)
->setName('description') ->setName('description')
->setLabel(pht('Description')) ->setLabel(pht('Description'))
->setValue($v_desc)) ->setValue($v_desc))
@ -127,7 +120,7 @@ final class DiffusionRepositoryEditBasicController
->setDatasource(new PhabricatorProjectDatasource()) ->setDatasource(new PhabricatorProjectDatasource())
->setName('projectPHIDs') ->setName('projectPHIDs')
->setLabel(pht('Projects')) ->setLabel(pht('Projects'))
->setValue($repository->getProjectPHIDs())) ->setValue($v_projects))
->appendChild( ->appendChild(
id(new AphrontFormSubmitControl()) id(new AphrontFormSubmitControl())
->setValue(pht('Save')) ->setValue(pht('Save'))
@ -140,14 +133,10 @@ final class DiffusionRepositoryEditBasicController
->setForm($form) ->setForm($form)
->setFormErrors($errors); ->setFormErrors($errors);
return $this->buildApplicationPage( return $this->newPage()
array( ->setTitle($title)
$crumbs, ->setCrumbs($crumbs)
$object_box, ->appendChild($object_box);
),
array(
'title' => $title,
));
} }
private function getReadmeInstructions() { private function getReadmeInstructions() {

View file

@ -3,25 +3,16 @@
final class DiffusionRepositoryEditBranchesController final class DiffusionRepositoryEditBranchesController
extends DiffusionRepositoryEditController { extends DiffusionRepositoryEditController {
protected function processDiffusionRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$request = $this->getRequest(); $response = $this->loadDiffusionContextForEdit();
$viewer = $request->getUser(); if ($response) {
$drequest = $this->diffusionRequest; return $response;
$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();
} }
$viewer = $this->getViewer();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$is_git = false; $is_git = false;
$is_hg = false; $is_hg = false;
@ -226,14 +217,10 @@ final class DiffusionRepositoryEditBranchesController
->setHeaderText($title) ->setHeaderText($title)
->setForm($form); ->setForm($form);
return $this->buildApplicationPage( return $this->newPage()
array( ->setTitle($title)
$crumbs, ->setCrumbs($crumbs)
$form_box, ->appendChild($form_box);
),
array(
'title' => $title,
));
} }
private function processBranches($string) { private function processBranches($string) {

View file

@ -3,25 +3,16 @@
final class DiffusionRepositoryEditDangerousController final class DiffusionRepositoryEditDangerousController
extends DiffusionRepositoryEditController { extends DiffusionRepositoryEditController {
protected function processDiffusionRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$viewer = $request->getUser(); $response = $this->loadDiffusionContextForEdit();
$drequest = $this->diffusionRequest; if ($response) {
$repository = $drequest->getRepository(); return $response;
$repository = id(new PhabricatorRepositoryQuery())
->setViewer($viewer)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->withIDs(array($repository->getID()))
->executeOne();
if (!$repository) {
return new Aphront404Response();
} }
$viewer = $this->getViewer();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
if (!$repository->canAllowDangerousChanges()) { if (!$repository->canAllowDangerousChanges()) {
return new Aphront400Response(); return new Aphront400Response();
} }
@ -42,13 +33,10 @@ final class DiffusionRepositoryEditDangerousController
return id(new AphrontReloadResponse())->setURI($edit_uri); return id(new AphrontReloadResponse())->setURI($edit_uri);
} }
$dialog = id(new AphrontDialogView())
->setUser($viewer);
$force = phutil_tag('tt', array(), '--force'); $force = phutil_tag('tt', array(), '--force');
if ($repository->shouldAllowDangerousChanges()) { if ($repository->shouldAllowDangerousChanges()) {
$dialog return $this->newDialog()
->setTitle(pht('Prevent Dangerous changes?')) ->setTitle(pht('Prevent Dangerous changes?'))
->appendChild( ->appendChild(
pht( pht(
@ -58,7 +46,7 @@ final class DiffusionRepositoryEditDangerousController
->addSubmitButton(pht('Prevent Dangerous Changes')) ->addSubmitButton(pht('Prevent Dangerous Changes'))
->addCancelButton($edit_uri); ->addCancelButton($edit_uri);
} else { } else {
$dialog return $this->newDialog()
->setTitle(pht('Allow Dangerous Changes?')) ->setTitle(pht('Allow Dangerous Changes?'))
->appendChild( ->appendChild(
pht( pht(
@ -69,9 +57,6 @@ final class DiffusionRepositoryEditDangerousController
->addSubmitButton(pht('Allow Dangerous Changes')) ->addSubmitButton(pht('Allow Dangerous Changes'))
->addCancelButton($edit_uri); ->addCancelButton($edit_uri);
} }
return id(new AphrontDialogResponse())
->setDialog($dialog);
} }
} }

View file

@ -3,24 +3,16 @@
final class DiffusionRepositoryEditDeleteController final class DiffusionRepositoryEditDeleteController
extends DiffusionRepositoryEditController { extends DiffusionRepositoryEditController {
protected function processDiffusionRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$viewer = $request->getUser(); $response = $this->loadDiffusionContextForEdit();
$drequest = $this->diffusionRequest; if ($response) {
$repository = $drequest->getRepository(); return $response;
$repository = id(new PhabricatorRepositoryQuery())
->setViewer($viewer)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->withIDs(array($repository->getID()))
->executeOne();
if (!$repository) {
return new Aphront404Response();
} }
$viewer = $this->getViewer();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/');
$dialog = new AphrontDialogView(); $dialog = new AphrontDialogView();
@ -45,14 +37,10 @@ final class DiffusionRepositoryEditDeleteController
phutil_tag('p', array(), $text_2), phutil_tag('p', array(), $text_2),
)); ));
$dialog = id(new AphrontDialogView()) return $this->newDialog()
->setUser($request->getUser())
->setTitle(pht('Really want to delete the repository?')) ->setTitle(pht('Really want to delete the repository?'))
->appendChild($body) ->appendChild($body)
->addCancelButton($edit_uri, pht('Okay')); ->addCancelButton($edit_uri, pht('Okay'));
return id(new AphrontDialogResponse())->setDialog($dialog);
} }
} }

View file

@ -3,25 +3,16 @@
final class DiffusionRepositoryEditEncodingController final class DiffusionRepositoryEditEncodingController
extends DiffusionRepositoryEditController { extends DiffusionRepositoryEditController {
protected function processDiffusionRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$user = $request->getUser(); $response = $this->loadDiffusionContextForEdit();
$drequest = $this->diffusionRequest; if ($response) {
$repository = $drequest->getRepository(); return $response;
$repository = id(new PhabricatorRepositoryQuery())
->setViewer($user)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->withIDs(array($repository->getID()))
->executeOne();
if (!$repository) {
return new Aphront404Response();
} }
$user = $this->getViewer();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/');
$v_encoding = $repository->getDetail('encoding'); $v_encoding = $repository->getDetail('encoding');
@ -79,14 +70,10 @@ final class DiffusionRepositoryEditEncodingController
->setForm($form) ->setForm($form)
->setFormErrors($errors); ->setFormErrors($errors);
return $this->buildApplicationPage( return $this->newPage()
array( ->setTitle($title)
$crumbs, ->setCrumbs($crumbs)
$object_box, ->appendChild($object_box);
),
array(
'title' => $title,
));
} }
private function getEncodingInstructions() { private function getEncodingInstructions() {

View file

@ -5,25 +5,17 @@ final class DiffusionRepositoryEditHostingController
private $serve; private $serve;
protected function processDiffusionRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$user = $request->getUser(); $response = $this->loadDiffusionContextForEdit();
$drequest = $this->diffusionRequest; if ($response) {
$repository = $drequest->getRepository(); return $response;
$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();
} }
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$this->serve = $request->getURIData('serve');
if (!$this->serve) { if (!$this->serve) {
return $this->handleHosting($repository); return $this->handleHosting($repository);
} else { } else {
@ -107,14 +99,10 @@ final class DiffusionRepositoryEditHostingController
->setHeaderText($title) ->setHeaderText($title)
->setForm($form); ->setForm($form);
return $this->buildApplicationPage( return $this->newPage()
array( ->setTitle($title)
$crumbs, ->setCrumbs($crumbs)
$object_box, ->appendChild($object_box);
),
array(
'title' => $title,
));
} }
public function handleProtocols(PhabricatorRepository $repository) { public function handleProtocols(PhabricatorRepository $repository) {
@ -272,14 +260,10 @@ final class DiffusionRepositoryEditHostingController
->setHeaderText($title) ->setHeaderText($title)
->setForm($form); ->setForm($form);
return $this->buildApplicationPage( return $this->newPage()
array( ->setTitle($title)
$crumbs, ->setCrumbs($crumbs)
$object_box, ->appendChild($object_box);
),
array(
'title' => $title,
));
} }
} }

View file

@ -3,15 +3,15 @@
final class DiffusionRepositoryEditMainController final class DiffusionRepositoryEditMainController
extends DiffusionRepositoryEditController { extends DiffusionRepositoryEditController {
protected function processDiffusionRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$viewer = $request->getUser(); $response = $this->loadDiffusionContextForEdit();
$drequest = $this->diffusionRequest; if ($response) {
$repository = $drequest->getRepository(); return $response;
}
PhabricatorPolicyFilter::requireCapability( $viewer = $this->getViewer();
$viewer, $drequest = $this->getDiffusionRequest();
$repository, $repository = $drequest->getRepository();
PhabricatorPolicyCapability::CAN_EDIT);
$is_svn = false; $is_svn = false;
$is_git = false; $is_git = false;

View file

@ -3,23 +3,16 @@
final class DiffusionRepositoryEditStagingController final class DiffusionRepositoryEditStagingController
extends DiffusionRepositoryEditController { extends DiffusionRepositoryEditController {
protected function processDiffusionRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$user = $request->getUser(); $response = $this->loadDiffusionContextForEdit();
$drequest = $this->diffusionRequest; if ($response) {
return $response;
}
$viewer = $this->getViewer();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository(); $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()) { if (!$repository->supportsStaging()) {
return new Aphront404Response(); return new Aphront404Response();
@ -43,7 +36,7 @@ final class DiffusionRepositoryEditStagingController
id(new PhabricatorRepositoryEditor()) id(new PhabricatorRepositoryEditor())
->setContinueOnNoEffect(true) ->setContinueOnNoEffect(true)
->setContentSourceFromRequest($request) ->setContentSourceFromRequest($request)
->setActor($user) ->setActor($viewer)
->applyTransactions($repository, $xactions); ->applyTransactions($repository, $xactions);
return id(new AphrontRedirectResponse())->setURI($edit_uri); return id(new AphrontRedirectResponse())->setURI($edit_uri);
@ -55,7 +48,7 @@ final class DiffusionRepositoryEditStagingController
$title = pht('Edit %s', $repository->getName()); $title = pht('Edit %s', $repository->getName());
$form = id(new AphrontFormView()) $form = id(new AphrontFormView())
->setUser($user) ->setUser($viewer)
->appendRemarkupInstructions( ->appendRemarkupInstructions(
pht( pht(
"To make it easier to run integration tests and builds on code ". "To make it easier to run integration tests and builds on code ".
@ -79,14 +72,10 @@ final class DiffusionRepositoryEditStagingController
->setHeaderText($title) ->setHeaderText($title)
->setForm($form); ->setForm($form);
return $this->buildApplicationPage( return $this->newPage()
array( ->setTitle($title)
$crumbs, ->setCrumbs($crumbs)
$object_box, ->appendChild($object_box);
),
array(
'title' => $title,
));
} }
} }

View file

@ -3,25 +3,16 @@
final class DiffusionRepositoryEditStorageController final class DiffusionRepositoryEditStorageController
extends DiffusionRepositoryEditController { extends DiffusionRepositoryEditController {
protected function processDiffusionRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$user = $request->getUser(); $response = $this->loadDiffusionContextForEdit();
$drequest = $this->diffusionRequest; if ($response) {
$repository = $drequest->getRepository(); return $response;
$repository = id(new PhabricatorRepositoryQuery())
->setViewer($user)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->withIDs(array($repository->getID()))
->executeOne();
if (!$repository) {
return new Aphront404Response();
} }
$viewer = $this->getViewer();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/');
$v_local = $repository->getHumanReadableDetail('local-path'); $v_local = $repository->getHumanReadableDetail('local-path');
@ -44,7 +35,7 @@ final class DiffusionRepositoryEditStorageController
} }
$form = id(new AphrontFormView()) $form = id(new AphrontFormView())
->setUser($user) ->setUser($viewer)
->appendChild( ->appendChild(
id(new AphrontFormMarkupControl()) id(new AphrontFormMarkupControl())
->setLabel(pht('Storage Service')) ->setLabel(pht('Storage Service'))
@ -61,7 +52,7 @@ final class DiffusionRepositoryEditStorageController
sprintf( sprintf(
'phabricator/ $ ./bin/repository edit %s --as %s --local-path ...', 'phabricator/ $ ./bin/repository edit %s --as %s --local-path ...',
$repository->getMonogram(), $repository->getMonogram(),
$user->getUsername()))) $viewer->getUsername())))
->appendChild( ->appendChild(
id(new AphrontFormSubmitControl()) id(new AphrontFormSubmitControl())
->addCancelButton($edit_uri, pht('Done'))); ->addCancelButton($edit_uri, pht('Done')));
@ -71,14 +62,10 @@ final class DiffusionRepositoryEditStorageController
->setForm($form) ->setForm($form)
->setFormErrors($errors); ->setFormErrors($errors);
return $this->buildApplicationPage( return $this->newPage()
array( ->setTitle($title)
$crumbs, ->setCrumbs($crumbs)
$object_box, ->appendChild($object_box);
),
array(
'title' => $title,
));
} }
} }

View file

@ -3,25 +3,16 @@
final class DiffusionRepositoryEditSubversionController final class DiffusionRepositoryEditSubversionController
extends DiffusionRepositoryEditController { extends DiffusionRepositoryEditController {
protected function processDiffusionRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$viewer = $request->getUser(); $response = $this->loadDiffusionContextForEdit();
$drequest = $this->diffusionRequest; if ($response) {
$repository = $drequest->getRepository(); return $response;
$repository = id(new PhabricatorRepositoryQuery())
->setViewer($viewer)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->withIDs(array($repository->getID()))
->executeOne();
if (!$repository) {
return new Aphront404Response();
} }
$viewer = $this->getViewer();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
switch ($repository->getVersionControlSystem()) { switch ($repository->getVersionControlSystem()) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
@ -108,14 +99,10 @@ final class DiffusionRepositoryEditSubversionController
->setHeaderText($title) ->setHeaderText($title)
->setForm($form); ->setForm($form);
return $this->buildApplicationPage( return $this->newPage()
array( ->setTitle($title)
$crumbs, ->setCrumbs($crumbs)
$form_box, ->appendChild($form_box);
),
array(
'title' => $title,
));
} }
} }

View file

@ -3,24 +3,16 @@
final class DiffusionRepositoryEditUpdateController final class DiffusionRepositoryEditUpdateController
extends DiffusionRepositoryEditController { extends DiffusionRepositoryEditController {
protected function processDiffusionRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$viewer = $request->getUser(); $response = $this->loadDiffusionContextForEdit();
$drequest = $this->diffusionRequest; if ($response) {
$repository = $drequest->getRepository(); return $response;
$repository = id(new PhabricatorRepositoryQuery())
->setViewer($viewer)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->withIDs(array($repository->getID()))
->executeOne();
if (!$repository) {
return new Aphront404Response();
} }
$viewer = $this->getViewer();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/');
if ($request->isFormPost()) { if ($request->isFormPost()) {

View file

@ -3,25 +3,16 @@
final class DiffusionRepositorySymbolsController final class DiffusionRepositorySymbolsController
extends DiffusionRepositoryEditController { extends DiffusionRepositoryEditController {
protected function processDiffusionRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$user = $request->getUser(); $response = $this->loadDiffusionContextForEdit();
$drequest = $this->diffusionRequest; if ($response) {
$repository = $drequest->getRepository(); return $response;
$repository = id(new PhabricatorRepositoryQuery())
->setViewer($user)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->withIDs(array($repository->getID()))
->executeOne();
if (!$repository) {
return new Aphront404Response();
} }
$viewer = $this->getViewer();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/');
$v_sources = $repository->getSymbolSources(); $v_sources = $repository->getSymbolSources();
@ -55,7 +46,7 @@ final class DiffusionRepositorySymbolsController
id(new PhabricatorRepositoryEditor()) id(new PhabricatorRepositoryEditor())
->setContinueOnNoEffect(true) ->setContinueOnNoEffect(true)
->setContentSourceFromRequest($request) ->setContentSourceFromRequest($request)
->setActor($user) ->setActor($viewer)
->applyTransactions($repository, $xactions); ->applyTransactions($repository, $xactions);
return id(new AphrontRedirectResponse())->setURI($edit_uri); return id(new AphrontRedirectResponse())->setURI($edit_uri);
@ -71,7 +62,7 @@ final class DiffusionRepositorySymbolsController
$title = pht('Edit %s', $repository->getName()); $title = pht('Edit %s', $repository->getName());
$form = id(new AphrontFormView()) $form = id(new AphrontFormView())
->setUser($user) ->setUser($viewer)
->appendRemarkupInstructions($this->getInstructions()) ->appendRemarkupInstructions($this->getInstructions())
->appendChild( ->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())
@ -99,14 +90,10 @@ final class DiffusionRepositorySymbolsController
->setForm($form) ->setForm($form)
->setFormErrors($errors); ->setFormErrors($errors);
return $this->buildApplicationPage( return $this->newPage()
array( ->setTitle($title)
$crumbs, ->setCrumbs($crumbs)
$object_box, ->appendChild($object_box);
),
array(
'title' => $title,
));
} }
private function getInstructions() { private function getInstructions() {

View file

@ -4,7 +4,7 @@ final class DiffusionRepositoryTestAutomationController
extends DiffusionRepositoryEditController { extends DiffusionRepositoryEditController {
public function handleRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$response = $this->loadDiffusionContext(); $response = $this->loadDiffusionContextForEdit();
if ($response) { if ($response) {
return $response; return $response;
} }
@ -13,19 +13,6 @@ final class DiffusionRepositoryTestAutomationController
$drequest = $this->getDiffusionRequest(); $drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository(); $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/'); $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/');
if (!$repository->canPerformAutomation()) { if (!$repository->canPerformAutomation()) {

View file

@ -100,7 +100,10 @@ abstract class DiffusionRequest extends Phobject {
} }
if ($identifier !== null) { if ($identifier !== null) {
$object = self::newFromIdentifier($identifier, $data[$viewer_key]); $object = self::newFromIdentifier(
$identifier,
$data[$viewer_key],
idx($data, 'edit'));
} else { } else {
$object = self::newFromRepository($repository); $object = self::newFromRepository($repository);
} }
@ -171,12 +174,22 @@ abstract class DiffusionRequest extends Phobject {
*/ */
final private static function newFromIdentifier( final private static function newFromIdentifier(
$identifier, $identifier,
PhabricatorUser $viewer) { PhabricatorUser $viewer,
$need_edit = false) {
$repository = id(new PhabricatorRepositoryQuery()) $query = id(new PhabricatorRepositoryQuery())
->setViewer($viewer) ->setViewer($viewer)
->withIdentifiers(array($identifier)) ->withIdentifiers(array($identifier));
->executeOne();
if ($need_edit) {
$query->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
));
}
$repository = $query->executeOne();
if (!$repository) { if (!$repository) {
return null; return null;