1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 06:42:42 +01:00

Replace the primary "Disabled/Enabled" Herald Rule filter with "Active/Inactive", considering author status

Summary:
Ref T13216. See PHI947. In Herald, Personal rules do not run if their author's account is disabled.

This isn't communicated very clearly in the UI, and the way the SearchEngine/Query are set up isn't great.

Define "active" as "rule will actually run", which specifically means "rule is enabled, and has a valid (non-disabled) author if it needs one".

Change the meaning of the "Active" default filter from "rule is enabled" to "rule is enabled, and has a valid author if it needs one".

Refine the status badge on the view controller to show this "invalid author" state.

Tweak the language for "Disable/Enable" to be more consistent -- we currently call it "disabled" in some cases and "archived" in others.

Test Plan:
  - Disabled a user account and saw their personal rules behave properly with the new filters/options/view controller.
  - Disabled/enabled a rule, saw consistent text.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13216

Differential Revision: https://secure.phabricator.com/D19805
This commit is contained in:
epriestley 2018-11-14 14:50:40 -08:00
parent bbd292b9b3
commit 8a8123c9db
4 changed files with 65 additions and 19 deletions

View file

@ -44,13 +44,13 @@ final class HeraldDisableController extends HeraldController {
} }
if ($is_disable) { if ($is_disable) {
$title = pht('Really archive this rule?'); $title = pht('Really disable this rule?');
$body = pht('This rule will no longer activate.'); $body = pht('This rule will no longer activate.');
$button = pht('Archive Rule'); $button = pht('Disable Rule');
} else { } else {
$title = pht('Really activate this rule?'); $title = pht('Really enable this rule?');
$body = pht('This rule will become active again.'); $body = pht('This rule will become active again.');
$button = pht('Activate Rule'); $button = pht('Enable Rule');
} }
$dialog = id(new AphrontDialogView()) $dialog = id(new AphrontDialogView())

View file

