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');