2011-03-22 22:34:38 +01:00
|
|
|
<?php
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class HeraldNewController extends HeraldController {
|
2011-03-22 22:34:38 +01:00
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
2013-10-05 00:15:48 +02:00
|
|
|
$content_type_map = HeraldAdapter::getEnabledAdapterMap($user);
|
2013-12-27 22:16:25 +01:00
|
|
|
$rule_type_map = HeraldRuleTypeConfig::getRuleTypeMap();
|
|
|
|
|
|
|
|
$errors = array();
|
|
|
|
|
|
|
|
$e_type = null;
|
|
|
|
$e_rule = null;
|
|
|
|
|
|
|
|
$step = 0;
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$step = $request->getInt('step');
|
|
|
|
$content_type = $request->getStr('content_type');
|
|
|
|
if (empty($content_type_map[$content_type])) {
|
|
|
|
$errors[] = pht('You must choose a content type for this rule.');
|
|
|
|
$e_type = pht('Required');
|
|
|
|
$step = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$errors && $step > 1) {
|
|
|
|
$rule_type = $request->getStr('rule_type');
|
|
|
|
if (empty($rule_type_map[$rule_type])) {
|
|
|
|
$errors[] = pht('You must choose a rule type for this rule.');
|
|
|
|
$e_rule = pht('Required');
|
|
|
|
$step = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$errors && $step == 2) {
|
|
|
|
$uri = id(new PhutilURI('edit/'))
|
|
|
|
->setQueryParams(
|
|
|
|
array(
|
|
|
|
'content_type' => $content_type,
|
|
|
|
'rule_type' => $rule_type,
|
|
|
|
));
|
|
|
|
$uri = $this->getApplicationURI($uri);
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($uri);
|
|
|
|
}
|
2011-03-22 22:34:38 +01:00
|
|
|
}
|
|
|
|
|
2013-12-27 22:16:25 +01:00
|
|
|
if ($errors) {
|
|
|
|
$errors = id(new AphrontErrorView())->setErrors($errors);
|
General Herald refactoring pass
Summary:
**Who can delete global rules?**: I discussed this with @jungejason. The current behavior is that the rule author or any administrator can delete a global rule, but this
isn't consistent with who can edit a rule (anyone) and doesn't really make much sense (it's an artifact of the global/personal split). I proposed that anyone can delete a
rule but we don't actually delete them, and log the deletion. However, when it came time to actually write the code for this I backed off a bit and continued actually
deleting the rules -- I think this does a reasonable job of balancing accountability with complexity. So the new impelmentation is:
- Personal rules can be deleted only by their owners.
- Global rules can be deleted by any user.
- All deletes are logged.
- Logs are more detailed.
- All logged actions can be viewed in aggregate.
**Minor Cleanup**
- Merged `HomeController` and `AllController`.
- Moved most queries to Query classes.
- Use AphrontFormSelectControl::renderSelectTag() where appropriate (this is a fairly recent addition).
- Use an AphrontErrorView to render the dry run notice (this didn't exist when I ported).
- Reenable some transaction code (this works again now).
- Removed the ability for admins to change rule authors (this was a little buggy, messy, and doesn't make tons of sense after the personal/global rule split).
- Rules which depend on other rules now display the right options (all global rules, all your personal rules for personal rules).
- Fix a bug in AphrontTableView where the "no data" cell would be rendered too wide if some columns are not visible.
- Allow selectFilter() in AphrontNavFilterView to be called without a 'default' argument.
Test Plan:
- Browsed, created, edited, deleted personal and gules.
- Verified generated logs.
- Did some dry runs.
- Verified transcript list and transcript details.
- Created/edited all/any rules; created/edited once/every time rules.
- Filtered admin views by users.
Reviewers: jungejason, btrahan
Reviewed By: btrahan
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D2040
2012-03-30 19:49:55 +02:00
|
|
|
}
|
2012-01-14 00:24:56 +01:00
|
|
|
|
2013-12-27 22:16:25 +01:00
|
|
|
$form = id(new AphrontFormView())
|
|
|
|
->setUser($user)
|
|
|
|
->setAction($this->getApplicationURI('new/'));
|
|
|
|
|
|
|
|
$rule_types = $this->renderRuleTypeControl($rule_type_map, $e_rule);
|
|
|
|
|
|
|
|
switch ($step) {
|
|
|
|
case 0:
|
|
|
|
default:
|
|
|
|
$form
|
|
|
|
->addHiddenInput('step', 1)
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSelectControl())
|
|
|
|
->setLabel(pht('New Rule for'))
|
|
|
|
->setName('content_type')
|
|
|
|
->setValue($request->getStr('content_type'))
|
|
|
|
->setOptions($content_type_map));
|
|
|
|
$cancel_text = null;
|
|
|
|
$cancel_uri = $this->getApplicationURI();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
$form
|
|
|
|
->addHiddenInput('content_type', $request->getStr('content_type'))
|
|
|
|
->addHiddenInput('step', 2)
|
|
|
|
->appendChild($rule_types);
|
|
|
|
$cancel_text = pht('Back');
|
|
|
|
$cancel_uri = id(new PhutilURI('new/'))
|
|
|
|
->setQueryParams(
|
|
|
|
array(
|
|
|
|
'content_type' => $request->getStr('content_type'),
|
|
|
|
'step' => 1,
|
|
|
|
));
|
|
|
|
$cancel_uri = $this->getApplicationURI($cancel_uri);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$form
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
|
|
|
->setValue(pht('Continue'))
|
|
|
|
->addCancelButton($cancel_uri, $cancel_text));
|
|
|
|
|
|
|
|
$form_box = id(new PHUIObjectBoxView())
|
|
|
|
->setFormError($errors)
|
|
|
|
->setHeaderText(pht('Create Herald Rule'))
|
|
|
|
->setForm($form);
|
|
|
|
|
|
|
|
$crumbs = $this
|
|
|
|
->buildApplicationCrumbs()
|
|
|
|
->addTextCrumb(pht('Create Rule'));
|
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
array(
|
|
|
|
$crumbs,
|
|
|
|
$form_box,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'title' => pht('Create Herald Rule'),
|
|
|
|
'device' => true,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderRuleTypeControl(array $rule_type_map, $e_rule) {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
Improve Herald personal/global UI/UX
Summary:
- Default "personal" vs "global" choice to "personal".
- Don't show global rules under "My Rules".
- After editing or creating a global rule, redirect back to global rule list.
- Use radio buttons for "personal" vs "global" and add captions explaining the
difference.
- For "global" rules, don't show the owner/author in the rule detail view --
they effectively have no owner (see also D1387).
- For "global" rules, don't show the owner/author in the rule list view, as
above.
- For admin views, show rule type (global vs personal).
Test Plan:
- Created and edited new global and personal rules.
- Viewed "my", "global" and "admin" views.
Reviewers: btrahan, jungejason, nh, xela
Reviewed By: btrahan
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1518
2012-01-31 21:09:29 +01:00
|
|
|
// Reorder array to put "personal" first.
|
|
|
|
$rule_type_map = array_select_keys(
|
|
|
|
$rule_type_map,
|
|
|
|
array(
|
|
|
|
HeraldRuleTypeConfig::RULE_TYPE_PERSONAL,
|
|
|
|
)) + $rule_type_map;
|
|
|
|
|
2013-10-09 22:52:04 +02:00
|
|
|
list($can_global, $global_link) = $this->explainApplicationCapability(
|
|
|
|
HeraldCapabilityManageGlobalRules::CAPABILITY,
|
|
|
|
pht('You have permission to create and manage global rules.'),
|
|
|
|
pht('You do not have permission to create or manage global rules.'));
|
2013-10-05 00:15:48 +02:00
|
|
|
|
Improve Herald personal/global UI/UX
Summary:
- Default "personal" vs "global" choice to "personal".
- Don't show global rules under "My Rules".
- After editing or creating a global rule, redirect back to global rule list.
- Use radio buttons for "personal" vs "global" and add captions explaining the
difference.
- For "global" rules, don't show the owner/author in the rule detail view --
they effectively have no owner (see also D1387).
- For "global" rules, don't show the owner/author in the rule list view, as
above.
- For admin views, show rule type (global vs personal).
Test Plan:
- Created and edited new global and personal rules.
- Viewed "my", "global" and "admin" views.
Reviewers: btrahan, jungejason, nh, xela
Reviewed By: btrahan
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1518
2012-01-31 21:09:29 +01:00
|
|
|
$captions = array(
|
|
|
|
HeraldRuleTypeConfig::RULE_TYPE_PERSONAL =>
|
2013-10-05 00:15:48 +02:00
|
|
|
pht(
|
|
|
|
'Personal rules notify you about events. You own them, but they can '.
|
2013-10-05 21:55:34 +02:00
|
|
|
'only affect you. Personal rules only trigger for objects you have '.
|
|
|
|
'permission to see.'),
|
Improve Herald personal/global UI/UX
Summary:
- Default "personal" vs "global" choice to "personal".
- Don't show global rules under "My Rules".
- After editing or creating a global rule, redirect back to global rule list.
- Use radio buttons for "personal" vs "global" and add captions explaining the
difference.
- For "global" rules, don't show the owner/author in the rule detail view --
they effectively have no owner (see also D1387).
- For "global" rules, don't show the owner/author in the rule list view, as
above.
- For admin views, show rule type (global vs personal).
Test Plan:
- Created and edited new global and personal rules.
- Viewed "my", "global" and "admin" views.
Reviewers: btrahan, jungejason, nh, xela
Reviewed By: btrahan
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1518
2012-01-31 21:09:29 +01:00
|
|
|
HeraldRuleTypeConfig::RULE_TYPE_GLOBAL =>
|
2013-10-09 22:52:04 +02:00
|
|
|
array(
|
|
|
|
pht(
|
|
|
|
'Global rules notify anyone about events. Global rules can '.
|
|
|
|
'bypass access control policies and act on any object.'),
|
|
|
|
$global_link,
|
|
|
|
),
|
Improve Herald personal/global UI/UX
Summary:
- Default "personal" vs "global" choice to "personal".
- Don't show global rules under "My Rules".
- After editing or creating a global rule, redirect back to global rule list.
- Use radio buttons for "personal" vs "global" and add captions explaining the
difference.
- For "global" rules, don't show the owner/author in the rule detail view --
they effectively have no owner (see also D1387).
- For "global" rules, don't show the owner/author in the rule list view, as
above.
- For admin views, show rule type (global vs personal).
Test Plan:
- Created and edited new global and personal rules.
- Viewed "my", "global" and "admin" views.
Reviewers: btrahan, jungejason, nh, xela
Reviewed By: btrahan
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1518
2012-01-31 21:09:29 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$radio = id(new AphrontFormRadioButtonControl())
|
2013-05-20 17:24:07 +02:00
|
|
|
->setLabel(pht('Type'))
|
Improve Herald personal/global UI/UX
Summary:
- Default "personal" vs "global" choice to "personal".
- Don't show global rules under "My Rules".
- After editing or creating a global rule, redirect back to global rule list.
- Use radio buttons for "personal" vs "global" and add captions explaining the
difference.
- For "global" rules, don't show the owner/author in the rule detail view --
they effectively have no owner (see also D1387).
- For "global" rules, don't show the owner/author in the rule list view, as
above.
- For admin views, show rule type (global vs personal).
Test Plan:
- Created and edited new global and personal rules.
- Viewed "my", "global" and "admin" views.
Reviewers: btrahan, jungejason, nh, xela
Reviewed By: btrahan
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1518
2012-01-31 21:09:29 +01:00
|
|
|
->setName('rule_type')
|
2013-12-27 22:16:25 +01:00
|
|
|
->setValue($request->getStr('rule_type'))
|
|
|
|
->setError($e_rule);
|
Improve Herald personal/global UI/UX
Summary:
- Default "personal" vs "global" choice to "personal".
- Don't show global rules under "My Rules".
- After editing or creating a global rule, redirect back to global rule list.
- Use radio buttons for "personal" vs "global" and add captions explaining the
difference.
- For "global" rules, don't show the owner/author in the rule detail view --
they effectively have no owner (see also D1387).
- For "global" rules, don't show the owner/author in the rule list view, as
above.
- For admin views, show rule type (global vs personal).
Test Plan:
- Created and edited new global and personal rules.
- Viewed "my", "global" and "admin" views.
Reviewers: btrahan, jungejason, nh, xela
Reviewed By: btrahan
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1518
2012-01-31 21:09:29 +01:00
|
|
|
|
|
|
|
foreach ($rule_type_map as $value => $name) {
|
2013-10-05 00:15:48 +02:00
|
|
|
$disabled = ($value == HeraldRuleTypeConfig::RULE_TYPE_GLOBAL) &&
|
|
|
|
(!$can_global);
|
|
|
|
|
Improve Herald personal/global UI/UX
Summary:
- Default "personal" vs "global" choice to "personal".
- Don't show global rules under "My Rules".
- After editing or creating a global rule, redirect back to global rule list.
- Use radio buttons for "personal" vs "global" and add captions explaining the
difference.
- For "global" rules, don't show the owner/author in the rule detail view --
they effectively have no owner (see also D1387).
- For "global" rules, don't show the owner/author in the rule list view, as
above.
- For admin views, show rule type (global vs personal).
Test Plan:
- Created and edited new global and personal rules.
- Viewed "my", "global" and "admin" views.
Reviewers: btrahan, jungejason, nh, xela
Reviewed By: btrahan
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1518
2012-01-31 21:09:29 +01:00
|
|
|
$radio->addButton(
|
|
|
|
$value,
|
|
|
|
$name,
|
2013-10-05 00:15:48 +02:00
|
|
|
idx($captions, $value),
|
|
|
|
$disabled ? 'disabled' : null,
|
|
|
|
$disabled);
|
Improve Herald personal/global UI/UX
Summary:
- Default "personal" vs "global" choice to "personal".
- Don't show global rules under "My Rules".
- After editing or creating a global rule, redirect back to global rule list.
- Use radio buttons for "personal" vs "global" and add captions explaining the
difference.
- For "global" rules, don't show the owner/author in the rule detail view --
they effectively have no owner (see also D1387).
- For "global" rules, don't show the owner/author in the rule list view, as
above.
- For admin views, show rule type (global vs personal).
Test Plan:
- Created and edited new global and personal rules.
- Viewed "my", "global" and "admin" views.
Reviewers: btrahan, jungejason, nh, xela
Reviewed By: btrahan
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1518
2012-01-31 21:09:29 +01:00
|
|
|
}
|
|
|
|
|
2013-12-27 22:16:25 +01:00
|
|
|
return $radio;
|
2011-03-22 22:34:38 +01:00
|
|
|
}
|
|
|
|
}
|