@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.

Move Herald application capabilities to newer infrastructure

Summary: Ref T603. Use the new hotness.

Test Plan: Edited Herald in Applications, tried to create rules / global rules without capabilities, got reasonable error messages.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T603

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

+66 -22
+4
src/__phutil_library_map__.php
··· 625 625 'HeraldAction' => 'applications/herald/storage/HeraldAction.php', 626 626 'HeraldAdapter' => 'applications/herald/adapter/HeraldAdapter.php', 627 627 'HeraldApplyTranscript' => 'applications/herald/storage/transcript/HeraldApplyTranscript.php', 628 + 'HeraldCapabilityCreateRules' => 'applications/herald/capability/HeraldCapabilityCreateRules.php', 629 + 'HeraldCapabilityManageGlobalRules' => 'applications/herald/capability/HeraldCapabilityManageGlobalRules.php', 628 630 'HeraldCommitAdapter' => 'applications/herald/adapter/HeraldCommitAdapter.php', 629 631 'HeraldCondition' => 'applications/herald/storage/HeraldCondition.php', 630 632 'HeraldConditionTranscript' => 'applications/herald/storage/transcript/HeraldConditionTranscript.php', ··· 2723 2725 'HarbormasterScratchTable' => 'HarbormasterDAO', 2724 2726 'HeraldAction' => 'HeraldDAO', 2725 2727 'HeraldApplyTranscript' => 'HeraldDAO', 2728 + 'HeraldCapabilityCreateRules' => 'PhabricatorPolicyCapability', 2729 + 'HeraldCapabilityManageGlobalRules' => 'PhabricatorPolicyCapability', 2726 2730 'HeraldCommitAdapter' => 'HeraldAdapter', 2727 2731 'HeraldCondition' => 'HeraldDAO', 2728 2732 'HeraldController' => 'PhabricatorController',
+12 -7
src/applications/base/PhabricatorApplication.php
··· 400 400 401 401 private function getCustomCapabilitySpecification($capability) { 402 402 $custom = $this->getCustomCapabilities(); 403 - if (empty($custom[$capability])) { 403 + if (!isset($custom[$capability])) { 404 404 throw new Exception("Unknown capability '{$capability}'!"); 405 405 } 406 406 return $custom[$capability]; 407 407 } 408 408 409 409 public function getCapabilityLabel($capability) { 410 - $map = array( 411 - PhabricatorPolicyCapability::CAN_VIEW => pht('Can Use Application'), 412 - PhabricatorPolicyCapability::CAN_EDIT => pht('Can Configure Application'), 413 - ); 410 + switch ($capability) { 411 + case PhabricatorPolicyCapability::CAN_VIEW: 412 + return pht('Can Use Application'); 413 + case PhabricatorPolicyCapability::CAN_EDIT: 414 + return pht('Can Configure Application'); 415 + } 414 416 415 - $map += ipull($this->getCustomCapabilities(), 'label'); 417 + $capobj = PhabricatorPolicyCapability::getCapabilityByKey($capability); 418 + if ($capobj) { 419 + return $capobj->getCapabilityName(); 420 + } 416 421 417 - return idx($map, $capability); 422 + return null; 418 423 } 419 424 420 425 public function isCapabilityEditable($capability) {
+2 -7
src/applications/herald/application/PhabricatorApplicationHerald.php
··· 2 2 3 3 final class PhabricatorApplicationHerald extends PhabricatorApplication { 4 4 5 - const CAN_CREATE_RULE = 'herald.create'; 6 - const CAN_CREATE_GLOBAL_RULE = 'herald.global'; 7 - 8 5 public function getBaseURI() { 9 6 return '/herald/'; 10 7 } ··· 54 51 55 52 protected function getCustomCapabilities() { 56 53 return array( 57 - self::CAN_CREATE_RULE => array( 58 - 'label' => pht('Can Create Rules'), 54 + HeraldCapabilityCreateRules::CAPABILITY => array( 59 55 ), 60 - self::CAN_CREATE_GLOBAL_RULE => array( 61 - 'label' => pht('Can Create Global Rules'), 56 + HeraldCapabilityManageGlobalRules::CAPABILITY => array( 62 57 'caption' => pht('Global rules can bypass access controls.'), 63 58 'default' => PhabricatorPolicies::POLICY_ADMIN, 64 59 ),
+20
src/applications/herald/capability/HeraldCapabilityCreateRules.php
··· 1 + <?php 2 + 3 + final class HeraldCapabilityCreateRules 4 + extends PhabricatorPolicyCapability { 5 + 6 + const CAPABILITY = 'herald.create'; 7 + 8 + public function getCapabilityKey() { 9 + return self::CAPABILITY; 10 + } 11 + 12 + public function getCapabilityName() { 13 + return pht('Can Create Rules'); 14 + } 15 + 16 + public function describeCapabilityRejection() { 17 + return pht('You do not have permission to create new Herald rules.'); 18 + } 19 + 20 + }
+20
src/applications/herald/capability/HeraldCapabilityManageGlobalRules.php
··· 1 + <?php 2 + 3 + final class HeraldCapabilityManageGlobalRules 4 + extends PhabricatorPolicyCapability { 5 + 6 + const CAPABILITY = 'herald.global'; 7 + 8 + public function getCapabilityKey() { 9 + return self::CAPABILITY; 10 + } 11 + 12 + public function getCapabilityName() { 13 + return pht('Can Manage Global Rules'); 14 + } 15 + 16 + public function describeCapabilityRejection() { 17 + return pht('You do not have permission to manage global Herald rules.'); 18 + } 19 + 20 + }
+1 -1
src/applications/herald/controller/HeraldController.php
··· 24 24 $crumbs = parent::buildApplicationCrumbs(); 25 25 26 26 $can_create = $this->hasApplicationCapability( 27 - PhabricatorApplicationHerald::CAN_CREATE_RULE); 27 + HeraldCapabilityCreateRules::CAPABILITY); 28 28 29 29 $crumbs->addAction( 30 30 id(new PHUIListItemView())
+1 -1
src/applications/herald/controller/HeraldDisableController.php
··· 30 30 31 31 if ($rule->getRuleType() == HeraldRuleTypeConfig::RULE_TYPE_GLOBAL) { 32 32 $this->requireApplicationCapability( 33 - PhabricatorApplicationHerald::CAN_CREATE_GLOBAL_RULE); 33 + HeraldCapabilityManageGlobalRules::CAPABILITY); 34 34 } 35 35 36 36 $view_uri = $this->getApplicationURI("rule/{$id}/");
+3 -3
src/applications/herald/controller/HeraldNewController.php
··· 15 15 $user = $request->getUser(); 16 16 17 17 $this->requireApplicationCapability( 18 - PhabricatorApplicationHerald::CAN_CREATE_RULE); 18 + HeraldCapabilityCreateRules::CAPABILITY); 19 19 20 20 $can_global = $this->hasApplicationCapability( 21 - PhabricatorApplicationHerald::CAN_CREATE_GLOBAL_RULE); 21 + HeraldCapabilityManageGlobalRules::CAPABILITY); 22 22 23 23 $content_type_map = HeraldAdapter::getEnabledAdapterMap($user); 24 24 if (empty($content_type_map[$this->contentType])) { ··· 39 39 40 40 if (!$can_global) { 41 41 $global_link = $this->explainApplicationCapability( 42 - PhabricatorApplicationHerald::CAN_CREATE_GLOBAL_RULE, 42 + HeraldCapabilityManageGlobalRules::CAPABILITY, 43 43 pht('You do not have permission to create or manage global rules.')); 44 44 } else { 45 45 $global_link = null;
+2 -2
src/applications/herald/controller/HeraldRuleController.php
··· 49 49 $cancel_uri = $this->getApplicationURI(); 50 50 51 51 $this->requireApplicationCapability( 52 - PhabricatorApplicationHerald::CAN_CREATE_RULE); 52 + HeraldCapabilityCreateRules::CAPABILITY); 53 53 } 54 54 55 55 if ($rule->getRuleType() == HeraldRuleTypeConfig::RULE_TYPE_GLOBAL) { 56 56 $this->requireApplicationCapability( 57 - PhabricatorApplicationHerald::CAN_CREATE_GLOBAL_RULE); 57 + HeraldCapabilityManageGlobalRules::CAPABILITY); 58 58 } 59 59 60 60 $adapter = HeraldAdapter::getAdapterForContentType($rule->getContentType());
+1 -1
src/applications/herald/storage/HeraldRule.php
··· 205 205 case PhabricatorPolicyCapability::CAN_EDIT: 206 206 $app = 'PhabricatorApplicationHerald'; 207 207 $herald = PhabricatorApplication::getByClass($app); 208 - $global = PhabricatorApplicationHerald::CAN_CREATE_GLOBAL_RULE; 208 + $global = HeraldCapabilityManageGlobalRules::CAPABILITY; 209 209 return $herald->getPolicy($global); 210 210 } 211 211 } else {