diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 58a6311d0e..ec8f1a4432 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -625,6 +625,8 @@ phutil_register_library_map(array( 'HeraldAction' => 'applications/herald/storage/HeraldAction.php', 'HeraldAdapter' => 'applications/herald/adapter/HeraldAdapter.php', 'HeraldApplyTranscript' => 'applications/herald/storage/transcript/HeraldApplyTranscript.php', + 'HeraldCapabilityCreateRules' => 'applications/herald/capability/HeraldCapabilityCreateRules.php', + 'HeraldCapabilityManageGlobalRules' => 'applications/herald/capability/HeraldCapabilityManageGlobalRules.php', 'HeraldCommitAdapter' => 'applications/herald/adapter/HeraldCommitAdapter.php', 'HeraldCondition' => 'applications/herald/storage/HeraldCondition.php', 'HeraldConditionTranscript' => 'applications/herald/storage/transcript/HeraldConditionTranscript.php', @@ -2723,6 +2725,8 @@ phutil_register_library_map(array( 'HarbormasterScratchTable' => 'HarbormasterDAO', 'HeraldAction' => 'HeraldDAO', 'HeraldApplyTranscript' => 'HeraldDAO', + 'HeraldCapabilityCreateRules' => 'PhabricatorPolicyCapability', + 'HeraldCapabilityManageGlobalRules' => 'PhabricatorPolicyCapability', 'HeraldCommitAdapter' => 'HeraldAdapter', 'HeraldCondition' => 'HeraldDAO', 'HeraldController' => 'PhabricatorController', diff --git a/src/applications/base/PhabricatorApplication.php b/src/applications/base/PhabricatorApplication.php index ebe44f0f89..d7e72275a2 100644 --- a/src/applications/base/PhabricatorApplication.php +++ b/src/applications/base/PhabricatorApplication.php @@ -400,21 +400,26 @@ abstract class PhabricatorApplication private function getCustomCapabilitySpecification($capability) { $custom = $this->getCustomCapabilities(); - if (empty($custom[$capability])) { + if (!isset($custom[$capability])) { throw new Exception("Unknown capability '{$capability}'!"); } return $custom[$capability]; } public function getCapabilityLabel($capability) { - $map = array( - PhabricatorPolicyCapability::CAN_VIEW => pht('Can Use Application'), - PhabricatorPolicyCapability::CAN_EDIT => pht('Can Configure Application'), - ); + switch ($capability) { + case PhabricatorPolicyCapability::CAN_VIEW: + return pht('Can Use Application'); + case PhabricatorPolicyCapability::CAN_EDIT: + return pht('Can Configure Application'); + } - $map += ipull($this->getCustomCapabilities(), 'label'); + $capobj = PhabricatorPolicyCapability::getCapabilityByKey($capability); + if ($capobj) { + return $capobj->getCapabilityName(); + } - return idx($map, $capability); + return null; } public function isCapabilityEditable($capability) { diff --git a/src/applications/herald/application/PhabricatorApplicationHerald.php b/src/applications/herald/application/PhabricatorApplicationHerald.php index 13d3a91bba..b3b7049785 100644 --- a/src/applications/herald/application/PhabricatorApplicationHerald.php +++ b/src/applications/herald/application/PhabricatorApplicationHerald.php @@ -2,9 +2,6 @@ final class PhabricatorApplicationHerald extends PhabricatorApplication { - const CAN_CREATE_RULE = 'herald.create'; - const CAN_CREATE_GLOBAL_RULE = 'herald.global'; - public function getBaseURI() { return '/herald/'; } @@ -54,11 +51,9 @@ final class PhabricatorApplicationHerald extends PhabricatorApplication { protected function getCustomCapabilities() { return array( - self::CAN_CREATE_RULE => array( - 'label' => pht('Can Create Rules'), + HeraldCapabilityCreateRules::CAPABILITY => array( ), - self::CAN_CREATE_GLOBAL_RULE => array( - 'label' => pht('Can Create Global Rules'), + HeraldCapabilityManageGlobalRules::CAPABILITY => array( 'caption' => pht('Global rules can bypass access controls.'), 'default' => PhabricatorPolicies::POLICY_ADMIN, ), diff --git a/src/applications/herald/capability/HeraldCapabilityCreateRules.php b/src/applications/herald/capability/HeraldCapabilityCreateRules.php new file mode 100644 index 0000000000..8f8026e60d --- /dev/null +++ b/src/applications/herald/capability/HeraldCapabilityCreateRules.php @@ -0,0 +1,20 @@ +hasApplicationCapability( - PhabricatorApplicationHerald::CAN_CREATE_RULE); + HeraldCapabilityCreateRules::CAPABILITY); $crumbs->addAction( id(new PHUIListItemView()) diff --git a/src/applications/herald/controller/HeraldDisableController.php b/src/applications/herald/controller/HeraldDisableController.php index 0313af86e4..13c8ad0807 100644 --- a/src/applications/herald/controller/HeraldDisableController.php +++ b/src/applications/herald/controller/HeraldDisableController.php @@ -30,7 +30,7 @@ final class HeraldDisableController extends HeraldController { if ($rule->getRuleType() == HeraldRuleTypeConfig::RULE_TYPE_GLOBAL) { $this->requireApplicationCapability( - PhabricatorApplicationHerald::CAN_CREATE_GLOBAL_RULE); + HeraldCapabilityManageGlobalRules::CAPABILITY); } $view_uri = $this->getApplicationURI("rule/{$id}/"); diff --git a/src/applications/herald/controller/HeraldNewController.php b/src/applications/herald/controller/HeraldNewController.php index ec4b08e810..e27b33160c 100644 --- a/src/applications/herald/controller/HeraldNewController.php +++ b/src/applications/herald/controller/HeraldNewController.php @@ -15,10 +15,10 @@ final class HeraldNewController extends HeraldController { $user = $request->getUser(); $this->requireApplicationCapability( - PhabricatorApplicationHerald::CAN_CREATE_RULE); + HeraldCapabilityCreateRules::CAPABILITY); $can_global = $this->hasApplicationCapability( - PhabricatorApplicationHerald::CAN_CREATE_GLOBAL_RULE); + HeraldCapabilityManageGlobalRules::CAPABILITY); $content_type_map = HeraldAdapter::getEnabledAdapterMap($user); if (empty($content_type_map[$this->contentType])) { @@ -39,7 +39,7 @@ final class HeraldNewController extends HeraldController { if (!$can_global) { $global_link = $this->explainApplicationCapability( - PhabricatorApplicationHerald::CAN_CREATE_GLOBAL_RULE, + HeraldCapabilityManageGlobalRules::CAPABILITY, pht('You do not have permission to create or manage global rules.')); } else { $global_link = null; diff --git a/src/applications/herald/controller/HeraldRuleController.php b/src/applications/herald/controller/HeraldRuleController.php index 1ddf62280b..7060391bf9 100644 --- a/src/applications/herald/controller/HeraldRuleController.php +++ b/src/applications/herald/controller/HeraldRuleController.php @@ -49,12 +49,12 @@ final class HeraldRuleController extends HeraldController { $cancel_uri = $this->getApplicationURI(); $this->requireApplicationCapability( - PhabricatorApplicationHerald::CAN_CREATE_RULE); + HeraldCapabilityCreateRules::CAPABILITY); } if ($rule->getRuleType() == HeraldRuleTypeConfig::RULE_TYPE_GLOBAL) { $this->requireApplicationCapability( - PhabricatorApplicationHerald::CAN_CREATE_GLOBAL_RULE); + HeraldCapabilityManageGlobalRules::CAPABILITY); } $adapter = HeraldAdapter::getAdapterForContentType($rule->getContentType()); diff --git a/src/applications/herald/storage/HeraldRule.php b/src/applications/herald/storage/HeraldRule.php index fbfc65f9cd..14de5eb3e2 100644 --- a/src/applications/herald/storage/HeraldRule.php +++ b/src/applications/herald/storage/HeraldRule.php @@ -205,7 +205,7 @@ final class HeraldRule extends HeraldDAO case PhabricatorPolicyCapability::CAN_EDIT: $app = 'PhabricatorApplicationHerald'; $herald = PhabricatorApplication::getByClass($app); - $global = PhabricatorApplicationHerald::CAN_CREATE_GLOBAL_RULE; + $global = HeraldCapabilityManageGlobalRules::CAPABILITY; return $herald->getPolicy($global); } } else {