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

Support Herald rules for Herald rules

Summary:
Depends on D19399. Ref T13130. This adds basic support for writing Herald rules against Herald rules. See T13130 for a lot more detail.

This needs a bit more work to be useful: for example, there's no way to specify the rule type or subject, so you can't say "notify me when global rules are edited" or "notify me when Maniphest rules are edited". I'll add some fields for that in followup changes to actually solve the original use case.

Test Plan:
- Wrote Herald rules against Herald rules.
- Ran them by editing rules and in the test console.
- Verified they sent some mail with `bin/mail list-outbound`.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13130

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

+144
+4
src/__phutil_library_map__.php
··· 1485 1485 'HeraldRemarkupFieldValue' => 'applications/herald/value/HeraldRemarkupFieldValue.php', 1486 1486 'HeraldRemarkupRule' => 'applications/herald/remarkup/HeraldRemarkupRule.php', 1487 1487 'HeraldRule' => 'applications/herald/storage/HeraldRule.php', 1488 + 'HeraldRuleAdapter' => 'applications/herald/adapter/HeraldRuleAdapter.php', 1488 1489 'HeraldRuleController' => 'applications/herald/controller/HeraldRuleController.php', 1489 1490 'HeraldRuleDatasource' => 'applications/herald/typeahead/HeraldRuleDatasource.php', 1490 1491 'HeraldRuleEditor' => 'applications/herald/editor/HeraldRuleEditor.php', 1491 1492 'HeraldRuleListController' => 'applications/herald/controller/HeraldRuleListController.php', 1492 1493 'HeraldRulePHIDType' => 'applications/herald/phid/HeraldRulePHIDType.php', 1493 1494 'HeraldRuleQuery' => 'applications/herald/query/HeraldRuleQuery.php', 1495 + 'HeraldRuleReplyHandler' => 'applications/herald/mail/HeraldRuleReplyHandler.php', 1494 1496 'HeraldRuleSearchEngine' => 'applications/herald/query/HeraldRuleSearchEngine.php', 1495 1497 'HeraldRuleSerializer' => 'applications/herald/editor/HeraldRuleSerializer.php', 1496 1498 'HeraldRuleTestCase' => 'applications/herald/storage/__tests__/HeraldRuleTestCase.php', ··· 6918 6920 'PhabricatorDestructibleInterface', 6919 6921 'PhabricatorSubscribableInterface', 6920 6922 ), 6923 + 'HeraldRuleAdapter' => 'HeraldAdapter', 6921 6924 'HeraldRuleController' => 'HeraldController', 6922 6925 'HeraldRuleDatasource' => 'PhabricatorTypeaheadDatasource', 6923 6926 'HeraldRuleEditor' => 'PhabricatorApplicationTransactionEditor', 6924 6927 'HeraldRuleListController' => 'HeraldController', 6925 6928 'HeraldRulePHIDType' => 'PhabricatorPHIDType', 6926 6929 'HeraldRuleQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 6930 + 'HeraldRuleReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', 6927 6931 'HeraldRuleSearchEngine' => 'PhabricatorApplicationSearchEngine', 6928 6932 'HeraldRuleSerializer' => 'Phobject', 6929 6933 'HeraldRuleTestCase' => 'PhabricatorTestCase',
+74
src/applications/herald/adapter/HeraldRuleAdapter.php
··· 1 + <?php 2 + 3 + final class HeraldRuleAdapter extends HeraldAdapter { 4 + 5 + private $rule; 6 + 7 + protected function newObject() { 8 + return new HeraldRule(); 9 + } 10 + 11 + public function getAdapterApplicationClass() { 12 + return 'PhabricatorHeraldApplication'; 13 + } 14 + 15 + public function getAdapterContentDescription() { 16 + return pht('React to Herald rules being created or updated.'); 17 + } 18 + 19 + public function isTestAdapterForObject($object) { 20 + return ($object instanceof HeraldRule); 21 + } 22 + 23 + public function getAdapterTestDescription() { 24 + return pht( 25 + 'Test rules which run when another Herald rule is created or '. 26 + 'updated.'); 27 + } 28 + 29 + protected function initializeNewAdapter() { 30 + $this->rule = $this->newObject(); 31 + } 32 + 33 + public function supportsApplicationEmail() { 34 + return true; 35 + } 36 + 37 + public function supportsRuleType($rule_type) { 38 + switch ($rule_type) { 39 + case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL: 40 + case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL: 41 + return true; 42 + case HeraldRuleTypeConfig::RULE_TYPE_OBJECT: 43 + default: 44 + return false; 45 + } 46 + } 47 + 48 + public function setRule(HeraldRule $rule) { 49 + $this->rule = $rule; 50 + return $this; 51 + } 52 + 53 + public function getRule() { 54 + return $this->rule; 55 + } 56 + 57 + public function setObject($object) { 58 + $this->rule = $object; 59 + return $this; 60 + } 61 + 62 + public function getObject() { 63 + return $this->rule; 64 + } 65 + 66 + public function getAdapterContentName() { 67 + return pht('Herald Rules'); 68 + } 69 + 70 + public function getHeraldName() { 71 + return $this->getRule()->getMonogram(); 72 + } 73 + 74 + }
+50
src/applications/herald/editor/HeraldRuleEditor.php
··· 87 87 return; 88 88 } 89 89 90 + protected function shouldApplyHeraldRules( 91 + PhabricatorLiskDAO $object, 92 + array $xactions) { 93 + return true; 94 + } 95 + 96 + protected function buildHeraldAdapter( 97 + PhabricatorLiskDAO $object, 98 + array $xactions) { 99 + return id(new HeraldRuleAdapter()) 100 + ->setRule($object); 101 + } 102 + 103 + protected function shouldSendMail( 104 + PhabricatorLiskDAO $object, 105 + array $xactions) { 106 + return true; 107 + } 108 + 109 + protected function getMailTo(PhabricatorLiskDAO $object) { 110 + $phids = array(); 111 + 112 + $phids[] = $this->getActingAsPHID(); 113 + 114 + if ($object->isPersonalRule()) { 115 + $phids[] = $object->getAuthorPHID(); 116 + } 117 + 118 + return $phids; 119 + } 120 + 121 + protected function buildReplyHandler(PhabricatorLiskDAO $object) { 122 + return id(new HeraldRuleReplyHandler()) 123 + ->setMailReceiver($object); 124 + } 125 + 126 + protected function buildMailTemplate(PhabricatorLiskDAO $object) { 127 + $monogram = $object->getMonogram(); 128 + $name = $object->getName(); 129 + 130 + $subject = pht('%s: %s', $monogram, $name); 131 + 132 + return id(new PhabricatorMetaMTAMail()) 133 + ->setSubject($subject); 134 + } 135 + 136 + protected function getMailSubjectPrefix() { 137 + return pht('[Herald]'); 138 + } 139 + 90 140 }
+16
src/applications/herald/mail/HeraldRuleReplyHandler.php
··· 1 + <?php 2 + 3 + final class HeraldRuleReplyHandler 4 + extends PhabricatorApplicationTransactionReplyHandler { 5 + 6 + public function validateMailReceiver($mail_receiver) { 7 + if (!($mail_receiver instanceof HeraldRule)) { 8 + throw new Exception(pht('Mail receiver is not a %s!', 'HeraldRule')); 9 + } 10 + } 11 + 12 + public function getObjectPrefix() { 13 + return 'H'; 14 + } 15 + 16 + }