@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Simplify the implementation of `PhabricatorPolicyCapability` subclasses

Summary: Instead of implementing the `getCapabilityKey` method in all subclasses of `PhabricatorPolicyCapability`, provide a `final` implementation in the base class which uses reflection. See D9837 and D9985 for similar implementations.

Test Plan: N/A

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin, hach-que

Differential Revision: https://secure.phabricator.com/D10039

+24 -150
-4
src/applications/countdown/capability/PhabricatorCountdownDefaultViewCapability.php
··· 5 5 6 6 const CAPABILITY = 'countdown.default.view'; 7 7 8 - public function getCapabilityKey() { 9 - return self::CAPABILITY; 10 - } 11 - 12 8 public function getCapabilityName() { 13 9 return pht('Default View Policy'); 14 10 }
-4
src/applications/differential/capability/DifferentialDefaultViewCapability.php
··· 5 5 6 6 const CAPABILITY = 'differential.default.view'; 7 7 8 - public function getCapabilityKey() { 9 - return self::CAPABILITY; 10 - } 11 - 12 8 public function getCapabilityName() { 13 9 return pht('Default View Policy'); 14 10 }
-4
src/applications/diffusion/capability/DiffusionCreateRepositoriesCapability.php
··· 5 5 6 6 const CAPABILITY = 'diffusion.create'; 7 7 8 - public function getCapabilityKey() { 9 - return self::CAPABILITY; 10 - } 11 - 12 8 public function getCapabilityName() { 13 9 return pht('Can Create Repositories'); 14 10 }
-4
src/applications/diffusion/capability/DiffusionDefaultEditCapability.php
··· 4 4 5 5 const CAPABILITY = 'diffusion.default.edit'; 6 6 7 - public function getCapabilityKey() { 8 - return self::CAPABILITY; 9 - } 10 - 11 7 public function getCapabilityName() { 12 8 return pht('Default Edit Policy'); 13 9 }
-4
src/applications/diffusion/capability/DiffusionDefaultPushCapability.php
··· 4 4 5 5 const CAPABILITY = 'diffusion.default.push'; 6 6 7 - public function getCapabilityKey() { 8 - return self::CAPABILITY; 9 - } 10 - 11 7 public function getCapabilityName() { 12 8 return pht('Default Push Policy'); 13 9 }
-4
src/applications/diffusion/capability/DiffusionDefaultViewCapability.php
··· 4 4 5 5 const CAPABILITY = 'diffusion.default.view'; 6 6 7 - public function getCapabilityKey() { 8 - return self::CAPABILITY; 9 - } 10 - 11 7 public function getCapabilityName() { 12 8 return pht('Default View Policy'); 13 9 }
-4
src/applications/diffusion/capability/DiffusionPushCapability.php
··· 4 4 5 5 const CAPABILITY = 'diffusion.push'; 6 6 7 - public function getCapabilityKey() { 8 - return self::CAPABILITY; 9 - } 10 - 11 7 public function getCapabilityName() { 12 8 return pht('Can Push'); 13 9 }
-4
src/applications/drydock/capability/DrydockCreateBlueprintsCapability.php
··· 5 5 6 6 const CAPABILITY = 'drydock.blueprint.create'; 7 7 8 - public function getCapabilityKey() { 9 - return self::CAPABILITY; 10 - } 11 - 12 8 public function getCapabilityName() { 13 9 return pht('Can Create Blueprints'); 14 10 }
-4
src/applications/drydock/capability/DrydockDefaultEditCapability.php
··· 4 4 5 5 const CAPABILITY = 'drydock.default.edit'; 6 6 7 - public function getCapabilityKey() { 8 - return self::CAPABILITY; 9 - } 10 - 11 7 public function getCapabilityName() { 12 8 return pht('Default Blueprint Edit Policy'); 13 9 }
-4
src/applications/drydock/capability/DrydockDefaultViewCapability.php
··· 4 4 5 5 const CAPABILITY = 'drydock.default.view'; 6 6 7 - public function getCapabilityKey() { 8 - return self::CAPABILITY; 9 - } 10 - 11 7 public function getCapabilityName() { 12 8 return pht('Default Blueprint View Policy'); 13 9 }
-4
src/applications/harbormaster/capability/HarbormasterManagePlansCapability.php
··· 5 5 6 6 const CAPABILITY = 'harbormaster.plans'; 7 7 8 - public function getCapabilityKey() { 9 - return self::CAPABILITY; 10 - } 11 - 12 8 public function getCapabilityName() { 13 9 return pht('Can Manage Build Plans'); 14 10 }
-4
src/applications/herald/capability/HeraldManageGlobalRulesCapability.php
··· 5 5 6 6 const CAPABILITY = 'herald.global'; 7 7 8 - public function getCapabilityKey() { 9 - return self::CAPABILITY; 10 - } 11 - 12 8 public function getCapabilityName() { 13 9 return pht('Can Manage Global Rules'); 14 10 }
-4
src/applications/legalpad/capability/LegalpadCreateDocumentsCapability.php
··· 5 5 6 6 const CAPABILITY = 'legalpad.create'; 7 7 8 - public function getCapabilityKey() { 9 - return self::CAPABILITY; 10 - } 11 - 12 8 public function getCapabilityName() { 13 9 return pht('Can Create Documents'); 14 10 }
-4
src/applications/legalpad/capability/LegalpadDefaultEditCapability.php
··· 4 4 5 5 const CAPABILITY = 'legalpad.default.edit'; 6 6 7 - public function getCapabilityKey() { 8 - return self::CAPABILITY; 9 - } 10 - 11 7 public function getCapabilityName() { 12 8 return pht('Default Edit Policy'); 13 9 }
-4
src/applications/legalpad/capability/LegalpadDefaultViewCapability.php
··· 4 4 5 5 const CAPABILITY = 'legalpad.default.view'; 6 6 7 - public function getCapabilityKey() { 8 - return self::CAPABILITY; 9 - } 10 - 11 7 public function getCapabilityName() { 12 8 return pht('Default View Policy'); 13 9 }
-4
src/applications/macro/capability/PhabricatorMacroManageCapability.php
··· 5 5 6 6 const CAPABILITY = 'macro.manage'; 7 7 8 - public function getCapabilityKey() { 9 - return self::CAPABILITY; 10 - } 11 - 12 8 public function getCapabilityName() { 13 9 return pht('Can Manage Macros'); 14 10 }
-4
src/applications/maniphest/capability/ManiphestBulkEditCapability.php
··· 4 4 5 5 const CAPABILITY = 'maniphest.edit.bulk'; 6 6 7 - public function getCapabilityKey() { 8 - return self::CAPABILITY; 9 - } 10 - 11 7 public function getCapabilityName() { 12 8 return pht('Can Bulk Edit Tasks'); 13 9 }
-4
src/applications/maniphest/capability/ManiphestDefaultEditCapability.php
··· 4 4 5 5 const CAPABILITY = 'maniphest.default.edit'; 6 6 7 - public function getCapabilityKey() { 8 - return self::CAPABILITY; 9 - } 10 - 11 7 public function getCapabilityName() { 12 8 return pht('Default Edit Policy'); 13 9 }
-4
src/applications/maniphest/capability/ManiphestDefaultViewCapability.php
··· 4 4 5 5 const CAPABILITY = 'maniphest.default.view'; 6 6 7 - public function getCapabilityKey() { 8 - return self::CAPABILITY; 9 - } 10 - 11 7 public function getCapabilityName() { 12 8 return pht('Default View Policy'); 13 9 }
-4
src/applications/maniphest/capability/ManiphestEditAssignCapability.php
··· 4 4 5 5 const CAPABILITY = 'maniphest.edit.assign'; 6 6 7 - public function getCapabilityKey() { 8 - return self::CAPABILITY; 9 - } 10 - 11 7 public function getCapabilityName() { 12 8 return pht('Can Assign Tasks'); 13 9 }
-4
src/applications/maniphest/capability/ManiphestEditPoliciesCapability.php
··· 5 5 6 6 const CAPABILITY = 'maniphest.edit.policies'; 7 7 8 - public function getCapabilityKey() { 9 - return self::CAPABILITY; 10 - } 11 - 12 8 public function getCapabilityName() { 13 9 return pht('Can Edit Task Policies'); 14 10 }
-4
src/applications/maniphest/capability/ManiphestEditPriorityCapability.php
··· 5 5 6 6 const CAPABILITY = 'maniphest.edit.priority'; 7 7 8 - public function getCapabilityKey() { 9 - return self::CAPABILITY; 10 - } 11 - 12 8 public function getCapabilityName() { 13 9 return pht('Can Prioritize Tasks'); 14 10 }
-4
src/applications/maniphest/capability/ManiphestEditProjectsCapability.php
··· 5 5 6 6 const CAPABILITY = 'maniphest.edit.projects'; 7 7 8 - public function getCapabilityKey() { 9 - return self::CAPABILITY; 10 - } 11 - 12 8 public function getCapabilityName() { 13 9 return pht('Can Edit Task Projects'); 14 10 }
-4
src/applications/maniphest/capability/ManiphestEditStatusCapability.php
··· 4 4 5 5 const CAPABILITY = 'maniphest.edit.status'; 6 6 7 - public function getCapabilityKey() { 8 - return self::CAPABILITY; 9 - } 10 - 11 7 public function getCapabilityName() { 12 8 return pht('Can Edit Task Status'); 13 9 }
-4
src/applications/nuance/capability/NuanceSourceDefaultEditCapability.php
··· 5 5 6 6 const CAPABILITY = 'nuance.source.default.edit'; 7 7 8 - public function getCapabilityKey() { 9 - return self::CAPABILITY; 10 - } 11 - 12 8 public function getCapabilityName() { 13 9 return pht('Default Source Edit Policy'); 14 10 }
-4
src/applications/nuance/capability/NuanceSourceDefaultViewCapability.php
··· 5 5 6 6 const CAPABILITY = 'nuance.source.default.view'; 7 7 8 - public function getCapabilityKey() { 9 - return self::CAPABILITY; 10 - } 11 - 12 8 public function getCapabilityName() { 13 9 return pht('Default Source View Policy'); 14 10 }
-4
src/applications/nuance/capability/NuanceSourceManageCapability.php
··· 4 4 5 5 const CAPABILITY = 'nuance.source.manage'; 6 6 7 - public function getCapabilityKey() { 8 - return self::CAPABILITY; 9 - } 10 - 11 7 public function getCapabilityName() { 12 8 return pht('Can Manage Sources'); 13 9 }
-4
src/applications/oauthserver/capability/PhabricatorOAuthServerCreateClientsCapability.php
··· 5 5 6 6 const CAPABILITY = 'oauthserver.create'; 7 7 8 - public function getCapabilityKey() { 9 - return self::CAPABILITY; 10 - } 11 - 12 8 public function getCapabilityName() { 13 9 return pht('Can Create OAuth Applications'); 14 10 }
-4
src/applications/paste/capability/PasteDefaultViewCapability.php
··· 4 4 5 5 const CAPABILITY = 'paste.default.view'; 6 6 7 - public function getCapabilityKey() { 8 - return self::CAPABILITY; 9 - } 10 - 11 7 public function getCapabilityName() { 12 8 return pht('Default View Policy'); 13 9 }
-4
src/applications/people/capability/PeopleBrowseUserDirectoryCapability.php
··· 5 5 6 6 const CAPABILITY = 'people.browse'; 7 7 8 - public function getCapabilityKey() { 9 - return self::CAPABILITY; 10 - } 11 - 12 8 public function getCapabilityName() { 13 9 return pht('Can Browse User Directory'); 14 10 }
-4
src/applications/pholio/capability/PholioDefaultEditCapability.php
··· 4 4 5 5 const CAPABILITY = 'pholio.default.edit'; 6 6 7 - public function getCapabilityKey() { 8 - return self::CAPABILITY; 9 - } 10 - 11 7 public function getCapabilityName() { 12 8 return pht('Default Edit Policy'); 13 9 }
-4
src/applications/pholio/capability/PholioDefaultViewCapability.php
··· 4 4 5 5 const CAPABILITY = 'pholio.default.view'; 6 6 7 - public function getCapabilityKey() { 8 - return self::CAPABILITY; 9 - } 10 - 11 7 public function getCapabilityName() { 12 8 return pht('Default View Policy'); 13 9 }
-4
src/applications/phragment/capability/PhragmentCanCreateCapability.php
··· 4 4 5 5 const CAPABILITY = 'phragment.create'; 6 6 7 - public function getCapabilityKey() { 8 - return self::CAPABILITY; 9 - } 10 - 11 7 public function getCapabilityName() { 12 8 return pht('Can Create Fragments'); 13 9 }
+1 -3
src/applications/policy/capability/PhabricatorPolicyCanEditCapability.php
··· 3 3 final class PhabricatorPolicyCanEditCapability 4 4 extends PhabricatorPolicyCapability { 5 5 6 - public function getCapabilityKey() { 7 - return self::CAN_EDIT; 8 - } 6 + const CAPABILITY = self::CAN_EDIT; 9 7 10 8 public function getCapabilityName() { 11 9 return pht('Can Edit');
+1 -3
src/applications/policy/capability/PhabricatorPolicyCanJoinCapability.php
··· 3 3 final class PhabricatorPolicyCanJoinCapability 4 4 extends PhabricatorPolicyCapability { 5 5 6 - public function getCapabilityKey() { 7 - return self::CAN_JOIN; 8 - } 6 + const CAPABILITY = self::CAN_JOIN; 9 7 10 8 public function getCapabilityName() { 11 9 return pht('Can Join');
+1 -3
src/applications/policy/capability/PhabricatorPolicyCanViewCapability.php
··· 3 3 final class PhabricatorPolicyCanViewCapability 4 4 extends PhabricatorPolicyCapability { 5 5 6 - public function getCapabilityKey() { 7 - return self::CAN_VIEW; 8 - } 6 + const CAPABILITY = self::CAN_VIEW; 9 7 10 8 public function getCapabilityName() { 11 9 return pht('Can View');
+21 -1
src/applications/policy/capability/PhabricatorPolicyCapability.php
··· 14 14 * 15 15 * @return string Globally unique capability key. 16 16 */ 17 - abstract public function getCapabilityKey(); 17 + final public function getCapabilityKey() { 18 + $class = new ReflectionClass($this); 19 + 20 + $const = $class->getConstant('CAPABILITY'); 21 + if ($const === false) { 22 + throw new Exception( 23 + pht( 24 + 'PolicyCapability class "%s" must define an CAPABILITY property.', 25 + get_class($this))); 26 + } 27 + 28 + if (!is_string($const)) { 29 + throw new Exception( 30 + pht( 31 + 'PolicyCapability class "%s" has an invalid CAPABILITY '. 32 + 'property. Capability constants must be a string.', 33 + get_class($this))); 34 + } 35 + 36 + return $const; 37 + } 18 38 19 39 20 40 /**
-4
src/applications/project/capability/ProjectCreateProjectsCapability.php
··· 5 5 6 6 const CAPABILITY = 'project.create'; 7 7 8 - public function getCapabilityKey() { 9 - return self::CAPABILITY; 10 - } 11 - 12 8 public function getCapabilityName() { 13 9 return pht('Can Create Projects'); 14 10 }
-4
src/applications/slowvote/capability/PhabricatorSlowvoteDefaultViewCapability.php
··· 5 5 6 6 const CAPABILITY = 'slowvote.default.view'; 7 7 8 - public function getCapabilityKey() { 9 - return self::CAPABILITY; 10 - } 11 - 12 8 public function getCapabilityName() { 13 9 return pht('Default View Policy'); 14 10 }