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

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
This commit is contained in:
epriestley 2016-04-29 16:51:05 -07:00
parent e8dca5a4f9
commit 0ba3939ce3
9 changed files with 138 additions and 7 deletions

View file

@ -789,6 +789,7 @@ phutil_register_library_map(array(
'DiffusionRepositorySymbolsManagementPanel' => 'applications/diffusion/management/DiffusionRepositorySymbolsManagementPanel.php', 'DiffusionRepositorySymbolsManagementPanel' => 'applications/diffusion/management/DiffusionRepositorySymbolsManagementPanel.php',
'DiffusionRepositoryTag' => 'applications/diffusion/data/DiffusionRepositoryTag.php', 'DiffusionRepositoryTag' => 'applications/diffusion/data/DiffusionRepositoryTag.php',
'DiffusionRepositoryTestAutomationController' => 'applications/diffusion/controller/DiffusionRepositoryTestAutomationController.php', 'DiffusionRepositoryTestAutomationController' => 'applications/diffusion/controller/DiffusionRepositoryTestAutomationController.php',
'DiffusionRepositoryURIDisableController' => 'applications/diffusion/controller/DiffusionRepositoryURIDisableController.php',
'DiffusionRepositoryURIEditController' => 'applications/diffusion/controller/DiffusionRepositoryURIEditController.php', 'DiffusionRepositoryURIEditController' => 'applications/diffusion/controller/DiffusionRepositoryURIEditController.php',
'DiffusionRepositoryURIViewController' => 'applications/diffusion/controller/DiffusionRepositoryURIViewController.php', 'DiffusionRepositoryURIViewController' => 'applications/diffusion/controller/DiffusionRepositoryURIViewController.php',
'DiffusionRepositoryURIsIndexEngineExtension' => 'applications/diffusion/engineextension/DiffusionRepositoryURIsIndexEngineExtension.php', 'DiffusionRepositoryURIsIndexEngineExtension' => 'applications/diffusion/engineextension/DiffusionRepositoryURIsIndexEngineExtension.php',
@ -5019,7 +5020,8 @@ phutil_register_library_map(array(
'DiffusionRepositorySymbolsManagementPanel' => 'DiffusionRepositoryManagementPanel', 'DiffusionRepositorySymbolsManagementPanel' => 'DiffusionRepositoryManagementPanel',
'DiffusionRepositoryTag' => 'Phobject', 'DiffusionRepositoryTag' => 'Phobject',
'DiffusionRepositoryTestAutomationController' => 'DiffusionRepositoryEditController', 'DiffusionRepositoryTestAutomationController' => 'DiffusionRepositoryEditController',
'DiffusionRepositoryURIEditController' => 'DiffusionRepositoryEditController', 'DiffusionRepositoryURIDisableController' => 'DiffusionController',
'DiffusionRepositoryURIEditController' => 'DiffusionController',
'DiffusionRepositoryURIViewController' => 'DiffusionController', 'DiffusionRepositoryURIViewController' => 'DiffusionController',
'DiffusionRepositoryURIsIndexEngineExtension' => 'PhabricatorIndexEngineExtension', 'DiffusionRepositoryURIsIndexEngineExtension' => 'PhabricatorIndexEngineExtension',
'DiffusionRepositoryURIsManagementPanel' => 'DiffusionRepositoryManagementPanel', 'DiffusionRepositoryURIsManagementPanel' => 'DiffusionRepositoryManagementPanel',

View file

@ -93,6 +93,8 @@ final class PhabricatorDiffusionApplication extends PhabricatorApplication {
=> 'DiffusionRepositoryManageController', => 'DiffusionRepositoryManageController',
'uri/' => array( 'uri/' => array(
'view/(?P<id>[0-9]\d*)/' => 'DiffusionRepositoryURIViewController', 'view/(?P<id>[0-9]\d*)/' => 'DiffusionRepositoryURIViewController',
'disable/(?P<id>[0-9]\d*)/'
=> 'DiffusionRepositoryURIDisableController',
$this->getEditRoutePattern('edit/') $this->getEditRoutePattern('edit/')
=> 'DiffusionRepositoryURIEditController', => 'DiffusionRepositoryURIEditController',
), ),

View file

@ -0,0 +1,72 @@
<?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);
}
}

View file

@ -1,7 +1,7 @@
<?php <?php
final class DiffusionRepositoryURIEditController final class DiffusionRepositoryURIEditController
extends DiffusionRepositoryEditController { extends DiffusionController {
public function handleRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$response = $this->loadDiffusionContextForEdit(); $response = $this->loadDiffusionContextForEdit();

View file

@ -82,16 +82,18 @@ final class DiffusionRepositoryURIViewController
private function buildCurtain(PhabricatorRepositoryURI $uri) { private function buildCurtain(PhabricatorRepositoryURI $uri) {
$viewer = $this->getViewer(); $viewer = $this->getViewer();
$id = $uri->getID();
$can_edit = PhabricatorPolicyFilter::hasCapability( $can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer, $viewer,
$uri, $uri,
PhabricatorPolicyCapability::CAN_EDIT); PhabricatorPolicyCapability::CAN_EDIT);
$edit_uri = $uri->getEditURI();
$curtain = $this->newCurtainView($uri); $curtain = $this->newCurtainView($uri);
$edit_uri = $uri->getEditURI();
$curtain->addAction( $curtain->addAction(
id(new PhabricatorActionView()) id(new PhabricatorActionView())
->setIcon('fa-pencil') ->setIcon('fa-pencil')
@ -100,6 +102,24 @@ final class DiffusionRepositoryURIViewController
->setWorkflow(!$can_edit) ->setWorkflow(!$can_edit)
->setDisabled(!$can_edit)); ->setDisabled(!$can_edit));
if ($uri->getIsDisabled()) {
$disable_name = pht('Enable URI');
$disable_icon = 'fa-check';
} else {
$disable_name = pht('Disable URI');
$disable_icon = 'fa-ban';
}
$disable_uri = $uri->getRepository()->getPathURI("uri/disable/{$id}/");
$curtain->addAction(
id(new PhabricatorActionView())
->setIcon($disable_icon)
->setName($disable_name)
->setHref($disable_uri)
->setWorkflow(true)
->setDisabled(!$can_edit));
return $curtain; return $curtain;
} }

View file

@ -217,6 +217,25 @@ final class DiffusionURIEditor
$errors[] = $error; $errors[] = $error;
break; break;
} }
foreach ($xactions as $xaction) {
$new_uri = $xaction->getNewValue();
if ($new_uri == $object->getURI()) {
continue;
}
try {
PhabricatorRepository::assertValidRemoteURI($new_uri);
} catch (Exception $ex) {
$errors[] = new PhabricatorApplicationTransactionValidationError(
$type,
pht('Invalid'),
$ex->getMessage(),
$xaction);
continue;
}
}
break; break;
case PhabricatorRepositoryURITransaction::TYPE_IO: case PhabricatorRepositoryURITransaction::TYPE_IO:
$available = $object->getAvailableIOTypeOptions(); $available = $object->getAvailableIOTypeOptions();

View file

@ -91,11 +91,17 @@ final class DiffusionRepositoryURIsManagementPanel
null, null,
)); ));
$doc_href = PhabricatorEnv::getDoclink( $doc_href = PhabricatorEnv::getDoclink('Diffusion User Guide: URIs');
'Diffusion User Guide: URIs'); $add_href = $repository->getPathURI('uri/edit/');
$header = id(new PHUIHeaderView()) $header = id(new PHUIHeaderView())
->setHeader(pht('Repository URIs')) ->setHeader(pht('Repository URIs'))
->addActionLink(
id(new PHUIButtonView())
->setIcon('fa-plus')
->setHref($add_href)
->setTag('a')
->setText(pht('Add New URI')))
->addActionLink( ->addActionLink(
id(new PHUIButtonView()) id(new PHUIButtonView())
->setIcon('fa-book') ->setIcon('fa-book')

View file

@ -1829,8 +1829,8 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
throw new Exception( throw new Exception(
pht( pht(
"The URI protocol is unrecognized. It should begin ". 'The URI protocol is unrecognized. It should begin with '.
"'%s', '%s', '%s', '%s', '%s', '%s', or be in the form '%s'.", '"%s", "%s", "%s", "%s", "%s", "%s", or be in the form "%s".',
'ssh://', 'ssh://',
'http://', 'http://',
'https://', 'https://',

View file

@ -51,6 +51,16 @@ final class PhabricatorRepositoryURITransaction
$this->renderHandleLink($author_phid), $this->renderHandleLink($author_phid),
$old_label, $old_label,
$new_label); $new_label);
case self::TYPE_DISABLE:
if ($new) {
return pht(
'%s disabled this URI.',
$this->renderHandleLink($author_phid));
} else {
return pht(
'%s enabled this URI.',
$this->renderHandleLink($author_phid));
}
} }