From 477d4e9db19a7abce3905ad5f1253088400968c8 Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Thu, 26 Sep 2013 14:20:56 -0700 Subject: [PATCH] Herald - add support for "content source" conditions Summary: ...and deploy on Maniphest. Ref T1638. Test Plan: created a herald rule to be cc'd for tasks created via web. made a task via web and another via email and was cc'd appropriately. edited the herald to be cc'd for tasks created via not web. made 2 tasks again and got cc'd appropriately Reviewers: epriestley Reviewed By: epriestley CC: Korvin, aran Maniphest Tasks: T1638 Differential Revision: https://secure.phabricator.com/D7145 --- .../herald/adapter/HeraldAdapter.php | 31 +++++++++++++++++-- .../adapter/HeraldManiphestTaskAdapter.php | 1 + .../controller/HeraldRuleController.php | 2 ++ .../herald/storage/HeraldRule.php | 2 +- .../PhabricatorContentSource.php | 13 ++++++++ ...habricatorApplicationTransactionEditor.php | 1 + .../js/application/herald/HeraldRuleEditor.js | 6 ++++ 7 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/applications/herald/adapter/HeraldAdapter.php b/src/applications/herald/adapter/HeraldAdapter.php index 0f95fc2954..641ca8191c 100644 --- a/src/applications/herald/adapter/HeraldAdapter.php +++ b/src/applications/herald/adapter/HeraldAdapter.php @@ -19,6 +19,7 @@ abstract class HeraldAdapter { const FIELD_RULE = 'rule'; const FIELD_AFFECTED_PACKAGE = 'affected-package'; const FIELD_AFFECTED_PACKAGE_OWNER = 'affected-package-owner'; + const FIELD_CONTENT_SOURCE = 'contentsource'; const CONDITION_CONTAINS = 'contains'; const CONDITION_NOT_CONTAINS = '!contains'; @@ -55,6 +56,17 @@ abstract class HeraldAdapter { const VALUE_OWNERS_PACKAGE = 'package'; const VALUE_PROJECT = 'project'; const VALUE_FLAG_COLOR = 'flagcolor'; + const VALUE_CONTENT_SOURCE = 'contentsource'; + + private $contentSource; + + public function setContentSource(PhabricatorContentSource $content_source) { + $this->contentSource = $content_source; + return $this; + } + public function getContentSource() { + return $this->contentSource; + } abstract public function getPHID(); abstract public function getHeraldName(); @@ -63,6 +75,8 @@ abstract class HeraldAdapter { switch ($field_name) { case self::FIELD_RULE: return null; + case self::FIELD_CONTENT_SOURCE: + return $this->getContentSource()->getSource(); default: throw new Exception( "Unknown field '{$field_name}'!"); @@ -108,6 +122,7 @@ abstract class HeraldAdapter { self::FIELD_AFFECTED_PACKAGE => pht('Any affected package'), self::FIELD_AFFECTED_PACKAGE_OWNER => pht("Any affected package's owner"), + self:: FIELD_CONTENT_SOURCE => pht('Content Source') ); } @@ -186,6 +201,11 @@ abstract class HeraldAdapter { self::CONDITION_INCLUDE_ANY, self::CONDITION_INCLUDE_NONE, ); + case self::FIELD_CONTENT_SOURCE: + return array( + self::CONDITION_IS, + self::CONDITION_IS_NOT, + ); default: throw new Exception( "This adapter does not define conditions for field '{$field}'!"); @@ -491,11 +511,18 @@ abstract class HeraldAdapter { switch ($condition) { case self::CONDITION_CONTAINS: case self::CONDITION_NOT_CONTAINS: - case self::CONDITION_IS: - case self::CONDITION_IS_NOT: case self::CONDITION_REGEXP: case self::CONDITION_REGEXP_PAIR: return self::VALUE_TEXT; + case self::CONDITION_IS: + case self::CONDITION_IS_NOT: + switch ($field) { + case self::FIELD_CONTENT_SOURCE: + return self::VALUE_CONTENT_SOURCE; + default: + return self::VALUE_TEXT; + } + break; case self::CONDITION_IS_ANY: case self::CONDITION_IS_NOT_ANY: switch ($field) { diff --git a/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php b/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php index 5f0c83440e..cd275afd00 100644 --- a/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php +++ b/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php @@ -34,6 +34,7 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter { self::FIELD_BODY, self::FIELD_AUTHOR, self::FIELD_CC, + self::FIELD_CONTENT_SOURCE, ); } diff --git a/src/applications/herald/controller/HeraldRuleController.php b/src/applications/herald/controller/HeraldRuleController.php index 05ea4965a4..c3868ebbd5 100644 --- a/src/applications/herald/controller/HeraldRuleController.php +++ b/src/applications/herald/controller/HeraldRuleController.php @@ -413,6 +413,8 @@ final class HeraldRuleController extends HeraldController { 'rules' => $all_rules, 'colors' => PhabricatorFlagColor::getColorNameMap(), 'defaultColor' => PhabricatorFlagColor::COLOR_BLUE, + 'contentSources' => PhabricatorContentSource::getSourceNameMap(), + 'defaultSource' => PhabricatorContentSource::SOURCE_WEB ), 'author' => array($rule->getAuthorPHID() => $handles[$rule->getAuthorPHID()]->getName()), diff --git a/src/applications/herald/storage/HeraldRule.php b/src/applications/herald/storage/HeraldRule.php index 50c564370f..dc81e149f6 100644 --- a/src/applications/herald/storage/HeraldRule.php +++ b/src/applications/herald/storage/HeraldRule.php @@ -13,7 +13,7 @@ final class HeraldRule extends HeraldDAO protected $repetitionPolicy; protected $ruleType; - protected $configVersion = 9; + protected $configVersion = 10; private $ruleApplied = self::ATTACHABLE; // phids for which this rule has been applied private $validAuthor = self::ATTACHABLE; diff --git a/src/applications/metamta/contentsource/PhabricatorContentSource.php b/src/applications/metamta/contentsource/PhabricatorContentSource.php index 03208832a6..21d2caa0e4 100644 --- a/src/applications/metamta/contentsource/PhabricatorContentSource.php +++ b/src/applications/metamta/contentsource/PhabricatorContentSource.php @@ -53,6 +53,19 @@ final class PhabricatorContentSource { array()); } + public static function getSourceNameMap() { + return array( + self::SOURCE_WEB => pht('Web'), + self::SOURCE_EMAIL => pht('Email'), + self::SOURCE_CONDUIT => pht('Conduit'), + self::SOURCE_MOBILE => pht('Mobile'), + self::SOURCE_TABLET => pht('Tablet'), + self::SOURCE_FAX => pht('Fax'), + self::SOURCE_LEGACY => pht('Legacy'), + self::SOURCE_UNKNOWN => pht('Other'), + ); + } + public function serialize() { return json_encode(array( 'source' => $this->getSource(), diff --git a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php index c3b4bcb0fc..bffe93275b 100644 --- a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php +++ b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php @@ -1496,6 +1496,7 @@ abstract class PhabricatorApplicationTransactionEditor array $xactions) { $adapter = $this->buildHeraldAdapter($object, $xactions); + $adapter->setContentSource($this->getContentSource()); $xscript = HeraldEngine::loadAndApplyRules($adapter); $this->setHeraldAdapter($adapter); diff --git a/webroot/rsrc/js/application/herald/HeraldRuleEditor.js b/webroot/rsrc/js/application/herald/HeraldRuleEditor.js index f036e330c7..e3c9da86cb 100644 --- a/webroot/rsrc/js/application/herald/HeraldRuleEditor.js +++ b/webroot/rsrc/js/application/herald/HeraldRuleEditor.js @@ -225,6 +225,12 @@ JX.install('HeraldRuleEditor', { get_fn = JX.bag; set_fn = JX.bag; break; + case 'contentsource': + input = this._renderSelect(this._config.template.contentSources); + get_fn = function() { return input.value; }; + set_fn = function(v) { input.value = v; }; + set_fn(this._config.template.defaultSource); + break; case 'flagcolor': input = this._renderSelect(this._config.template.colors); get_fn = function() { return input.value; };