@ -14,6 +14,7 @@ final class HeraldRuleViewController extends HeraldController {
->setViewer($viewer) ->setViewer($viewer)
->withIDs(array($id)) ->withIDs(array($id))
->needConditionsAndActions(true) ->needConditionsAndActions(true)
->needValidateAuthors(true)
->executeOne(); ->executeOne();
if (!$rule) { if (!$rule) {
return new Aphront404Response(); return new Aphront404Response();
@ -26,15 +27,11 @@ final class HeraldRuleViewController extends HeraldController {
->setHeaderIcon('fa-bullhorn'); ->setHeaderIcon('fa-bullhorn');
if ($rule->getIsDisabled()) { if ($rule->getIsDisabled()) {
$header->setStatus( $header->setStatus('fa-ban', 'red', pht('Disabled'));
'fa-ban', } else if (!$rule->hasValidAuthor()) {
'red', $header->setStatus('fa-user', 'red', pht('Author Not Active'));
pht('Archived'));
} else { } else {
$header->setStatus( $header->setStatus('fa-check', 'bluegrey', pht('Active'));
'fa-check',
'bluegrey',
pht('Active'));
} }
$curtain = $this->buildCurtain($rule); $curtain = $this->buildCurtain($rule);
@ -90,16 +87,15 @@ final class HeraldRuleViewController extends HeraldController {
if ($rule->getIsDisabled()) { if ($rule->getIsDisabled()) {
$disable_uri = "disable/{$id}/enable/"; $disable_uri = "disable/{$id}/enable/";
$disable_icon = 'fa-check'; $disable_icon = 'fa-check';
$disable_name = pht('Activate Rule'); $disable_name = pht('Enable Rule');
} else { } else {
$disable_uri = "disable/{$id}/disable/"; $disable_uri = "disable/{$id}/disable/";
$disable_icon = 'fa-ban'; $disable_icon = 'fa-ban';
$disable_name = pht('Archive Rule'); $disable_name = pht('Disable Rule');
} }
$curtain->addAction( $curtain->addAction(
id(new PhabricatorActionView()) id(new PhabricatorActionView())
->setName(pht('Disable Rule'))
->setHref($this->getApplicationURI($disable_uri)) ->setHref($this->getApplicationURI($disable_uri))
->setIcon($disable_icon) ->setIcon($disable_icon)
->setName($disable_name) ->setName($disable_name)

View file

@ -8,6 +8,7 @@ final class HeraldRuleQuery extends PhabricatorCursorPagedPolicyAwareQuery {
private $ruleTypes; private $ruleTypes;
private $contentTypes; private $contentTypes;
private $disabled; private $disabled;
private $active;
private $datasourceQuery; private $datasourceQuery;
private $triggerObjectPHIDs; private $triggerObjectPHIDs;
@ -45,6 +46,11 @@ final class HeraldRuleQuery extends PhabricatorCursorPagedPolicyAwareQuery {
return $this; return $this;
} }
public function withActive($active) {
$this->active = $active;
return $this;
}
public function withDatasourceQuery($query) { public function withDatasourceQuery($query) {
$this->datasourceQuery = $query; $this->datasourceQuery = $query;
return $this; return $this;
@ -92,10 +98,31 @@ final class HeraldRuleQuery extends PhabricatorCursorPagedPolicyAwareQuery {
} }
} }
if ($this->needValidateAuthors) { if ($this->needValidateAuthors || ($this->active !== null)) {
$this->validateRuleAuthors($rules); $this->validateRuleAuthors($rules);
} }
if ($this->active !== null) {
$need_active = (bool)$this->active;
foreach ($rules as $key => $rule) {
if ($rule->getIsDisabled()) {
$is_active = false;
} else if (!$rule->hasValidAuthor()) {
$is_active = false;
} else {
$is_active = true;
}
if ($is_active != $need_active) {
unset($rules[$key]);
}
}
}
if (!$rules) {
return array();
}
if ($this->needConditionsAndActions) { if ($this->needConditionsAndActions) {
$conditions = id(new HeraldCondition())->loadAllWhere( $conditions = id(new HeraldCondition())->loadAllWhere(
'ruleID IN (%Ld)', 'ruleID IN (%Ld)',
@ -213,6 +240,13 @@ final class HeraldRuleQuery extends PhabricatorCursorPagedPolicyAwareQuery {
(int)$this->disabled); (int)$this->disabled);
} }
if ($this->active !== null) {
$where[] = qsprintf(
$conn,
'rule.isDisabled = %d',
(int)(!$this->active));
}
if ($this->datasourceQuery !== null) { if ($this->datasourceQuery !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,

View file

@ -11,7 +11,8 @@ final class HeraldRuleSearchEngine extends PhabricatorApplicationSearchEngine {
} }
public function newQuery() { public function newQuery() {
return new HeraldRuleQuery(); return id(new HeraldRuleQuery())
->needValidateAuthors(true);
} }
protected function buildCustomSearchFields() { protected function buildCustomSearchFields() {
@ -41,7 +42,14 @@ final class HeraldRuleSearchEngine extends PhabricatorApplicationSearchEngine {
pht('Search for rules affecting given types of content.')) pht('Search for rules affecting given types of content.'))
->setOptions($content_types), ->setOptions($content_types),
id(new PhabricatorSearchThreeStateField()) id(new PhabricatorSearchThreeStateField())
->setLabel(pht('Rule Status')) ->setLabel(pht('Active Rules'))
->setKey('active')
->setOptions(
pht('(Show All)'),
pht('Show Only Active Rules'),
pht('Show Only Inactive Rules')),
id(new PhabricatorSearchThreeStateField())
->setLabel(pht('Disabled Rules'))
->setKey('disabled') ->setKey('disabled')
->setOptions( ->setOptions(
pht('(Show All)'), pht('(Show All)'),
@ -69,6 +77,10 @@ final class HeraldRuleSearchEngine extends PhabricatorApplicationSearchEngine {
$query->withDisabled($map['disabled']); $query->withDisabled($map['disabled']);
} }
if ($map['active'] !== null) {
$query->withActive($map['active']);
}
return $query; return $query;
} }
@ -99,7 +111,8 @@ final class HeraldRuleSearchEngine extends PhabricatorApplicationSearchEngine {
case 'all': case 'all':
return $query; return $query;
case 'active': case 'active':
return $query->setParameter('disabled', false); return $query
->setParameter('active', true);
case 'authored': case 'authored':
return $query return $query
->setParameter('authorPHIDs', array($viewer_phid)) ->setParameter('authorPHIDs', array($viewer_phid))
@ -145,6 +158,9 @@ final class HeraldRuleSearchEngine extends PhabricatorApplicationSearchEngine {
if ($rule->getIsDisabled()) { if ($rule->getIsDisabled()) {
$item->setDisabled(true); $item->setDisabled(true);
$item->addIcon('fa-lock grey', pht('Disabled')); $item->addIcon('fa-lock grey', pht('Disabled'));
} else if (!$rule->hasValidAuthor()) {
$item->setDisabled(true);
$item->addIcon('fa-user grey', pht('Author Not Active'));
} }
$content_type_name = idx($content_type_map, $rule->getContentType()); $content_type_name = idx($content_type_map, $rule->getContentType());