Page MenuHomePhabricator

D14510.id35146.diff
No OneTemporary

D14510.id35146.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2670,6 +2670,7 @@
'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 @@
),
'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
--- a/src/applications/phurl/application/PhabricatorPhurlApplication.php
+++ b/src/applications/phurl/application/PhabricatorPhurlApplication.php
@@ -60,4 +60,12 @@
);
}
+ 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
--- /dev/null
+++ b/src/applications/phurl/capability/PhabricatorPhurlURLCreateCapability.php
@@ -0,0 +1,16 @@
+<?php
+
+final class PhabricatorPhurlURLCreateCapability
+ extends PhabricatorPolicyCapability {
+
+ const CAPABILITY = 'phurl.url.create';
+
+ public function getCapabilityName() {
+ return pht('Can Create Phurl URLs');
+ }
+
+ public function describeCapabilityRejection() {
+ return pht('You do not have permission to create a Phurl URL.');
+ }
+
+}
diff --git a/src/applications/phurl/controller/PhabricatorPhurlController.php b/src/applications/phurl/controller/PhabricatorPhurlController.php
--- a/src/applications/phurl/controller/PhabricatorPhurlController.php
+++ b/src/applications/phurl/controller/PhabricatorPhurlController.php
@@ -3,12 +3,17 @@
abstract class PhabricatorPhurlController extends PhabricatorController {
protected function buildApplicationCrumbs() {
+ $can_create = $this->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
--- a/src/applications/phurl/controller/PhabricatorPhurlURLEditController.php
+++ b/src/applications/phurl/controller/PhabricatorPhurlURLEditController.php
@@ -17,6 +17,9 @@
$uri_query = $request->getStr('query');
if ($is_create) {
+ $this->requireApplicationCapability(
+ PhabricatorPhurlURLCreateCapability::CAPABILITY);
+
$url = PhabricatorPhurlURL::initializeNewPhurlURL(
$viewer);
$submit_label = pht('Create');

File Metadata

Mime Type
text/plain
Expires
Fri, May 10, 4:37 AM (1 w, 3 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6281534
Default Alt Text
D14510.id35146.diff (4 KB)

Event Timeline