From 0ba3939ce344fe55ab1cb9226bfd1b7dbc91d278 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 29 Apr 2016 16:51:05 -0700 Subject: [PATCH] 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 --- src/__phutil_library_map__.php | 4 +- .../PhabricatorDiffusionApplication.php | 2 + ...iffusionRepositoryURIDisableController.php | 72 +++++++++++++++++++ .../DiffusionRepositoryURIEditController.php | 2 +- .../DiffusionRepositoryURIViewController.php | 22 +++++- .../diffusion/editor/DiffusionURIEditor.php | 19 +++++ ...DiffusionRepositoryURIsManagementPanel.php | 10 ++- .../storage/PhabricatorRepository.php | 4 +- .../PhabricatorRepositoryURITransaction.php | 10 +++ 9 files changed, 138 insertions(+), 7 deletions(-) create mode 100644 src/applications/diffusion/controller/DiffusionRepositoryURIDisableController.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 996d873ca9..b0ffd4eef5 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -789,6 +789,7 @@ phutil_register_library_map(array( 'DiffusionRepositorySymbolsManagementPanel' => 'applications/diffusion/management/DiffusionRepositorySymbolsManagementPanel.php', 'DiffusionRepositoryTag' => 'applications/diffusion/data/DiffusionRepositoryTag.php', 'DiffusionRepositoryTestAutomationController' => 'applications/diffusion/controller/DiffusionRepositoryTestAutomationController.php', + 'DiffusionRepositoryURIDisableController' => 'applications/diffusion/controller/DiffusionRepositoryURIDisableController.php', 'DiffusionRepositoryURIEditController' => 'applications/diffusion/controller/DiffusionRepositoryURIEditController.php', 'DiffusionRepositoryURIViewController' => 'applications/diffusion/controller/DiffusionRepositoryURIViewController.php', 'DiffusionRepositoryURIsIndexEngineExtension' => 'applications/diffusion/engineextension/DiffusionRepositoryURIsIndexEngineExtension.php', @@ -5019,7 +5020,8 @@ phutil_register_library_map(array( 'DiffusionRepositorySymbolsManagementPanel' => 'DiffusionRepositoryManagementPanel', 'DiffusionRepositoryTag' => 'Phobject', 'DiffusionRepositoryTestAutomationController' => 'DiffusionRepositoryEditController', - 'DiffusionRepositoryURIEditController' => 'DiffusionRepositoryEditController', + 'DiffusionRepositoryURIDisableController' => 'DiffusionController', + 'DiffusionRepositoryURIEditController' => 'DiffusionController', 'DiffusionRepositoryURIViewController' => 'DiffusionController', 'DiffusionRepositoryURIsIndexEngineExtension' => 'PhabricatorIndexEngineExtension', 'DiffusionRepositoryURIsManagementPanel' => 'DiffusionRepositoryManagementPanel', diff --git a/src/applications/diffusion/application/PhabricatorDiffusionApplication.php b/src/applications/diffusion/application/PhabricatorDiffusionApplication.php index f910c090b7..ec27124d05 100644 --- a/src/applications/diffusion/application/PhabricatorDiffusionApplication.php +++ b/src/applications/diffusion/application/PhabricatorDiffusionApplication.php @@ -93,6 +93,8 @@ final class PhabricatorDiffusionApplication extends PhabricatorApplication { => 'DiffusionRepositoryManageController', 'uri/' => array( 'view/(?P[0-9]\d*)/' => 'DiffusionRepositoryURIViewController', + 'disable/(?P[0-9]\d*)/' + => 'DiffusionRepositoryURIDisableController', $this->getEditRoutePattern('edit/') => 'DiffusionRepositoryURIEditController', ), diff --git a/src/applications/diffusion/controller/DiffusionRepositoryURIDisableController.php b/src/applications/diffusion/controller/DiffusionRepositoryURIDisableController.php new file mode 100644 index 0000000000..b846b3f4e2 --- /dev/null +++ b/src/applications/diffusion/controller/DiffusionRepositoryURIDisableController.php @@ -0,0 +1,72 @@ +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); + } + +} diff --git a/src/applications/diffusion/controller/DiffusionRepositoryURIEditController.php b/src/applications/diffusion/controller/DiffusionRepositoryURIEditController.php index f52edd1f35..4a1dc56d4a 100644 --- a/src/applications/diffusion/controller/DiffusionRepositoryURIEditController.php +++ b/src/applications/diffusion/controller/DiffusionRepositoryURIEditController.php @@ -1,7 +1,7 @@ loadDiffusionContextForEdit(); diff --git a/src/applications/diffusion/controller/DiffusionRepositoryURIViewController.php b/src/applications/diffusion/controller/DiffusionRepositoryURIViewController.php index b7da37ebe2..8cd143c5a1 100644 --- a/src/applications/diffusion/controller/DiffusionRepositoryURIViewController.php +++ b/src/applications/diffusion/controller/DiffusionRepositoryURIViewController.php @@ -82,16 +82,18 @@ final class DiffusionRepositoryURIViewController private function buildCurtain(PhabricatorRepositoryURI $uri) { $viewer = $this->getViewer(); + $id = $uri->getID(); $can_edit = PhabricatorPolicyFilter::hasCapability( $viewer, $uri, PhabricatorPolicyCapability::CAN_EDIT); - $edit_uri = $uri->getEditURI(); $curtain = $this->newCurtainView($uri); + $edit_uri = $uri->getEditURI(); + $curtain->addAction( id(new PhabricatorActionView()) ->setIcon('fa-pencil') @@ -100,6 +102,24 @@ final class DiffusionRepositoryURIViewController ->setWorkflow(!$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; } diff --git a/src/applications/diffusion/editor/DiffusionURIEditor.php b/src/applications/diffusion/editor/DiffusionURIEditor.php index d124ff4b4c..3d2164ad0b 100644 --- a/src/applications/diffusion/editor/DiffusionURIEditor.php +++ b/src/applications/diffusion/editor/DiffusionURIEditor.php @@ -217,6 +217,25 @@ final class DiffusionURIEditor $errors[] = $error; 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; case PhabricatorRepositoryURITransaction::TYPE_IO: $available = $object->getAvailableIOTypeOptions(); diff --git a/src/applications/diffusion/management/DiffusionRepositoryURIsManagementPanel.php b/src/applications/diffusion/management/DiffusionRepositoryURIsManagementPanel.php index 113914b8d4..634535fef4 100644 --- a/src/applications/diffusion/management/DiffusionRepositoryURIsManagementPanel.php +++ b/src/applications/diffusion/management/DiffusionRepositoryURIsManagementPanel.php @@ -91,11 +91,17 @@ final class DiffusionRepositoryURIsManagementPanel null, )); - $doc_href = PhabricatorEnv::getDoclink( - 'Diffusion User Guide: URIs'); + $doc_href = PhabricatorEnv::getDoclink('Diffusion User Guide: URIs'); + $add_href = $repository->getPathURI('uri/edit/'); $header = id(new PHUIHeaderView()) ->setHeader(pht('Repository URIs')) + ->addActionLink( + id(new PHUIButtonView()) + ->setIcon('fa-plus') + ->setHref($add_href) + ->setTag('a') + ->setText(pht('Add New URI'))) ->addActionLink( id(new PHUIButtonView()) ->setIcon('fa-book') diff --git a/src/applications/repository/storage/PhabricatorRepository.php b/src/applications/repository/storage/PhabricatorRepository.php index 11614b3649..be77852be8 100644 --- a/src/applications/repository/storage/PhabricatorRepository.php +++ b/src/applications/repository/storage/PhabricatorRepository.php @@ -1829,8 +1829,8 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO throw new Exception( pht( - "The URI protocol is unrecognized. It should begin ". - "'%s', '%s', '%s', '%s', '%s', '%s', or be in the form '%s'.", + 'The URI protocol is unrecognized. It should begin with '. + '"%s", "%s", "%s", "%s", "%s", "%s", or be in the form "%s".', 'ssh://', 'http://', 'https://', diff --git a/src/applications/repository/storage/PhabricatorRepositoryURITransaction.php b/src/applications/repository/storage/PhabricatorRepositoryURITransaction.php index f3aee8dce0..034aa48d7c 100644 --- a/src/applications/repository/storage/PhabricatorRepositoryURITransaction.php +++ b/src/applications/repository/storage/PhabricatorRepositoryURITransaction.php @@ -51,6 +51,16 @@ final class PhabricatorRepositoryURITransaction $this->renderHandleLink($author_phid), $old_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)); + } }