From 4d362ddcee4a76beb27c87ff2260e473cbc5182a Mon Sep 17 00:00:00 2001 From: lkassianik Date: Wed, 18 Nov 2015 12:24:09 -0800 Subject: [PATCH] Ref T6049, Add Phurl URL create capability Summary: Ref T6049, Add Phurl URL create capability Test Plan: - Change {nav Home > Applications > Phurl > Configure} to allow no one to create Phurl URLs - Attempt {nav Phurl > Shorten URL}. Should not be able to create a Phurl. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin Maniphest Tasks: T6049 Differential Revision: https://secure.phabricator.com/D14510 --- src/__phutil_library_map__.php | 2 ++ .../application/PhabricatorPhurlApplication.php | 8 ++++++++ .../PhabricatorPhurlURLCreateCapability.php | 16 ++++++++++++++++ .../controller/PhabricatorPhurlController.php | 7 ++++++- .../PhabricatorPhurlURLEditController.php | 3 +++ 5 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/applications/phurl/capability/PhabricatorPhurlURLCreateCapability.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index e28eec6f6a..73a0fd7393 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2670,6 +2670,7 @@ phutil_register_library_map(array( 'PhabricatorPhurlURL' => 'applications/phurl/storage/PhabricatorPhurlURL.php', 'PhabricatorPhurlURLAccessController' => 'applications/phurl/controller/PhabricatorPhurlURLAccessController.php', 'PhabricatorPhurlURLCommentController' => 'applications/phurl/controller/PhabricatorPhurlURLCommentController.php', + 'PhabricatorPhurlURLCreateCapability' => 'applications/phurl/capability/PhabricatorPhurlURLCreateCapability.php', 'PhabricatorPhurlURLEditController' => 'applications/phurl/controller/PhabricatorPhurlURLEditController.php', 'PhabricatorPhurlURLEditor' => 'applications/phurl/editor/PhabricatorPhurlURLEditor.php', 'PhabricatorPhurlURLListController' => 'applications/phurl/controller/PhabricatorPhurlURLListController.php', @@ -6848,6 +6849,7 @@ phutil_register_library_map(array( ), 'PhabricatorPhurlURLAccessController' => 'PhabricatorPhurlController', 'PhabricatorPhurlURLCommentController' => 'PhabricatorPhurlController', + 'PhabricatorPhurlURLCreateCapability' => 'PhabricatorPolicyCapability', 'PhabricatorPhurlURLEditController' => 'PhabricatorPhurlController', 'PhabricatorPhurlURLEditor' => 'PhabricatorApplicationTransactionEditor', 'PhabricatorPhurlURLListController' => 'PhabricatorPhurlController', diff --git a/src/applications/phurl/application/PhabricatorPhurlApplication.php b/src/applications/phurl/application/PhabricatorPhurlApplication.php index 75ac91c8c2..11b12067ea 100644 --- a/src/applications/phurl/application/PhabricatorPhurlApplication.php +++ b/src/applications/phurl/application/PhabricatorPhurlApplication.php @@ -60,4 +60,12 @@ final class PhabricatorPhurlApplication extends PhabricatorApplication { ); } + protected function getCustomCapabilities() { + return array( + PhabricatorPhurlURLCreateCapability::CAPABILITY => array( + 'default' => PhabricatorPolicies::POLICY_USER, + ), + ); + } + } diff --git a/src/applications/phurl/capability/PhabricatorPhurlURLCreateCapability.php b/src/applications/phurl/capability/PhabricatorPhurlURLCreateCapability.php new file mode 100644 index 0000000000..59590e6c6a --- /dev/null +++ b/src/applications/phurl/capability/PhabricatorPhurlURLCreateCapability.php @@ -0,0 +1,16 @@ +hasApplicationCapability( + PhabricatorPhurlURLCreateCapability::CAPABILITY); + $crumbs = parent::buildApplicationCrumbs(); $crumbs->addAction( id(new PHUIListItemView()) ->setName(pht('Shorten URL')) ->setHref($this->getApplicationURI().'url/create/') - ->setIcon('fa-plus-square')); + ->setIcon('fa-plus-square') + ->setDisabled(!$can_create) + ->setWorkflow(!$can_create)); return $crumbs; } diff --git a/src/applications/phurl/controller/PhabricatorPhurlURLEditController.php b/src/applications/phurl/controller/PhabricatorPhurlURLEditController.php index a4960d0c03..4136c855d8 100644 --- a/src/applications/phurl/controller/PhabricatorPhurlURLEditController.php +++ b/src/applications/phurl/controller/PhabricatorPhurlURLEditController.php @@ -17,6 +17,9 @@ final class PhabricatorPhurlURLEditController $uri_query = $request->getStr('query'); if ($is_create) { + $this->requireApplicationCapability( + PhabricatorPhurlURLCreateCapability::CAPABILITY); + $url = PhabricatorPhurlURL::initializeNewPhurlURL( $viewer); $submit_label = pht('Create');