mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 22:10:55 +01:00
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
This commit is contained in:
parent
c34de83619
commit
b4d7a9de39
39 changed files with 24 additions and 150 deletions
|
@ -5,10 +5,6 @@ final class PhabricatorCountdownDefaultViewCapability
|
|||
|
||||
const CAPABILITY = 'countdown.default.view';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Default View Policy');
|
||||
}
|
||||
|
|
|
@ -5,10 +5,6 @@ final class DifferentialDefaultViewCapability
|
|||
|
||||
const CAPABILITY = 'differential.default.view';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Default View Policy');
|
||||
}
|
||||
|
|
|
@ -5,10 +5,6 @@ final class DiffusionCreateRepositoriesCapability
|
|||
|
||||
const CAPABILITY = 'diffusion.create';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Can Create Repositories');
|
||||
}
|
||||
|
|
|
@ -4,10 +4,6 @@ final class DiffusionDefaultEditCapability extends PhabricatorPolicyCapability {
|
|||
|
||||
const CAPABILITY = 'diffusion.default.edit';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Default Edit Policy');
|
||||
}
|
||||
|
|
|
@ -4,10 +4,6 @@ final class DiffusionDefaultPushCapability extends PhabricatorPolicyCapability {
|
|||
|
||||
const CAPABILITY = 'diffusion.default.push';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Default Push Policy');
|
||||
}
|
||||
|
|
|
@ -4,10 +4,6 @@ final class DiffusionDefaultViewCapability extends PhabricatorPolicyCapability {
|
|||
|
||||
const CAPABILITY = 'diffusion.default.view';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Default View Policy');
|
||||
}
|
||||
|
|
|
@ -4,10 +4,6 @@ final class DiffusionPushCapability extends PhabricatorPolicyCapability {
|
|||
|
||||
const CAPABILITY = 'diffusion.push';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Can Push');
|
||||
}
|
||||
|
|
|
@ -5,10 +5,6 @@ final class DrydockCreateBlueprintsCapability
|
|||
|
||||
const CAPABILITY = 'drydock.blueprint.create';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Can Create Blueprints');
|
||||
}
|
||||
|
|
|
@ -4,10 +4,6 @@ final class DrydockDefaultEditCapability extends PhabricatorPolicyCapability {
|
|||
|
||||
const CAPABILITY = 'drydock.default.edit';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Default Blueprint Edit Policy');
|
||||
}
|
||||
|
|
|
@ -4,10 +4,6 @@ final class DrydockDefaultViewCapability extends PhabricatorPolicyCapability {
|
|||
|
||||
const CAPABILITY = 'drydock.default.view';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Default Blueprint View Policy');
|
||||
}
|
||||
|
|
|
@ -5,10 +5,6 @@ final class HarbormasterManagePlansCapability
|
|||
|
||||
const CAPABILITY = 'harbormaster.plans';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Can Manage Build Plans');
|
||||
}
|
||||
|
|
|
@ -5,10 +5,6 @@ final class HeraldManageGlobalRulesCapability
|
|||
|
||||
const CAPABILITY = 'herald.global';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Can Manage Global Rules');
|
||||
}
|
||||
|
|
|
@ -5,10 +5,6 @@ final class LegalpadCreateDocumentsCapability
|
|||
|
||||
const CAPABILITY = 'legalpad.create';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Can Create Documents');
|
||||
}
|
||||
|
|
|
@ -4,10 +4,6 @@ final class LegalpadDefaultEditCapability extends PhabricatorPolicyCapability {
|
|||
|
||||
const CAPABILITY = 'legalpad.default.edit';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Default Edit Policy');
|
||||
}
|
||||
|
|
|
@ -4,10 +4,6 @@ final class LegalpadDefaultViewCapability extends PhabricatorPolicyCapability {
|
|||
|
||||
const CAPABILITY = 'legalpad.default.view';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Default View Policy');
|
||||
}
|
||||
|
|
|
@ -5,10 +5,6 @@ final class PhabricatorMacroManageCapability
|
|||
|
||||
const CAPABILITY = 'macro.manage';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Can Manage Macros');
|
||||
}
|
||||
|
|
|
@ -4,10 +4,6 @@ final class ManiphestBulkEditCapability extends PhabricatorPolicyCapability {
|
|||
|
||||
const CAPABILITY = 'maniphest.edit.bulk';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Can Bulk Edit Tasks');
|
||||
}
|
||||
|
|
|
@ -4,10 +4,6 @@ final class ManiphestDefaultEditCapability extends PhabricatorPolicyCapability {
|
|||
|
||||
const CAPABILITY = 'maniphest.default.edit';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Default Edit Policy');
|
||||
}
|
||||
|
|
|
@ -4,10 +4,6 @@ final class ManiphestDefaultViewCapability extends PhabricatorPolicyCapability {
|
|||
|
||||
const CAPABILITY = 'maniphest.default.view';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Default View Policy');
|
||||
}
|
||||
|
|
|
@ -4,10 +4,6 @@ final class ManiphestEditAssignCapability extends PhabricatorPolicyCapability {
|
|||
|
||||
const CAPABILITY = 'maniphest.edit.assign';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Can Assign Tasks');
|
||||
}
|
||||
|
|
|
@ -5,10 +5,6 @@ final class ManiphestEditPoliciesCapability
|
|||
|
||||
const CAPABILITY = 'maniphest.edit.policies';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Can Edit Task Policies');
|
||||
}
|
||||
|
|
|
@ -5,10 +5,6 @@ final class ManiphestEditPriorityCapability
|
|||
|
||||
const CAPABILITY = 'maniphest.edit.priority';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Can Prioritize Tasks');
|
||||
}
|
||||
|
|
|
@ -5,10 +5,6 @@ final class ManiphestEditProjectsCapability
|
|||
|
||||
const CAPABILITY = 'maniphest.edit.projects';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Can Edit Task Projects');
|
||||
}
|
||||
|
|
|
@ -4,10 +4,6 @@ final class ManiphestEditStatusCapability extends PhabricatorPolicyCapability {
|
|||
|
||||
const CAPABILITY = 'maniphest.edit.status';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Can Edit Task Status');
|
||||
}
|
||||
|
|
|
@ -5,10 +5,6 @@ final class NuanceSourceDefaultEditCapability
|
|||
|
||||
const CAPABILITY = 'nuance.source.default.edit';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Default Source Edit Policy');
|
||||
}
|
||||
|
|
|
@ -5,10 +5,6 @@ final class NuanceSourceDefaultViewCapability
|
|||
|
||||
const CAPABILITY = 'nuance.source.default.view';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Default Source View Policy');
|
||||
}
|
||||
|
|
|
@ -4,10 +4,6 @@ final class NuanceSourceManageCapability extends PhabricatorPolicyCapability {
|
|||
|
||||
const CAPABILITY = 'nuance.source.manage';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Can Manage Sources');
|
||||
}
|
||||
|
|
|
@ -5,10 +5,6 @@ final class PhabricatorOAuthServerCreateClientsCapability
|
|||
|
||||
const CAPABILITY = 'oauthserver.create';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Can Create OAuth Applications');
|
||||
}
|
||||
|
|
|
@ -4,10 +4,6 @@ final class PasteDefaultViewCapability extends PhabricatorPolicyCapability {
|
|||
|
||||
const CAPABILITY = 'paste.default.view';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Default View Policy');
|
||||
}
|
||||
|
|
|
@ -5,10 +5,6 @@ final class PeopleBrowseUserDirectoryCapability
|
|||
|
||||
const CAPABILITY = 'people.browse';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Can Browse User Directory');
|
||||
}
|
||||
|
|
|
@ -4,10 +4,6 @@ final class PholioDefaultEditCapability extends PhabricatorPolicyCapability {
|
|||
|
||||
const CAPABILITY = 'pholio.default.edit';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Default Edit Policy');
|
||||
}
|
||||
|
|
|
@ -4,10 +4,6 @@ final class PholioDefaultViewCapability extends PhabricatorPolicyCapability {
|
|||
|
||||
const CAPABILITY = 'pholio.default.view';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Default View Policy');
|
||||
}
|
||||
|
|
|
@ -4,10 +4,6 @@ final class PhragmentCanCreateCapability extends PhabricatorPolicyCapability {
|
|||
|
||||
const CAPABILITY = 'phragment.create';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Can Create Fragments');
|
||||
}
|
||||
|
|
|
@ -3,9 +3,7 @@
|
|||
final class PhabricatorPolicyCanEditCapability
|
||||
extends PhabricatorPolicyCapability {
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAN_EDIT;
|
||||
}
|
||||
const CAPABILITY = self::CAN_EDIT;
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Can Edit');
|
||||
|
|
|
@ -3,9 +3,7 @@
|
|||
final class PhabricatorPolicyCanJoinCapability
|
||||
extends PhabricatorPolicyCapability {
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAN_JOIN;
|
||||
}
|
||||
const CAPABILITY = self::CAN_JOIN;
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Can Join');
|
||||
|
|
|
@ -3,9 +3,7 @@
|
|||
final class PhabricatorPolicyCanViewCapability
|
||||
extends PhabricatorPolicyCapability {
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAN_VIEW;
|
||||
}
|
||||
const CAPABILITY = self::CAN_VIEW;
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Can View');
|
||||
|
|
|
@ -14,7 +14,27 @@ abstract class PhabricatorPolicyCapability extends Phobject {
|
|||
*
|
||||
* @return string Globally unique capability key.
|
||||
*/
|
||||
abstract public function getCapabilityKey();
|
||||
final public function getCapabilityKey() {
|
||||
$class = new ReflectionClass($this);
|
||||
|
||||
$const = $class->getConstant('CAPABILITY');
|
||||
if ($const === false) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'PolicyCapability class "%s" must define an CAPABILITY property.',
|
||||
get_class($this)));
|
||||
}
|
||||
|
||||
if (!is_string($const)) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'PolicyCapability class "%s" has an invalid CAPABILITY '.
|
||||
'property. Capability constants must be a string.',
|
||||
get_class($this)));
|
||||
}
|
||||
|
||||
return $const;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,10 +5,6 @@ final class ProjectCreateProjectsCapability
|
|||
|
||||
const CAPABILITY = 'project.create';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Can Create Projects');
|
||||
}
|
||||
|
|
|
@ -5,10 +5,6 @@ final class PhabricatorSlowvoteDefaultViewCapability
|
|||
|
||||
const CAPABILITY = 'slowvote.default.view';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Default View Policy');
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue