mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-10 05:48:30 +01:00
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
This commit is contained in:
parent
b435c0297e
commit
477d4e9db1
7 changed files with 53 additions and 3 deletions
|
@ -19,6 +19,7 @@ abstract class HeraldAdapter {
|
||||||
const FIELD_RULE = 'rule';
|
const FIELD_RULE = 'rule';
|
||||||
const FIELD_AFFECTED_PACKAGE = 'affected-package';
|
const FIELD_AFFECTED_PACKAGE = 'affected-package';
|
||||||
const FIELD_AFFECTED_PACKAGE_OWNER = 'affected-package-owner';
|
const FIELD_AFFECTED_PACKAGE_OWNER = 'affected-package-owner';
|
||||||
|
const FIELD_CONTENT_SOURCE = 'contentsource';
|
||||||
|
|
||||||
const CONDITION_CONTAINS = 'contains';
|
const CONDITION_CONTAINS = 'contains';
|
||||||
const CONDITION_NOT_CONTAINS = '!contains';
|
const CONDITION_NOT_CONTAINS = '!contains';
|
||||||
|
@ -55,6 +56,17 @@ abstract class HeraldAdapter {
|
||||||
const VALUE_OWNERS_PACKAGE = 'package';
|
const VALUE_OWNERS_PACKAGE = 'package';
|
||||||
const VALUE_PROJECT = 'project';
|
const VALUE_PROJECT = 'project';
|
||||||
const VALUE_FLAG_COLOR = 'flagcolor';
|
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 getPHID();
|
||||||
abstract public function getHeraldName();
|
abstract public function getHeraldName();
|
||||||
|
@ -63,6 +75,8 @@ abstract class HeraldAdapter {
|
||||||
switch ($field_name) {
|
switch ($field_name) {
|
||||||
case self::FIELD_RULE:
|
case self::FIELD_RULE:
|
||||||
return null;
|
return null;
|
||||||
|
case self::FIELD_CONTENT_SOURCE:
|
||||||
|
return $this->getContentSource()->getSource();
|
||||||
default:
|
default:
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
"Unknown field '{$field_name}'!");
|
"Unknown field '{$field_name}'!");
|
||||||
|
@ -108,6 +122,7 @@ abstract class HeraldAdapter {
|
||||||
self::FIELD_AFFECTED_PACKAGE => pht('Any affected package'),
|
self::FIELD_AFFECTED_PACKAGE => pht('Any affected package'),
|
||||||
self::FIELD_AFFECTED_PACKAGE_OWNER =>
|
self::FIELD_AFFECTED_PACKAGE_OWNER =>
|
||||||
pht("Any affected package's 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_ANY,
|
||||||
self::CONDITION_INCLUDE_NONE,
|
self::CONDITION_INCLUDE_NONE,
|
||||||
);
|
);
|
||||||
|
case self::FIELD_CONTENT_SOURCE:
|
||||||
|
return array(
|
||||||
|
self::CONDITION_IS,
|
||||||
|
self::CONDITION_IS_NOT,
|
||||||
|
);
|
||||||
default:
|
default:
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
"This adapter does not define conditions for field '{$field}'!");
|
"This adapter does not define conditions for field '{$field}'!");
|
||||||
|
@ -491,11 +511,18 @@ abstract class HeraldAdapter {
|
||||||
switch ($condition) {
|
switch ($condition) {
|
||||||
case self::CONDITION_CONTAINS:
|
case self::CONDITION_CONTAINS:
|
||||||
case self::CONDITION_NOT_CONTAINS:
|
case self::CONDITION_NOT_CONTAINS:
|
||||||
case self::CONDITION_IS:
|
|
||||||
case self::CONDITION_IS_NOT:
|
|
||||||
case self::CONDITION_REGEXP:
|
case self::CONDITION_REGEXP:
|
||||||
case self::CONDITION_REGEXP_PAIR:
|
case self::CONDITION_REGEXP_PAIR:
|
||||||
return self::VALUE_TEXT;
|
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_ANY:
|
||||||
case self::CONDITION_IS_NOT_ANY:
|
case self::CONDITION_IS_NOT_ANY:
|
||||||
switch ($field) {
|
switch ($field) {
|
||||||
|
|
|
@ -34,6 +34,7 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter {
|
||||||
self::FIELD_BODY,
|
self::FIELD_BODY,
|
||||||
self::FIELD_AUTHOR,
|
self::FIELD_AUTHOR,
|
||||||
self::FIELD_CC,
|
self::FIELD_CC,
|
||||||
|
self::FIELD_CONTENT_SOURCE,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -413,6 +413,8 @@ final class HeraldRuleController extends HeraldController {
|
||||||
'rules' => $all_rules,
|
'rules' => $all_rules,
|
||||||
'colors' => PhabricatorFlagColor::getColorNameMap(),
|
'colors' => PhabricatorFlagColor::getColorNameMap(),
|
||||||
'defaultColor' => PhabricatorFlagColor::COLOR_BLUE,
|
'defaultColor' => PhabricatorFlagColor::COLOR_BLUE,
|
||||||
|
'contentSources' => PhabricatorContentSource::getSourceNameMap(),
|
||||||
|
'defaultSource' => PhabricatorContentSource::SOURCE_WEB
|
||||||
),
|
),
|
||||||
'author' => array($rule->getAuthorPHID() =>
|
'author' => array($rule->getAuthorPHID() =>
|
||||||
$handles[$rule->getAuthorPHID()]->getName()),
|
$handles[$rule->getAuthorPHID()]->getName()),
|
||||||
|
|
|
@ -13,7 +13,7 @@ final class HeraldRule extends HeraldDAO
|
||||||
protected $repetitionPolicy;
|
protected $repetitionPolicy;
|
||||||
protected $ruleType;
|
protected $ruleType;
|
||||||
|
|
||||||
protected $configVersion = 9;
|
protected $configVersion = 10;
|
||||||
|
|
||||||
private $ruleApplied = self::ATTACHABLE; // phids for which this rule has been applied
|
private $ruleApplied = self::ATTACHABLE; // phids for which this rule has been applied
|
||||||
private $validAuthor = self::ATTACHABLE;
|
private $validAuthor = self::ATTACHABLE;
|
||||||
|
|
|
@ -53,6 +53,19 @@ final class PhabricatorContentSource {
|
||||||
array());
|
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() {
|
public function serialize() {
|
||||||
return json_encode(array(
|
return json_encode(array(
|
||||||
'source' => $this->getSource(),
|
'source' => $this->getSource(),
|
||||||
|
|
|
@ -1496,6 +1496,7 @@ abstract class PhabricatorApplicationTransactionEditor
|
||||||
array $xactions) {
|
array $xactions) {
|
||||||
|
|
||||||
$adapter = $this->buildHeraldAdapter($object, $xactions);
|
$adapter = $this->buildHeraldAdapter($object, $xactions);
|
||||||
|
$adapter->setContentSource($this->getContentSource());
|
||||||
$xscript = HeraldEngine::loadAndApplyRules($adapter);
|
$xscript = HeraldEngine::loadAndApplyRules($adapter);
|
||||||
|
|
||||||
$this->setHeraldAdapter($adapter);
|
$this->setHeraldAdapter($adapter);
|
||||||
|
|
|
@ -225,6 +225,12 @@ JX.install('HeraldRuleEditor', {
|
||||||
get_fn = JX.bag;
|
get_fn = JX.bag;
|
||||||
set_fn = JX.bag;
|
set_fn = JX.bag;
|
||||||
break;
|
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':
|
case 'flagcolor':
|
||||||
input = this._renderSelect(this._config.template.colors);
|
input = this._renderSelect(this._config.template.colors);
|
||||||
get_fn = function() { return input.value; };
|
get_fn = function() { return input.value; };
|
||||||
|
|
Loading…
Add table
Reference in a new issue