Skip to content

Commit 8a8123c

Browse files
author
epriestley
committedNov 15, 2018
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
1 parent bbd292b commit 8a8123c

File tree

4 files changed

+65
-19
lines changed

4 files changed

+65
-19
lines changed
 

‎src/applications/herald/controller/HeraldDisableController.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ public function handleRequest(AphrontRequest $request) {
4444
}
4545

4646
if ($is_disable) {
47-
$title = pht('Really archive this rule?');
47+
$title = pht('Really disable this rule?');
4848
$body = pht('This rule will no longer activate.');
49-
$button = pht('Archive Rule');
49+
$button = pht('Disable Rule');
5050
} else {
51-
$title = pht('Really activate this rule?');
51+
$title = pht('Really enable this rule?');
5252
$body = pht('This rule will become active again.');
53-
$button = pht('Activate Rule');
53+
$button = pht('Enable Rule');
5454
}
5555

5656
$dialog = id(new AphrontDialogView())

‎src/applications/herald/controller/HeraldRuleViewController.php

+7-11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public function handleRequest(AphrontRequest $request) {
1414
->setViewer($viewer)
1515
->withIDs(array($id))
1616
->needConditionsAndActions(true)
17+
->needValidateAuthors(true)
1718
->executeOne();
1819
if (!$rule) {
1920
return new Aphront404Response();
@@ -26,15 +27,11 @@ public function handleRequest(AphrontRequest $request) {
2627
->setHeaderIcon('fa-bullhorn');
2728

2829
if ($rule->getIsDisabled()) {
29-
$header->setStatus(
30-
'fa-ban',
31-
'red',
32-
pht('Archived'));
30+
$header->setStatus('fa-ban', 'red', pht('Disabled'));
31+
} else if (!$rule->hasValidAuthor()) {
32+
$header->setStatus('fa-user', 'red', pht('Author Not Active'));
3333
} else {
34-
$header->setStatus(
35-
'fa-check',
36-
'bluegrey',
37-
pht('Active'));
34+
$header->setStatus('fa-check', 'bluegrey', pht('Active'));
3835
}
3936

4037
$curtain = $this->buildCurtain($rule);
@@ -90,16 +87,15 @@ private function buildCurtain(HeraldRule $rule) {
9087
if ($rule->getIsDisabled()) {
9188
$disable_uri = "disable/{$id}/enable/";
9289
$disable_icon = 'fa-check';
93-
$disable_name = pht('Activate Rule');
90+
$disable_name = pht('Enable Rule');
9491
} else {
9592
$disable_uri = "disable/{$id}/disable/";
9693
$disable_icon = 'fa-ban';
97-
$disable_name = pht('Archive Rule');
94+
$disable_name = pht('Disable Rule');
9895
}
9996

10097
$curtain->addAction(
10198
id(new PhabricatorActionView())
102-
->setName(pht('Disable Rule'))
10399
->setHref($this->getApplicationURI($disable_uri))
104100
->setIcon($disable_icon)
105101
->setName($disable_name)

‎src/applications/herald/query/HeraldRuleQuery.php

+35-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ final class HeraldRuleQuery extends PhabricatorCursorPagedPolicyAwareQuery {
88
private $ruleTypes;
99
private $contentTypes;
1010
private $disabled;
11+
private $active;
1112
private $datasourceQuery;
1213
private $triggerObjectPHIDs;
1314

@@ -45,6 +46,11 @@ public function withDisabled($disabled) {
4546
return $this;
4647
}
4748

49+
public function withActive($active) {
50+
$this->active = $active;
51+
return $this;
52+
}
53+
4854
public function withDatasourceQuery($query) {
4955
$this->datasourceQuery = $query;
5056
return $this;
@@ -92,10 +98,31 @@ protected function willFilterPage(array $rules) {
9298
}
9399
}
94100

95-
if ($this->needValidateAuthors) {
101+
if ($this->needValidateAuthors || ($this->active !== null)) {
96102
$this->validateRuleAuthors($rules);
97103
}
98104

105+
if ($this->active !== null) {
106+
$need_active = (bool)$this->active;
107+
foreach ($rules as $key => $rule) {
108+
if ($rule->getIsDisabled()) {
109+
$is_active = false;
110+
} else if (!$rule->hasValidAuthor()) {
111+
$is_active = false;
112+
} else {
113+
$is_active = true;
114+
}
115+
116+
if ($is_active != $need_active) {
117+
unset($rules[$key]);
118+
}
119+
}
120+
}
121+
122+
if (!$rules) {
123+
return array();
124+
}
125+
99126
if ($this->needConditionsAndActions) {
100127
$conditions = id(new HeraldCondition())->loadAllWhere(
101128
'ruleID IN (%Ld)',
@@ -213,6 +240,13 @@ protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
213240
(int)$this->disabled);
214241
}
215242

243+
if ($this->active !== null) {
244+
$where[] = qsprintf(
245+
$conn,
246+
'rule.isDisabled = %d',
247+
(int)(!$this->active));
248+
}
249+
216250
if ($this->datasourceQuery !== null) {
217251
$where[] = qsprintf(
218252
$conn,

‎src/applications/herald/query/HeraldRuleSearchEngine.php

+19-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ public function getApplicationClassName() {
1111
}
1212

1313
public function newQuery() {
14-
return new HeraldRuleQuery();
14+
return id(new HeraldRuleQuery())
15+
->needValidateAuthors(true);
1516
}
1617

1718
protected function buildCustomSearchFields() {
@@ -41,7 +42,14 @@ protected function buildCustomSearchFields() {
4142
pht('Search for rules affecting given types of content.'))
4243
->setOptions($content_types),
4344
id(new PhabricatorSearchThreeStateField())
44-
->setLabel(pht('Rule Status'))
45+
->setLabel(pht('Active Rules'))
46+
->setKey('active')
47+
->setOptions(
48+
pht('(Show All)'),
49+
pht('Show Only Active Rules'),
50+
pht('Show Only Inactive Rules')),
51+
id(new PhabricatorSearchThreeStateField())
52+
->setLabel(pht('Disabled Rules'))
4553
->setKey('disabled')
4654
->setOptions(
4755
pht('(Show All)'),
@@ -69,6 +77,10 @@ protected function buildQueryFromParameters(array $map) {
6977
$query->withDisabled($map['disabled']);
7078
}
7179

80+
if ($map['active'] !== null) {
81+
$query->withActive($map['active']);
82+
}
83+
7284
return $query;
7385
}
7486

@@ -99,7 +111,8 @@ public function buildSavedQueryFromBuiltin($query_key) {
99111
case 'all':
100112
return $query;
101113
case 'active':
102-
return $query->setParameter('disabled', false);
114+
return $query
115+
->setParameter('active', true);
103116
case 'authored':
104117
return $query
105118
->setParameter('authorPHIDs', array($viewer_phid))
@@ -145,6 +158,9 @@ protected function renderResultList(
145158
if ($rule->getIsDisabled()) {
146159
$item->setDisabled(true);
147160
$item->addIcon('fa-lock grey', pht('Disabled'));
161+
} else if (!$rule->hasValidAuthor()) {
162+
$item->setDisabled(true);
163+
$item->addIcon('fa-user grey', pht('Author Not Active'));
148164
}
149165

150166
$content_type_name = idx($content_type_map, $rule->getContentType());

0 commit comments

Comments
 (0)
Failed to load comments.