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

Modularize the Diffusion/Differential "Block" Herald actions

Also removes HeraldCustomAction. This completes action modularization.

Ref T8726.

+195 -252
+13
resources/sql/autopatches/20150803.herald.2.sql
··· 1 + UPDATE {$NAMESPACE}_herald.herald_action a 2 + JOIN {$NAMESPACE}_herald.herald_rule r 3 + ON a.ruleID = r.id 4 + SET a.action = 'diffusion.block' 5 + WHERE r.contentType != 'differential.diff' 6 + AND a.action = 'block'; 7 + 8 + UPDATE {$NAMESPACE}_herald.herald_action a 9 + JOIN {$NAMESPACE}_herald.herald_rule r 10 + ON a.ruleID = r.id 11 + SET a.action = 'differential.block' 12 + WHERE r.contentType = 'differential.diff' 13 + AND a.action = 'block';
+4 -2
src/__phutil_library_map__.php
··· 303 303 'DifferentialAuditorsField' => 'applications/differential/customfield/DifferentialAuditorsField.php', 304 304 'DifferentialAuthorField' => 'applications/differential/customfield/DifferentialAuthorField.php', 305 305 'DifferentialBlameRevisionField' => 'applications/differential/customfield/DifferentialBlameRevisionField.php', 306 + 'DifferentialBlockHeraldAction' => 'applications/differential/herald/DifferentialBlockHeraldAction.php', 306 307 'DifferentialBranchField' => 'applications/differential/customfield/DifferentialBranchField.php', 307 308 'DifferentialChangeHeraldFieldGroup' => 'applications/differential/herald/DifferentialChangeHeraldFieldGroup.php', 308 309 'DifferentialChangeType' => 'applications/differential/constants/DifferentialChangeType.php', ··· 501 502 'DiffusionAuditorsAddAuditorsHeraldAction' => 'applications/diffusion/herald/DiffusionAuditorsAddAuditorsHeraldAction.php', 502 503 'DiffusionAuditorsAddSelfHeraldAction' => 'applications/diffusion/herald/DiffusionAuditorsAddSelfHeraldAction.php', 503 504 'DiffusionAuditorsHeraldAction' => 'applications/diffusion/herald/DiffusionAuditorsHeraldAction.php', 505 + 'DiffusionBlockHeraldAction' => 'applications/diffusion/herald/DiffusionBlockHeraldAction.php', 504 506 'DiffusionBranchQueryConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionBranchQueryConduitAPIMethod.php', 505 507 'DiffusionBranchTableController' => 'applications/diffusion/controller/DiffusionBranchTableController.php', 506 508 'DiffusionBranchTableView' => 'applications/diffusion/view/DiffusionBranchTableView.php', ··· 1031 1033 'HeraldConditionTranscript' => 'applications/herald/storage/transcript/HeraldConditionTranscript.php', 1032 1034 'HeraldContentSourceField' => 'applications/herald/field/HeraldContentSourceField.php', 1033 1035 'HeraldController' => 'applications/herald/controller/HeraldController.php', 1034 - 'HeraldCustomAction' => 'applications/herald/extension/HeraldCustomAction.php', 1035 1036 'HeraldDAO' => 'applications/herald/storage/HeraldDAO.php', 1036 1037 'HeraldDifferentialAdapter' => 'applications/differential/herald/HeraldDifferentialAdapter.php', 1037 1038 'HeraldDifferentialDiffAdapter' => 'applications/differential/herald/HeraldDifferentialDiffAdapter.php', ··· 3908 3909 'DifferentialAuditorsField' => 'DifferentialStoredCustomField', 3909 3910 'DifferentialAuthorField' => 'DifferentialCustomField', 3910 3911 'DifferentialBlameRevisionField' => 'DifferentialStoredCustomField', 3912 + 'DifferentialBlockHeraldAction' => 'HeraldAction', 3911 3913 'DifferentialBranchField' => 'DifferentialCustomField', 3912 3914 'DifferentialChangeHeraldFieldGroup' => 'HeraldFieldGroup', 3913 3915 'DifferentialChangeType' => 'Phobject', ··· 4135 4137 'DiffusionAuditorsAddAuditorsHeraldAction' => 'DiffusionAuditorsHeraldAction', 4136 4138 'DiffusionAuditorsAddSelfHeraldAction' => 'DiffusionAuditorsHeraldAction', 4137 4139 'DiffusionAuditorsHeraldAction' => 'HeraldAction', 4140 + 'DiffusionBlockHeraldAction' => 'HeraldAction', 4138 4141 'DiffusionBranchQueryConduitAPIMethod' => 'DiffusionQueryConduitAPIMethod', 4139 4142 'DiffusionBranchTableController' => 'DiffusionController', 4140 4143 'DiffusionBranchTableView' => 'DiffusionView', ··· 4745 4748 'HeraldConditionTranscript' => 'Phobject', 4746 4749 'HeraldContentSourceField' => 'HeraldField', 4747 4750 'HeraldController' => 'PhabricatorController', 4748 - 'HeraldCustomAction' => 'Phobject', 4749 4751 'HeraldDAO' => 'PhabricatorLiskDAO', 4750 4752 'HeraldDifferentialAdapter' => 'HeraldAdapter', 4751 4753 'HeraldDifferentialDiffAdapter' => 'HeraldDifferentialAdapter',
+2 -1
src/applications/differential/editor/DifferentialDiffEditor.php
··· 131 131 $rules = mpull($rules, null, 'getID'); 132 132 133 133 $effects = $engine->applyRules($rules, $adapter); 134 + $action_block = DifferentialBlockHeraldAction::ACTIONCONST; 134 135 135 136 $blocking_effect = null; 136 137 foreach ($effects as $effect) { 137 - if ($effect->getAction() == HeraldAdapter::ACTION_BLOCK) { 138 + if ($effect->getAction() == $action_block) { 138 139 $blocking_effect = $effect; 139 140 break; 140 141 }
+56
src/applications/differential/herald/DifferentialBlockHeraldAction.php
··· 1 + <?php 2 + 3 + final class DifferentialBlockHeraldAction 4 + extends HeraldAction { 5 + 6 + const ACTIONCONST = 'differential.block'; 7 + 8 + const DO_BLOCK = 'do.block'; 9 + 10 + public function getHeraldActionName() { 11 + return pht('Block diff with message'); 12 + } 13 + 14 + public function getActionGroupKey() { 15 + return HeraldApplicationActionGroup::ACTIONGROUPKEY; 16 + } 17 + 18 + public function supportsObject($object) { 19 + return ($object instanceof DifferentialDiff); 20 + } 21 + 22 + public function supportsRuleType($rule_type) { 23 + return ($rule_type != HeraldRuleTypeConfig::RULE_TYPE_PERSONAL); 24 + } 25 + 26 + public function applyEffect($object, HeraldEffect $effect) { 27 + // This rule intentionally has no direct effect: the caller handles it 28 + // after executing Herald. 29 + $this->logEffect(self::DO_BLOCK); 30 + } 31 + 32 + public function getHeraldActionStandardType() { 33 + return self::STANDARD_TEXT; 34 + } 35 + 36 + public function renderActionDescription($value) { 37 + return pht('Block diff with message: %s', $value); 38 + } 39 + 40 + protected function getActionEffectMap() { 41 + return array( 42 + self::DO_BLOCK => array( 43 + 'icon' => 'fa-stop', 44 + 'color' => 'red', 45 + 'name' => pht('Blocked Diff'), 46 + ), 47 + ); 48 + } 49 + 50 + protected function renderActionEffectDescription($type, $data) { 51 + switch ($type) { 52 + case self::DO_ADD_AUDITORS: 53 + return pht('Blocked diff.'); 54 + } 55 + } 56 + }
-39
src/applications/differential/herald/HeraldDifferentialDiffAdapter.php
··· 63 63 return pht('New Diff'); 64 64 } 65 65 66 - public function getActionNameMap($rule_type) { 67 - return array( 68 - self::ACTION_BLOCK => pht('Block diff with message'), 69 - ) + parent::getActionNameMap($rule_type); 70 - } 71 - 72 - public function getActions($rule_type) { 73 - switch ($rule_type) { 74 - case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL: 75 - return array_merge( 76 - array( 77 - self::ACTION_BLOCK, 78 - ), 79 - parent::getActions($rule_type)); 80 - } 81 - } 82 - 83 - public function applyHeraldEffects(array $effects) { 84 - assert_instances_of($effects, 'HeraldEffect'); 85 - 86 - $result = array(); 87 - foreach ($effects as $effect) { 88 - $action = $effect->getAction(); 89 - switch ($action) { 90 - case self::ACTION_BLOCK: 91 - $result[] = new HeraldApplyTranscript( 92 - $effect, 93 - true, 94 - pht('Blocked diff.')); 95 - break; 96 - default: 97 - $result[] = $this->applyStandardEffect($effect); 98 - break; 99 - } 100 - } 101 - 102 - return $result; 103 - } 104 - 105 66 }
+3 -1
src/applications/diffusion/engine/DiffusionCommitHookEngine.php
··· 325 325 $this->emailPHIDs[$email_phid] = $email_phid; 326 326 } 327 327 328 + $block_action = DiffusionBlockHeraldAction::ACTIONCONST; 329 + 328 330 if ($blocking_effect === null) { 329 331 foreach ($effects as $effect) { 330 - if ($effect->getAction() == HeraldAdapter::ACTION_BLOCK) { 332 + if ($effect->getAction() == $block_action) { 331 333 $blocking_effect = $effect; 332 334 $blocked_update = $update; 333 335 break;
+56
src/applications/diffusion/herald/DiffusionBlockHeraldAction.php
··· 1 + <?php 2 + 3 + final class DiffusionBlockHeraldAction 4 + extends HeraldAction { 5 + 6 + const ACTIONCONST = 'diffusion.block'; 7 + 8 + const DO_BLOCK = 'do.block'; 9 + 10 + public function getHeraldActionName() { 11 + return pht('Block push with message'); 12 + } 13 + 14 + public function getActionGroupKey() { 15 + return HeraldApplicationActionGroup::ACTIONGROUPKEY; 16 + } 17 + 18 + public function supportsObject($object) { 19 + return ($object instanceof PhabricatorRepositoryPushLog); 20 + } 21 + 22 + public function supportsRuleType($rule_type) { 23 + return ($rule_type != HeraldRuleTypeConfig::RULE_TYPE_PERSONAL); 24 + } 25 + 26 + public function applyEffect($object, HeraldEffect $effect) { 27 + // This rule intentionally has no direct effect: the caller handles it 28 + // after executing Herald. 29 + $this->logEffect(self::DO_BLOCK); 30 + } 31 + 32 + public function getHeraldActionStandardType() { 33 + return self::STANDARD_TEXT; 34 + } 35 + 36 + public function renderActionDescription($value) { 37 + return pht('Block push with message: %s', $value); 38 + } 39 + 40 + protected function getActionEffectMap() { 41 + return array( 42 + self::DO_BLOCK => array( 43 + 'icon' => 'fa-stop', 44 + 'color' => 'red', 45 + 'name' => pht('Blocked Push'), 46 + ), 47 + ); 48 + } 49 + 50 + protected function renderActionEffectDescription($type, $data) { 51 + switch ($type) { 52 + case self::DO_ADD_AUDITORS: 53 + return pht('Blocked push.'); 54 + } 55 + } 56 + }
-39
src/applications/diffusion/herald/HeraldPreCommitAdapter.php
··· 73 73 $this->hookEngine->getRepository()->getProjectPHIDs()); 74 74 } 75 75 76 - public function getActions($rule_type) { 77 - switch ($rule_type) { 78 - case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL: 79 - case HeraldRuleTypeConfig::RULE_TYPE_OBJECT: 80 - return array_merge( 81 - array( 82 - self::ACTION_BLOCK, 83 - ), 84 - parent::getActions($rule_type)); 85 - case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL: 86 - return array_merge( 87 - array( 88 - ), 89 - parent::getActions($rule_type)); 90 - } 91 - } 92 - 93 - public function applyHeraldEffects(array $effects) { 94 - assert_instances_of($effects, 'HeraldEffect'); 95 - 96 - $result = array(); 97 - foreach ($effects as $effect) { 98 - $action = $effect->getAction(); 99 - switch ($action) { 100 - case self::ACTION_BLOCK: 101 - $result[] = new HeraldApplyTranscript( 102 - $effect, 103 - true, 104 - pht('Blocked push.')); 105 - break; 106 - default: 107 - $result[] = $this->applyStandardEffect($effect); 108 - break; 109 - } 110 - } 111 - 112 - return $result; 113 - } 114 - 115 76 }
+23
src/applications/herald/action/HeraldAction.php
··· 8 8 9 9 const STANDARD_NONE = 'standard.none'; 10 10 const STANDARD_PHID_LIST = 'standard.phid.list'; 11 + const STANDARD_TEXT = 'standard.text'; 11 12 12 13 const DO_STANDARD_EMPTY = 'do.standard.empty'; 13 14 const DO_STANDARD_NO_EFFECT = 'do.standard.no-effect'; 14 15 const DO_STANDARD_INVALID = 'do.standard.invalid'; 15 16 const DO_STANDARD_UNLOADABLE = 'do.standard.unloadable'; 16 17 const DO_STANDARD_PERMISSION = 'do.standard.permission'; 18 + const DO_STANDARD_INVALID_ACTION = 'do.standard.invalid-action'; 19 + const DO_STANDARD_WRONG_RULE_TYPE = 'do.standard.wrong-rule-type'; 17 20 18 21 abstract public function getHeraldActionName(); 19 22 abstract public function supportsObject($object); ··· 48 51 switch ($this->getHeraldActionStandardType()) { 49 52 case self::STANDARD_NONE: 50 53 return new HeraldEmptyFieldValue(); 54 + case self::STANDARD_TEXT: 55 + return new HeraldTextFieldValue(); 51 56 case self::STANDARD_PHID_LIST: 52 57 $tokenizer = id(new HeraldTokenizerFieldValue()) 53 58 ->setKey($this->getHeraldActionName()) ··· 324 329 'color' => 'red', 325 330 'name' => pht('No Permission'), 326 331 ), 332 + self::DO_STANDARD_INVALID_ACTION => array( 333 + 'icon' => 'fa-ban', 334 + 'color' => 'red', 335 + 'name' => pht('Invalid Action'), 336 + ), 337 + self::DO_STANDARD_WRONG_RULE_TYPE => array( 338 + 'icon' => 'fa-ban', 339 + 'color' => 'red', 340 + 'name' => pht('Wrong Rule Type'), 341 + ), 327 342 ); 328 343 } 329 344 ··· 357 372 '%s target(s) do not have permission to see this object: %s.', 358 373 new PhutilNumber(count($data)), 359 374 $this->renderHandleList($data)); 375 + case self::DO_STANDARD_INVALID_ACTION: 376 + return pht( 377 + 'No implementation is available for rule "%s".', 378 + $data); 379 + case self::DO_STANDARD_WRONG_RULE_TYPE: 380 + return pht( 381 + 'This action does not support rules of type "%s".', 382 + $data); 360 383 } 361 384 362 385 return null;
+38 -150
src/applications/herald/adapter/HeraldAdapter.php
··· 26 26 const CONDITION_IS_TRUE = 'true'; 27 27 const CONDITION_IS_FALSE = 'false'; 28 28 29 - const ACTION_BLOCK = 'block'; 30 - 31 29 private $contentSource; 32 30 private $isNewObject; 33 31 private $applicationEmail; 34 - private $customActions = null; 35 32 private $queuedTransactions = array(); 36 33 private $emailPHIDs = array(); 37 34 private $forcedEmailPHIDs = array(); ··· 55 52 return $this; 56 53 } 57 54 58 - public function getCustomActions() { 59 - if ($this->customActions === null) { 60 - $custom_actions = id(new PhutilSymbolLoader()) 61 - ->setAncestorClass('HeraldCustomAction') 62 - ->loadObjects(); 63 - 64 - foreach ($custom_actions as $key => $object) { 65 - if (!$object->appliesToAdapter($this)) { 66 - unset($custom_actions[$key]); 67 - } 68 - } 69 - 70 - $this->customActions = array(); 71 - foreach ($custom_actions as $action) { 72 - $key = $action->getActionKey(); 73 - 74 - if (array_key_exists($key, $this->customActions)) { 75 - throw new Exception( 76 - pht( 77 - "More than one Herald custom action implementation ". 78 - "handles the action key: '%s'.", 79 - $key)); 80 - } 81 - 82 - $this->customActions[$key] = $action; 83 - } 84 - } 85 - 86 - return $this->customActions; 87 - } 88 - 89 55 public function setContentSource(PhabricatorContentSource $content_source) { 90 56 $this->contentSource = $content_source; 91 57 return $this; ··· 143 109 } 144 110 145 111 return $result; 146 - } 147 - 148 - protected function handleCustomHeraldEffect(HeraldEffect $effect) { 149 - $custom_action = idx($this->getCustomActions(), $effect->getAction()); 150 - 151 - if ($custom_action !== null) { 152 - return $custom_action->applyEffect( 153 - $this, 154 - $this->getObject(), 155 - $effect); 156 - } 157 - 158 - return null; 159 112 } 160 113 161 114 public function isAvailableToUser(PhabricatorUser $viewer) { ··· 654 607 return $this->actionMap; 655 608 } 656 609 610 + private function requireActionImplementation($action_key) { 611 + $action = $this->getActionImplementation($action_key); 612 + 613 + if (!$action) { 614 + throw new Exception( 615 + pht( 616 + 'No action with key "%s" is available to Herald adapter "%s".', 617 + $action_key, 618 + get_class($this))); 619 + } 620 + 621 + return $action; 622 + } 623 + 657 624 private function getActionsForRuleType($rule_type) { 658 625 $actions = $this->getActionImplementationMap(); 659 626 ··· 681 648 } 682 649 683 650 return $action->getActionGroupKey(); 684 - } 685 - 686 - public function getCustomActionsForRuleType($rule_type) { 687 - $results = array(); 688 - foreach ($this->getCustomActions() as $custom_action) { 689 - if ($custom_action->appliesToRuleType($rule_type)) { 690 - $results[] = $custom_action; 691 - } 692 - } 693 - return $results; 694 651 } 695 652 696 653 public function getActions($rule_type) { 697 - $custom_actions = $this->getCustomActionsForRuleType($rule_type); 698 - $custom_actions = mpull($custom_actions, 'getActionKey'); 699 - 700 - $actions = $custom_actions; 701 - 654 + $actions = array(); 702 655 foreach ($this->getActionsForRuleType($rule_type) as $key => $action) { 703 656 $actions[] = $key; 704 657 } ··· 707 660 } 708 661 709 662 public function getActionNameMap($rule_type) { 710 - switch ($rule_type) { 711 - case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL: 712 - case HeraldRuleTypeConfig::RULE_TYPE_OBJECT: 713 - $standard = array( 714 - self::ACTION_BLOCK => pht('Block change with message'), 715 - ); 716 - break; 717 - case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL: 718 - $standard = array( 719 - ); 720 - break; 721 - default: 722 - throw new Exception(pht("Unknown rule type '%s'!", $rule_type)); 723 - } 724 - 725 - $custom_actions = $this->getCustomActionsForRuleType($rule_type); 726 - $standard += mpull($custom_actions, 'getActionName', 'getActionKey'); 727 - 663 + $map = array(); 728 664 foreach ($this->getActionsForRuleType($rule_type) as $key => $action) { 729 - $standard[$key] = $action->getHeraldActionName(); 665 + $map[$key] = $action->getHeraldActionName(); 730 666 } 731 667 732 - return $standard; 668 + return $map; 733 669 } 734 670 735 671 public function willSaveAction( 736 672 HeraldRule $rule, 737 673 HeraldActionRecord $action) { 738 674 739 - $impl = $this->getActionImplementation($action->getAction()); 740 - if ($impl) { 741 - $target = $action->getTarget(); 742 - $target = $impl->willSaveActionValue($target); 743 - $action->setTarget($target); 744 - return; 745 - } 746 - 675 + $impl = $this->requireActionImplementation($action->getAction()); 747 676 $target = $action->getTarget(); 748 - if (is_array($target)) { 749 - $target = array_keys($target); 750 - } 751 - 752 - $author_phid = $rule->getAuthorPHID(); 753 - 754 - $rule_type = $rule->getRuleType(); 755 - if ($rule_type == HeraldRuleTypeConfig::RULE_TYPE_PERSONAL) { 756 - switch ($action->getAction()) { 757 - case self::ACTION_BLOCK: 758 - break; 759 - default: 760 - throw new HeraldInvalidActionException( 761 - pht( 762 - 'Unrecognized action type "%s"!', 763 - $action->getAction())); 764 - } 765 - } 677 + $target = $impl->willSaveActionValue($target); 766 678 767 679 $action->setTarget($target); 768 680 } ··· 778 690 } 779 691 780 692 public function getValueTypeForAction($action, $rule_type) { 781 - $impl = $this->getActionImplementation($action); 782 - if ($impl) { 783 - return $impl->getHeraldActionValueType(); 784 - } 785 - 786 - $is_personal = ($rule_type == HeraldRuleTypeConfig::RULE_TYPE_PERSONAL); 787 - 788 - if (!$is_personal) { 789 - switch ($action) { 790 - case self::ACTION_BLOCK: 791 - return new HeraldTextFieldValue(); 792 - } 793 - } 794 - 795 - $custom_action = idx($this->getCustomActions(), $action); 796 - if ($custom_action !== null) { 797 - return $custom_action->getActionType(); 798 - } 799 - 800 - throw new Exception(pht("Unknown or invalid action '%s'.", $action)); 693 + $impl = $this->requireActionImplementation($action); 694 + return $impl->getHeraldActionValueType(); 801 695 } 802 696 803 697 private function buildTokenizerFieldValue( ··· 1113 1007 $rule_type = $effect->getRule()->getRuleType(); 1114 1008 1115 1009 $impl = $this->getActionImplementation($action); 1116 - if ($impl) { 1117 - if ($impl->supportsRuleType($rule_type)) { 1118 - $impl->applyEffect($this->getObject(), $effect); 1119 - return $impl->getApplyTranscript($effect); 1120 - } 1121 - } 1122 - 1123 - $supported = $this->getActions($rule_type); 1124 - $supported = array_fuse($supported); 1125 - if (empty($supported[$action])) { 1010 + if (!$impl) { 1126 1011 return new HeraldApplyTranscript( 1127 1012 $effect, 1128 1013 false, 1129 - pht( 1130 - 'Adapter "%s" does not support action "%s" for rule type "%s".', 1131 - get_class($this), 1132 - $action, 1133 - $rule_type)); 1014 + array( 1015 + array( 1016 + HeraldAction::DO_STANDARD_INVALID_ACTION, 1017 + $action, 1018 + ), 1019 + )); 1134 1020 } 1135 1021 1136 - $result = $this->handleCustomHeraldEffect($effect); 1137 - 1138 - if (!$result) { 1022 + if (!$impl->supportsRuleType($rule_type)) { 1139 1023 return new HeraldApplyTranscript( 1140 1024 $effect, 1141 1025 false, 1142 - pht( 1143 - 'No custom action exists to handle rule action "%s".', 1144 - $action)); 1026 + array( 1027 + array( 1028 + HeraldAction::DO_STANDARD_WRONG_RULE_TYPE, 1029 + $rule_type, 1030 + ), 1031 + )); 1145 1032 } 1146 1033 1147 - return $result; 1034 + $impl->applyEffect($this->getObject(), $effect); 1035 + return $impl->getApplyTranscript($effect); 1148 1036 } 1149 1037 1150 1038 public function loadEdgePHIDs($type) {
-20
src/applications/herald/extension/HeraldCustomAction.php
··· 1 - <?php 2 - 3 - abstract class HeraldCustomAction extends Phobject { 4 - 5 - abstract public function appliesToAdapter(HeraldAdapter $adapter); 6 - 7 - abstract public function appliesToRuleType($rule_type); 8 - 9 - abstract public function getActionKey(); 10 - 11 - abstract public function getActionName(); 12 - 13 - abstract public function getActionType(); 14 - 15 - abstract public function applyEffect( 16 - HeraldAdapter $adapter, 17 - $object, 18 - HeraldEffect $effect); 19 - 20 - }