@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator

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

+35 -1
+2
src/__phutil_library_map__.php
··· 2670 2670 'PhabricatorPhurlURL' => 'applications/phurl/storage/PhabricatorPhurlURL.php', 2671 2671 'PhabricatorPhurlURLAccessController' => 'applications/phurl/controller/PhabricatorPhurlURLAccessController.php', 2672 2672 'PhabricatorPhurlURLCommentController' => 'applications/phurl/controller/PhabricatorPhurlURLCommentController.php', 2673 + 'PhabricatorPhurlURLCreateCapability' => 'applications/phurl/capability/PhabricatorPhurlURLCreateCapability.php', 2673 2674 'PhabricatorPhurlURLEditController' => 'applications/phurl/controller/PhabricatorPhurlURLEditController.php', 2674 2675 'PhabricatorPhurlURLEditor' => 'applications/phurl/editor/PhabricatorPhurlURLEditor.php', 2675 2676 'PhabricatorPhurlURLListController' => 'applications/phurl/controller/PhabricatorPhurlURLListController.php', ··· 6848 6849 ), 6849 6850 'PhabricatorPhurlURLAccessController' => 'PhabricatorPhurlController', 6850 6851 'PhabricatorPhurlURLCommentController' => 'PhabricatorPhurlController', 6852 + 'PhabricatorPhurlURLCreateCapability' => 'PhabricatorPolicyCapability', 6851 6853 'PhabricatorPhurlURLEditController' => 'PhabricatorPhurlController', 6852 6854 'PhabricatorPhurlURLEditor' => 'PhabricatorApplicationTransactionEditor', 6853 6855 'PhabricatorPhurlURLListController' => 'PhabricatorPhurlController',
+8
src/applications/phurl/application/PhabricatorPhurlApplication.php
··· 60 60 ); 61 61 } 62 62 63 + protected function getCustomCapabilities() { 64 + return array( 65 + PhabricatorPhurlURLCreateCapability::CAPABILITY => array( 66 + 'default' => PhabricatorPolicies::POLICY_USER, 67 + ), 68 + ); 69 + } 70 + 63 71 }
+16
src/applications/phurl/capability/PhabricatorPhurlURLCreateCapability.php
··· 1 + <?php 2 + 3 + final class PhabricatorPhurlURLCreateCapability 4 + extends PhabricatorPolicyCapability { 5 + 6 + const CAPABILITY = 'phurl.url.create'; 7 + 8 + public function getCapabilityName() { 9 + return pht('Can Create Phurl URLs'); 10 + } 11 + 12 + public function describeCapabilityRejection() { 13 + return pht('You do not have permission to create a Phurl URL.'); 14 + } 15 + 16 + }
+6 -1
src/applications/phurl/controller/PhabricatorPhurlController.php
··· 3 3 abstract class PhabricatorPhurlController extends PhabricatorController { 4 4 5 5 protected function buildApplicationCrumbs() { 6 + $can_create = $this->hasApplicationCapability( 7 + PhabricatorPhurlURLCreateCapability::CAPABILITY); 8 + 6 9 $crumbs = parent::buildApplicationCrumbs(); 7 10 $crumbs->addAction( 8 11 id(new PHUIListItemView()) 9 12 ->setName(pht('Shorten URL')) 10 13 ->setHref($this->getApplicationURI().'url/create/') 11 - ->setIcon('fa-plus-square')); 14 + ->setIcon('fa-plus-square') 15 + ->setDisabled(!$can_create) 16 + ->setWorkflow(!$can_create)); 12 17 13 18 return $crumbs; 14 19 }
+3
src/applications/phurl/controller/PhabricatorPhurlURLEditController.php
··· 17 17 $uri_query = $request->getStr('query'); 18 18 19 19 if ($is_create) { 20 + $this->requireApplicationCapability( 21 + PhabricatorPhurlURLCreateCapability::CAPABILITY); 22 + 20 23 $url = PhabricatorPhurlURL::initializeNewPhurlURL( 21 24 $viewer); 22 25 $submit_label = pht('Create');