2013-12-03 19:28:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DiffusionRepositoryEditDangerousController
|
2016-05-09 23:24:21 +02:00
|
|
|
extends DiffusionRepositoryManageController {
|
2013-12-03 19:28:39 +01:00
|
|
|
|
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();
|
|
|
|
|
2016-05-09 16:01:37 +02:00
|
|
|
$panel_uri = id(new DiffusionRepositoryBasicsManagementPanel())
|
|
|
|
->setRepository($repository)
|
|
|
|
->getPanelURI();
|
2016-05-02 14:35:05 +02:00
|
|
|
|
2013-12-03 19:28:39 +01:00
|
|
|
if (!$repository->canAllowDangerousChanges()) {
|
2016-06-24 17:48:06 +02:00
|
|
|
return $this->newDialog()
|
|
|
|
->setTitle(pht('Unprotectable Repository'))
|
|
|
|
->appendParagraph(
|
|
|
|
pht(
|
|
|
|
'This repository can not be protected from dangerous changes '.
|
|
|
|
'because Phabricator does not control what users are allowed '.
|
|
|
|
'to push to it.'))
|
|
|
|
->addCancelButton($panel_uri);
|
2013-12-03 19:28:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
2016-05-09 16:01:37 +02:00
|
|
|
return id(new AphrontReloadResponse())->setURI($panel_uri);
|
2013-12-03 19:28:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$force = phutil_tag('tt', array(), '--force');
|
|
|
|
|
|
|
|
if ($repository->shouldAllowDangerousChanges()) {
|
2016-05-09 16:01:37 +02:00
|
|
|
$title = pht('Prevent Dangerous Changes');
|
2016-06-24 17:48:06 +02:00
|
|
|
|
|
|
|
if ($repository->isSVN()) {
|
|
|
|
$body = pht(
|
|
|
|
'It will no longer be possible to edit revprops in this '.
|
|
|
|
'repository.');
|
|
|
|
} else {
|
|
|
|
$body = pht(
|
|
|
|
'It will no longer be possible to delete branches from this '.
|
|
|
|
'repository, or %s push to this repository.',
|
|
|
|
$force);
|
|
|
|
}
|
|
|
|
|
2016-05-09 16:01:37 +02:00
|
|
|
$submit = pht('Prevent Dangerous Changes');
|
2013-12-03 19:28:39 +01:00
|
|
|
} else {
|
2016-05-09 16:01:37 +02:00
|
|
|
$title = pht('Allow Dangerous Changes');
|
2016-06-24 17:48:06 +02:00
|
|
|
if ($repository->isSVN()) {
|
|
|
|
$body = pht(
|
|
|
|
'If you allow dangerous changes, it will be possible to edit '.
|
|
|
|
'reprops in this repository, including arbitrarily rewriting '.
|
|
|
|
'commit messages. These operations can alter a repository in a '.
|
|
|
|
'way that is difficult to recover from.');
|
|
|
|
} else {
|
|
|
|
$body = 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);
|
|
|
|
}
|
2016-05-09 16:01:37 +02:00
|
|
|
$submit = pht('Allow Dangerous Changes');
|
2013-12-03 19:28:39 +01:00
|
|
|
}
|
2016-05-09 16:01:37 +02:00
|
|
|
|
|
|
|
return $this->newDialog()
|
|
|
|
->setTitle($title)
|
|
|
|
->appendParagraph($body)
|
|
|
|
->addSubmitButton($submit)
|
|
|
|
->addCancelButton($panel_uri);
|
2013-12-03 19:28:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|