1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-03 12:12:43 +01:00
phorge-phorge/src/applications/diffusion/controller/DiffusionRepositoryURIDisableController.php
epriestley 0ba3939ce3 Flesh out more web UI actions for new URI interface
Summary:
Ref T10748.

  - Allow users to add new URIs by clicking a button instead of knowing a secret URI.
  - Validate that URIs are actually valid URIs.
  - Add enable/disable action and strings.

Test Plan:
  - Created a new URI.
  - Tried to create a nonsense URI, created a good URI.
  - Enabled/disabled a URI.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10748

Differential Revision: https://secure.phabricator.com/D15825
2016-04-29 17:16:15 -07:00

72 lines
2 KiB
PHP

<?php
final class DiffusionRepositoryURIDisableController
extends DiffusionController {
public function handleRequest(AphrontRequest $request) {
$response = $this->loadDiffusionContextForEdit();
if ($response) {
return $response;
}
$viewer = $this->getViewer();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$id = $request->getURIData('id');
$uri = id(new PhabricatorRepositoryURIQuery())
->setViewer($viewer)
->withIDs(array($id))
->withRepositories(array($repository))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$uri) {
return new Aphront404Response();
}
$is_disabled = $uri->getIsDisabled();
$view_uri = $uri->getViewURI();
if ($request->isFormPost()) {
$xactions = array();
$xactions[] = id(new PhabricatorRepositoryURITransaction())
->setTransactionType(PhabricatorRepositoryURITransaction::TYPE_DISABLE)
->setNewValue(!$is_disabled);
$editor = id(new DiffusionURIEditor())
->setActor($viewer)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true)
->setContentSourceFromRequest($request)
->applyTransactions($uri, $xactions);
return id(new AphrontRedirectResponse())->setURI($view_uri);
}
if ($is_disabled) {
$title = pht('Enable URI');
$body = pht(
'Enable this URI? Any configured behaviors will begin working '.
'again.');
$button = pht('Enable URI');
} else {
$title = pht('Disable URI');
$body = pht(
'Disable this URI? It will no longer be observed, fetched, mirrored, '.
'served or shown to users.');
$button = pht('Disable URI');
}
return $this->newDialog()
->setTitle($title)
->appendParagraph($body)
->addCancelButton($view_uri)
->addSubmitButton($button);
}
}