1
0
Fork 0
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:
Joshua Spence 2014-07-25 08:25:42 +10:00
parent c34de83619
commit b4d7a9de39
39 changed files with 24 additions and 150 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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;
}
/**

View file

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

View file

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