Differential D14945 Diff 36121 src/applications/diffusion/controller/DiffusionRepositoryEditDangerousController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/controller/DiffusionRepositoryEditDangerousController.php
<?php | <?php | ||||
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(); | ||||
} | } | ||||
$edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); | $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); | ||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
$xaction = id(new PhabricatorRepositoryTransaction()) | $xaction = id(new PhabricatorRepositoryTransaction()) | ||||
->setTransactionType(PhabricatorRepositoryTransaction::TYPE_DANGEROUS) | ->setTransactionType(PhabricatorRepositoryTransaction::TYPE_DANGEROUS) | ||||
->setNewValue(!$repository->shouldAllowDangerousChanges()); | ->setNewValue(!$repository->shouldAllowDangerousChanges()); | ||||
$editor = id(new PhabricatorRepositoryEditor()) | $editor = id(new PhabricatorRepositoryEditor()) | ||||
->setContinueOnNoEffect(true) | ->setContinueOnNoEffect(true) | ||||
->setContentSourceFromRequest($request) | ->setContentSourceFromRequest($request) | ||||
->setActor($viewer) | ->setActor($viewer) | ||||
->applyTransactions($repository, array($xaction)); | ->applyTransactions($repository, array($xaction)); | ||||
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( | ||||
'It will no longer be possible to delete branches from this '. | 'It will no longer be possible to delete branches from this '. | ||||
'repository, or %s push to this repository.', | 'repository, or %s push to this repository.', | ||||
$force)) | $force)) | ||||
->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( | ||||
'If you allow dangerous changes, it will be possible to delete '. | 'If you allow dangerous changes, it will be possible to delete '. | ||||
'branches and %s push this repository. These operations can '. | 'branches and %s push this repository. These operations can '. | ||||
'alter a repository in a way that is difficult to recover from.', | 'alter a repository in a way that is difficult to recover from.', | ||||
$force)) | $force)) | ||||
->addSubmitButton(pht('Allow Dangerous Changes')) | ->addSubmitButton(pht('Allow Dangerous Changes')) | ||||
->addCancelButton($edit_uri); | ->addCancelButton($edit_uri); | ||||
} | } | ||||
return id(new AphrontDialogResponse()) | |||||
->setDialog($dialog); | |||||
} | } | ||||
} | } |