1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-09 14:21:02 +01:00

Allow Herald Adapters to choose applicable rule types (global, personal, etc).

Summary: Ref T4264. Lays the groundwork for new "Object" rule types. Prevents personal "Hook" rules, which don't make any sense.

Test Plan: Created new Maniphest (global/personal available) and Ref Hook (global only) rules.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4264

Differential Revision: https://secure.phabricator.com/D7852
This commit is contained in:
epriestley 2013-12-30 16:48:07 -08:00
parent db3228844a
commit 472b0f983e
9 changed files with 106 additions and 12 deletions

View file

@ -41,6 +41,17 @@ final class HeraldPreCommitContentAdapter extends HeraldAdapter {
"Hook rules can block changes.");
}
public function supportsRuleType($rule_type) {
switch ($rule_type) {
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
return true;
case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
case HeraldRuleTypeConfig::RULE_TYPE_OBJECT:
default:
return false;
}
}
public function getFieldNameMap() {
return array(
) + parent::getFieldNameMap();

View file

@ -44,6 +44,17 @@ final class HeraldPreCommitRefAdapter extends HeraldAdapter {
"Hook rules can block changes.");
}
public function supportsRuleType($rule_type) {
switch ($rule_type) {
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
return true;
case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
case HeraldRuleTypeConfig::RULE_TYPE_OBJECT:
default:
return false;
}
}
public function getFieldNameMap() {
return array(
self::FIELD_REF_TYPE => pht('Ref type'),

View file

@ -140,6 +140,10 @@ abstract class HeraldAdapter {
abstract public function getAdapterApplicationClass();
abstract public function getObject();
public function supportsRuleType($rule_type) {
return false;
}
public function getAdapterSortKey() {
return sprintf(
'%08d%s',

View file

@ -49,6 +49,17 @@ final class HeraldCommitAdapter extends HeraldAdapter {
"and run build plans.");
}
public function supportsRuleType($rule_type) {
switch ($rule_type) {
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
return true;
case HeraldRuleTypeConfig::RULE_TYPE_OBJECT:
default:
return false;
}
}
public function getFieldNameMap() {
return array(
self::FIELD_NEED_AUDIT_FOR_PACKAGE =>

View file

@ -43,6 +43,17 @@ final class HeraldDifferentialRevisionAdapter extends HeraldAdapter {
"and run build plans.");
}
public function supportsRuleType($rule_type) {
switch ($rule_type) {
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
return true;
case HeraldRuleTypeConfig::RULE_TYPE_OBJECT:
default:
return false;
}
}
public function getFields() {
return array_merge(
array(

View file

@ -19,6 +19,17 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter {
'React to tasks being created or updated.');
}
public function supportsRuleType($rule_type) {
switch ($rule_type) {
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
return true;
case HeraldRuleTypeConfig::RULE_TYPE_OBJECT:
default:
return false;
}
}
public function setTask(ManiphestTask $task) {
$this->task = $task;
return $this;

View file

@ -41,6 +41,17 @@ final class HeraldPholioMockAdapter extends HeraldAdapter {
return pht('Pholio Mocks');
}
public function supportsRuleType($rule_type) {
switch ($rule_type) {
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
return true;
case HeraldRuleTypeConfig::RULE_TYPE_OBJECT:
default:
return false;
}
}
public function getFields() {
return array_merge(
array(

View file

@ -53,17 +53,13 @@ final class HeraldNewController extends HeraldController {
->setUser($user)
->setAction($this->getApplicationURI('new/'));
switch ($step) {
case 0:
default:
$content_types = $this->renderContentTypeControl(
$content_type_map,
$e_type);
$rule_types = $this->renderRuleTypeControl(
$rule_type_map,
$e_rule);
switch ($step) {
case 0:
default:
$form
->addHiddenInput('step', 1)
->appendChild($content_types);
@ -72,6 +68,10 @@ final class HeraldNewController extends HeraldController {
$cancel_uri = $this->getApplicationURI();
break;
case 1:
$rule_types = $this->renderRuleTypeControl(
$rule_type_map,
$e_rule);
$form
->addHiddenInput('content_type', $request->getStr('content_type'))
->addHiddenInput('step', 2)
@ -185,14 +185,31 @@ final class HeraldNewController extends HeraldController {
->setValue($request->getStr('rule_type'))
->setError($e_rule);
$adapter = HeraldAdapter::getAdapterForContentType(
$request->getStr('content_type'));
foreach ($rule_type_map as $value => $name) {
$caption = idx($captions, $value);
$disabled = ($value == HeraldRuleTypeConfig::RULE_TYPE_GLOBAL) &&
(!$can_global);
if (!$adapter->supportsRuleType($value)) {
$disabled = true;
$caption = array(
$caption,
"\n\n",
phutil_tag(
'em',
array(),
pht(
'This rule type is not supported by the selected content type.')),
);
}
$radio->addButton(
$value,
$name,
idx($captions, $value),
phutil_escape_html_newlines($caption),
$disabled ? 'disabled' : null,
$disabled);
}

View file

@ -59,9 +59,16 @@ final class HeraldRuleController extends HeraldController {
$local_version = id(new HeraldRule())->getConfigVersion();
if ($rule->getConfigVersion() > $local_version) {
throw new Exception(
pht(
"This rule was created with a newer version of Herald. You can not ".
"view or edit it in this older version. Upgrade your Phabricator ".
"deployment.");
"deployment."));
}
if (!$adapter->supportsRuleType($rule->getRuleType())) {
throw new Exception(
pht(
"This rule's content type does not support the selected rule type."));
}
// Upgrade rule version to our version, since we might add newly-defined