2013-12-03 19:28:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DiffusionRepositoryEditDangerousController
|
|
|
|
extends DiffusionRepositoryEditController {
|
|
|
|
|
2016-01-05 17:49:10 +01:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$response = $this->loadDiffusionContextForEdit();
|
|
|
|
if ($response) {
|
|
|
|
return $response;
|
2013-12-03 19:28:39 +01:00
|
|
|
}
|
|
|
|
|
2016-01-05 17:49:10 +01:00
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$drequest = $this->getDiffusionRequest();
|
|
|
|
$repository = $drequest->getRepository();
|
|
|
|
|
2013-12-03 19:28:39 +01:00
|
|
|
if (!$repository->canAllowDangerousChanges()) {
|
|
|
|
return new Aphront400Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$edit_uri = $this->getRepositoryControllerURI($repository, 'edit/');
|
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$xaction = id(new PhabricatorRepositoryTransaction())
|
|
|
|
->setTransactionType(PhabricatorRepositoryTransaction::TYPE_DANGEROUS)
|
|
|
|
->setNewValue(!$repository->shouldAllowDangerousChanges());
|
|
|
|
|
|
|
|
$editor = id(new PhabricatorRepositoryEditor())
|
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->setContentSourceFromRequest($request)
|
|
|
|
->setActor($viewer)
|
|
|
|
->applyTransactions($repository, array($xaction));
|
|
|
|
|
|
|
|
return id(new AphrontReloadResponse())->setURI($edit_uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
$force = phutil_tag('tt', array(), '--force');
|
|
|
|
|
|
|
|
if ($repository->shouldAllowDangerousChanges()) {
|
2016-01-05 17:49:10 +01:00
|
|
|
return $this->newDialog()
|
2013-12-03 19:28:39 +01:00
|
|
|
->setTitle(pht('Prevent Dangerous changes?'))
|
|
|
|
->appendChild(
|
|
|
|
pht(
|
|
|
|
'It will no longer be possible to delete branches from this '.
|
|
|
|
'repository, or %s push to this repository.',
|
|
|
|
$force))
|
|
|
|
->addSubmitButton(pht('Prevent Dangerous Changes'))
|
|
|
|
->addCancelButton($edit_uri);
|
|
|
|
} else {
|
2016-01-05 17:49:10 +01:00
|
|
|
return $this->newDialog()
|
2013-12-03 19:28:39 +01:00
|
|
|
->setTitle(pht('Allow Dangerous Changes?'))
|
|
|
|
->appendChild(
|
|
|
|
pht(
|
|
|
|
'If you allow dangerous changes, it will be possible to delete '.
|
|
|
|
'branches and %s push this repository. These operations can '.
|
|
|
|
'alter a repository in a way that is difficult to recover from.',
|
|
|
|
$force))
|
|
|
|
->addSubmitButton(pht('Allow Dangerous Changes'))
|
|
|
|
->addCancelButton($edit_uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|