2011-03-22 23:27:52 +01:00
|
|
|
<?php
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class HeraldRuleController extends HeraldController {
|
2011-03-22 23:27:52 +01:00
|
|
|
|
2015-08-02 00:41:36 +02:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $request->getViewer();
|
|
|
|
$id = $request->getURIData('id');
|
2011-12-16 22:29:32 +01:00
|
|
|
|
2015-08-02 00:41:36 +02:00
|
|
|
$content_type_map = HeraldAdapter::getEnabledAdapterMap($viewer);
|
2012-01-14 00:24:56 +01:00
|
|
|
$rule_type_map = HeraldRuleTypeConfig::getRuleTypeMap();
|
2011-03-22 23:27:52 +01:00
|
|
|
|
2015-08-02 00:41:36 +02:00
|
|
|
if ($id) {
|
2013-08-02 19:25:45 +02:00
|
|
|
$rule = id(new HeraldRuleQuery())
|
2015-08-02 00:41:36 +02:00
|
|
|
->setViewer($viewer)
|
2013-08-06 22:43:45 +02:00
|
|
|
->withIDs(array($id))
|
2013-08-02 19:25:45 +02:00
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->executeOne();
|
2011-03-22 23:27:52 +01:00
|
|
|
if (!$rule) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
2015-11-12 21:06:59 +01:00
|
|
|
$cancel_uri = '/'.$rule->getMonogram();
|
2011-03-22 23:27:52 +01:00
|
|
|
} else {
|
2015-09-25 19:43:04 +02:00
|
|
|
$new_uri = $this->getApplicationURI('new/');
|
|
|
|
|
2011-03-22 23:27:52 +01:00
|
|
|
$rule = new HeraldRule();
|
2015-08-02 00:41:36 +02:00
|
|
|
$rule->setAuthorPHID($viewer->getPHID());
|
2013-09-04 21:07:26 +02:00
|
|
|
$rule->setMustMatchAll(1);
|
2011-03-22 23:27:52 +01:00
|
|
|
|
2012-01-14 00:24:56 +01:00
|
|
|
$content_type = $request->getStr('content_type');
|
|
|
|
$rule->setContentType($content_type);
|
|
|
|
|
|
|
|
$rule_type = $request->getStr('rule_type');
|
|
|
|
if (!isset($rule_type_map[$rule_type])) {
|
2015-09-25 19:43:04 +02:00
|
|
|
return $this->newDialog()
|
|
|
|
->setTitle(pht('Invalid Rule Type'))
|
|
|
|
->appendParagraph(
|
|
|
|
pht(
|
|
|
|
'The selected rule type ("%s") is not recognized by Herald.',
|
|
|
|
$rule_type))
|
|
|
|
->addCancelButton($new_uri);
|
2012-01-14 00:24:56 +01:00
|
|
|
}
|
|
|
|
$rule->setRuleType($rule_type);
|
2013-08-06 22:43:45 +02:00
|
|
|
|
2015-09-25 19:43:04 +02:00
|
|
|
try {
|
|
|
|
$adapter = HeraldAdapter::getAdapterForContentType(
|
|
|
|
$rule->getContentType());
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
return $this->newDialog()
|
|
|
|
->setTitle(pht('Invalid Content Type'))
|
|
|
|
->appendParagraph(
|
|
|
|
pht(
|
|
|
|
'The selected content type ("%s") is not recognized by '.
|
|
|
|
'Herald.',
|
|
|
|
$rule->getContentType()))
|
|
|
|
->addCancelButton($new_uri);
|
|
|
|
}
|
2013-12-31 01:48:14 +01:00
|
|
|
|
|
|
|
if (!$adapter->supportsRuleType($rule->getRuleType())) {
|
2015-09-25 19:43:04 +02:00
|
|
|
return $this->newDialog()
|
|
|
|
->setTitle(pht('Rule/Content Mismatch'))
|
|
|
|
->appendParagraph(
|
|
|
|
pht(
|
|
|
|
'The selected rule type ("%s") is not supported by the selected '.
|
|
|
|
'content type ("%s").',
|
|
|
|
$rule->getRuleType(),
|
|
|
|
$rule->getContentType()))
|
|
|
|
->addCancelButton($new_uri);
|
2013-12-31 01:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($rule->isObjectRule()) {
|
|
|
|
$rule->setTriggerObjectPHID($request->getStr('targetPHID'));
|
|
|
|
$object = id(new PhabricatorObjectQuery())
|
2015-08-02 00:41:36 +02:00
|
|
|
->setViewer($viewer)
|
2013-12-31 01:48:14 +01:00
|
|
|
->withPHIDs(array($rule->getTriggerObjectPHID()))
|
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->executeOne();
|
|
|
|
if (!$object) {
|
|
|
|
throw new Exception(
|
|
|
|
pht('No valid object provided for object rule!'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$adapter->canTriggerOnObject($object)) {
|
|
|
|
throw new Exception(
|
|
|
|
pht('Object is of wrong type for adapter!'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-06 22:43:45 +02:00
|
|
|
$cancel_uri = $this->getApplicationURI();
|
2013-10-05 00:15:48 +02:00
|
|
|
}
|
|
|
|
|
2013-12-27 22:17:10 +01:00
|
|
|
if ($rule->isGlobalRule()) {
|
2013-10-05 00:15:48 +02:00
|
|
|
$this->requireApplicationCapability(
|
2014-07-25 00:20:39 +02:00
|
|
|
HeraldManageGlobalRulesCapability::CAPABILITY);
|
2011-03-22 23:27:52 +01:00
|
|
|
}
|
|
|
|
|
2013-08-02 19:25:45 +02:00
|
|
|
$adapter = HeraldAdapter::getAdapterForContentType($rule->getContentType());
|
|
|
|
|
2011-03-22 23:27:52 +01:00
|
|
|
$local_version = id(new HeraldRule())->getConfigVersion();
|
|
|
|
if ($rule->getConfigVersion() > $local_version) {
|
|
|
|
throw new Exception(
|
2013-12-31 01:48:07 +01:00
|
|
|
pht(
|
2014-06-09 20:36:49 +02:00
|
|
|
'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.'));
|
2013-12-31 01:48:07 +01:00
|
|
|
}
|
|
|
|
|
2011-03-22 23:27:52 +01:00
|
|
|
// Upgrade rule version to our version, since we might add newly-defined
|
|
|
|
// conditions, etc.
|
|
|
|
$rule->setConfigVersion($local_version);
|
|
|
|
|
|
|
|
$rule_conditions = $rule->loadConditions();
|
|
|
|
$rule_actions = $rule->loadActions();
|
|
|
|
|
|
|
|
$rule->attachConditions($rule_conditions);
|
|
|
|
$rule->attachActions($rule_actions);
|
|
|
|
|
|
|
|
$e_name = true;
|
|
|
|
$errors = array();
|
|
|
|
if ($request->isFormPost() && $request->getStr('save')) {
|
2013-08-05 19:02:40 +02:00
|
|
|
list($e_name, $errors) = $this->saveRule($adapter, $rule, $request);
|
2011-03-22 23:27:52 +01:00
|
|
|
if (!$errors) {
|
2013-08-06 22:43:45 +02:00
|
|
|
$id = $rule->getID();
|
2015-11-12 21:06:59 +01:00
|
|
|
$uri = '/'.$rule->getMonogram();
|
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
|
|
|
return id(new AphrontRedirectResponse())->setURI($uri);
|
2011-03-22 23:27:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
$must_match_selector = $this->renderMustMatchSelector($rule);
|
2013-08-02 21:35:33 +02:00
|
|
|
$repetition_selector = $this->renderRepetitionSelector($rule, $adapter);
|
2011-03-22 23:27:52 +01:00
|
|
|
|
2012-08-15 23:11:40 +02:00
|
|
|
$handles = $this->loadHandlesForRule($rule);
|
2011-05-28 00:52:26 +02:00
|
|
|
|
2011-03-24 19:07:36 +01:00
|
|
|
require_celerity_resource('herald-css');
|
|
|
|
|
2012-01-14 00:24:56 +01:00
|
|
|
$content_type_name = $content_type_map[$rule->getContentType()];
|
|
|
|
$rule_type_name = $rule_type_map[$rule->getRuleType()];
|
2011-03-22 23:27:52 +01:00
|
|
|
|
|
|
|
$form = id(new AphrontFormView())
|
2015-08-02 00:41:36 +02:00
|
|
|
->setUser($viewer)
|
2011-03-23 01:08:08 +01:00
|
|
|
->setID('herald-rule-edit-form')
|
2012-01-14 00:24:56 +01:00
|
|
|
->addHiddenInput('content_type', $rule->getContentType())
|
|
|
|
->addHiddenInput('rule_type', $rule->getRuleType())
|
2011-03-24 19:07:36 +01:00
|
|
|
->addHiddenInput('save', 1)
|
|
|
|
->appendChild(
|
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
|
|
|
// Build this explicitly (instead of using addHiddenInput())
|
|
|
|
// so we can add a sigil to it.
|
2013-01-25 21:57:17 +01:00
|
|
|
javelin_tag(
|
2011-03-24 19:07:36 +01:00
|
|
|
'input',
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'rule',
|
|
|
|
'sigil' => 'rule',
|
|
|
|
)))
|
2011-03-22 23:27:52 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
2013-05-20 17:24:07 +02:00
|
|
|
->setLabel(pht('Rule Name'))
|
2011-03-24 19:07:36 +01:00
|
|
|
->setName('name')
|
2011-03-22 23:27:52 +01:00
|
|
|
->setError($e_name)
|
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
|
|
|
->setValue($rule->getName()));
|
|
|
|
|
2013-12-31 01:48:14 +01:00
|
|
|
$trigger_object_control = false;
|
|
|
|
if ($rule->isObjectRule()) {
|
|
|
|
$trigger_object_control = id(new AphrontFormStaticControl())
|
|
|
|
->setValue(
|
|
|
|
pht(
|
|
|
|
'This rule triggers for %s.',
|
|
|
|
$handles[$rule->getTriggerObjectPHID()]->renderLink()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
$form
|
2011-03-22 23:27:52 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormMarkupControl())
|
2013-05-20 17:24:07 +02:00
|
|
|
->setValue(pht(
|
2014-06-09 20:36:49 +02:00
|
|
|
'This %s rule triggers for %s.',
|
2013-05-20 17:24:07 +02:00
|
|
|
phutil_tag('strong', array(), $rule_type_name),
|
|
|
|
phutil_tag('strong', array(), $content_type_name))))
|
2013-12-31 01:48:14 +01:00
|
|
|
->appendChild($trigger_object_control)
|
2011-03-22 23:27:52 +01:00
|
|
|
->appendChild(
|
2014-11-07 23:16:30 +01:00
|
|
|
id(new PHUIFormInsetView())
|
2013-05-20 17:24:07 +02:00
|
|
|
->setTitle(pht('Conditions'))
|
2013-01-25 21:57:17 +01:00
|
|
|
->setRightButton(javelin_tag(
|
2012-03-16 01:10:19 +01:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '#',
|
2017-06-05 22:14:34 +02:00
|
|
|
'class' => 'button button-green',
|
2012-03-16 01:10:19 +01:00
|
|
|
'sigil' => 'create-condition',
|
2014-10-07 15:01:04 +02:00
|
|
|
'mustcapture' => true,
|
2012-03-16 01:10:19 +01:00
|
|
|
),
|
2013-05-20 17:24:07 +02:00
|
|
|
pht('New Condition')))
|
2012-03-16 01:10:19 +01:00
|
|
|
->setDescription(
|
2013-05-20 17:24:07 +02:00
|
|
|
pht('When %s these conditions are met:', $must_match_selector))
|
2013-01-25 21:57:17 +01:00
|
|
|
->setContent(javelin_tag(
|
2011-03-23 01:08:08 +01:00
|
|
|
'table',
|
|
|
|
array(
|
|
|
|
'sigil' => 'rule-conditions',
|
2014-10-07 15:01:04 +02:00
|
|
|
'class' => 'herald-condition-table',
|
2011-03-23 01:08:08 +01:00
|
|
|
),
|
2012-03-16 01:10:19 +01:00
|
|
|
'')))
|
2011-03-22 23:27:52 +01:00
|
|
|
->appendChild(
|
2014-11-07 23:16:30 +01:00
|
|
|
id(new PHUIFormInsetView())
|
2013-05-20 17:24:07 +02:00
|
|
|
->setTitle(pht('Action'))
|
2013-01-25 21:57:17 +01:00
|
|
|
->setRightButton(javelin_tag(
|
2011-03-23 04:41:02 +01:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '#',
|
2017-06-05 22:14:34 +02:00
|
|
|
'class' => 'button button-green',
|
2011-03-23 04:41:02 +01:00
|
|
|
'sigil' => 'create-action',
|
|
|
|
'mustcapture' => true,
|
|
|
|
),
|
2013-05-20 17:24:07 +02:00
|
|
|
pht('New Action')))
|
|
|
|
->setDescription(pht(
|
2018-01-25 17:03:29 +01:00
|
|
|
'Take these actions %s',
|
2013-02-05 23:30:29 +01:00
|
|
|
$repetition_selector))
|
2013-01-25 21:57:17 +01:00
|
|
|
->setContent(javelin_tag(
|
2012-03-16 01:10:19 +01:00
|
|
|
'table',
|
|
|
|
array(
|
|
|
|
'sigil' => 'rule-actions',
|
|
|
|
'class' => 'herald-action-table',
|
|
|
|
),
|
|
|
|
'')))
|
2011-03-22 23:27:52 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
2013-05-20 17:24:07 +02:00
|
|
|
->setValue(pht('Save Rule'))
|
2013-08-06 22:43:45 +02:00
|
|
|
->addCancelButton($cancel_uri));
|
2011-03-22 23:27:52 +01:00
|
|
|
|
2013-08-02 19:25:45 +02:00
|
|
|
$this->setupEditorBehavior($rule, $handles, $adapter);
|
2011-10-22 03:34:38 +02:00
|
|
|
|
2013-05-20 17:24:07 +02:00
|
|
|
$title = $rule->getID()
|
2016-04-01 16:14:25 +02:00
|
|
|
? pht('Edit Herald Rule: %s', $rule->getName())
|
|
|
|
: pht('Create Herald Rule: %s', idx($content_type_map, $content_type));
|
|
|
|
|
2013-09-25 20:23:29 +02:00
|
|
|
$form_box = id(new PHUIObjectBoxView())
|
2017-09-07 21:01:44 +02:00
|
|
|
->setHeaderText($title)
|
|
|
|
->setBackground(PHUIObjectBoxView::WHITE_CONFIG)
|
2014-01-10 18:17:37 +01:00
|
|
|
->setFormErrors($errors)
|
2013-08-26 20:53:11 +02:00
|
|
|
->setForm($form);
|
|
|
|
|
2013-05-20 17:24:07 +02:00
|
|
|
$crumbs = $this
|
|
|
|
->buildApplicationCrumbs()
|
2016-04-01 16:14:25 +02:00
|
|
|
->addTextCrumb($title)
|
|
|
|
->setBorder(true);
|
|
|
|
|
|
|
|
$view = id(new PHUITwoColumnView())
|
|
|
|
->setFooter($form_box);
|
2015-11-29 02:05:28 +01:00
|
|
|
|
|
|
|
return $this->newPage()
|
|
|
|
->setTitle($title)
|
|
|
|
->setCrumbs($crumbs)
|
|
|
|
->appendChild(
|
|
|
|
array(
|
2016-04-01 16:14:25 +02:00
|
|
|
$view,
|
2011-10-22 03:34:38 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2013-08-05 19:02:40 +02:00
|
|
|
private function saveRule(HeraldAdapter $adapter, $rule, $request) {
|
2016-03-29 01:02:41 +02:00
|
|
|
$new_name = $request->getStr('name');
|
2013-09-04 21:07:26 +02:00
|
|
|
$match_all = ($request->getStr('must_match') == 'all');
|
2011-10-22 03:34:38 +02:00
|
|
|
|
2018-02-05 14:58:21 +01:00
|
|
|
$repetition_policy = $request->getStr('repetition_policy');
|
|
|
|
|
|
|
|
// If the user selected an invalid policy, or there's only one possible
|
|
|
|
// value so we didn't render a control, adjust the value to the first
|
|
|
|
// valid policy value.
|
|
|
|
$repetition_options = $this->getRepetitionOptionMap($adapter);
|
|
|
|
if (!isset($repetition_options[$repetition_policy])) {
|
|
|
|
$repetition_policy = head_key($repetition_options);
|
|
|
|
}
|
2011-10-22 03:34:38 +02:00
|
|
|
|
|
|
|
$e_name = true;
|
|
|
|
$errors = array();
|
|
|
|
|
2016-03-29 01:02:41 +02:00
|
|
|
if (!strlen($new_name)) {
|
2014-06-09 20:36:49 +02:00
|
|
|
$e_name = pht('Required');
|
|
|
|
$errors[] = pht('Rule must have a name.');
|
2011-10-22 03:34:38 +02:00
|
|
|
}
|
|
|
|
|
2015-05-05 12:20:11 +02:00
|
|
|
$data = null;
|
|
|
|
try {
|
|
|
|
$data = phutil_json_decode($request->getStr('rule'));
|
|
|
|
} catch (PhutilJSONParserException $ex) {
|
|
|
|
throw new PhutilProxyException(
|
|
|
|
pht('Failed to decode rule data.'),
|
|
|
|
$ex);
|
|
|
|
}
|
|
|
|
|
2011-10-22 03:34:38 +02:00
|
|
|
if (!is_array($data) ||
|
|
|
|
!$data['conditions'] ||
|
|
|
|
!$data['actions']) {
|
2015-05-22 09:27:56 +02:00
|
|
|
throw new Exception(pht('Failed to decode rule data.'));
|
2011-10-22 03:34:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$conditions = array();
|
|
|
|
foreach ($data['conditions'] as $condition) {
|
|
|
|
if ($condition === null) {
|
|
|
|
// We manage this as a sparse array on the client, so may receive
|
|
|
|
// NULL if conditions have been removed.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$obj = new HeraldCondition();
|
|
|
|
$obj->setFieldName($condition[0]);
|
|
|
|
$obj->setFieldCondition($condition[1]);
|
|
|
|
|
|
|
|
if (is_array($condition[2])) {
|
|
|
|
$obj->setValue(array_keys($condition[2]));
|
|
|
|
} else {
|
|
|
|
$obj->setValue($condition[2]);
|
|
|
|
}
|
|
|
|
|
2013-08-05 19:02:40 +02:00
|
|
|
try {
|
|
|
|
$adapter->willSaveCondition($obj);
|
|
|
|
} catch (HeraldInvalidConditionException $ex) {
|
|
|
|
$errors[] = $ex->getMessage();
|
2011-10-22 03:34:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$conditions[] = $obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
$actions = array();
|
|
|
|
foreach ($data['actions'] as $action) {
|
|
|
|
if ($action === null) {
|
|
|
|
// Sparse on the client; removals can give us NULLs.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($action[1])) {
|
|
|
|
// Legitimate for any action which doesn't need a target, like
|
|
|
|
// "Do nothing".
|
|
|
|
$action[1] = null;
|
|
|
|
}
|
|
|
|
|
2015-07-23 22:26:40 +02:00
|
|
|
$obj = new HeraldActionRecord();
|
2013-08-06 20:23:01 +02:00
|
|
|
$obj->setAction($action[0]);
|
|
|
|
$obj->setTarget($action[1]);
|
|
|
|
|
|
|
|
try {
|
|
|
|
$adapter->willSaveAction($rule, $obj);
|
|
|
|
} catch (HeraldInvalidActionException $ex) {
|
2015-05-25 11:02:49 +02:00
|
|
|
$errors[] = $ex->getMessage();
|
2013-08-06 20:23:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$actions[] = $obj;
|
2012-01-05 22:07:08 +01:00
|
|
|
}
|
|
|
|
|
2011-10-22 03:34:38 +02:00
|
|
|
if (!$errors) {
|
2016-03-29 01:02:41 +02:00
|
|
|
$new_state = id(new HeraldRuleSerializer())->serializeRuleComponents(
|
|
|
|
$match_all,
|
|
|
|
$conditions,
|
|
|
|
$actions,
|
2018-02-05 14:58:21 +01:00
|
|
|
$repetition_policy);
|
2016-03-29 01:02:41 +02:00
|
|
|
|
|
|
|
$xactions = array();
|
2019-03-07 13:48:41 +01:00
|
|
|
|
|
|
|
// Until this moves to EditEngine, manually add a "CREATE" transaction
|
|
|
|
// if we're creating a new rule. This improves rendering of the initial
|
|
|
|
// group of transactions.
|
|
|
|
$is_new = (bool)(!$rule->getID());
|
|
|
|
if ($is_new) {
|
|
|
|
$xactions[] = id(new HeraldRuleTransaction())
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_CREATE);
|
|
|
|
}
|
|
|
|
|
2016-03-29 01:02:41 +02:00
|
|
|
$xactions[] = id(new HeraldRuleTransaction())
|
2019-03-07 13:48:41 +01:00
|
|
|
->setTransactionType(HeraldRuleEditTransaction::TRANSACTIONTYPE)
|
2016-03-29 01:02:41 +02:00
|
|
|
->setNewValue($new_state);
|
|
|
|
$xactions[] = id(new HeraldRuleTransaction())
|
2019-03-07 13:48:41 +01:00
|
|
|
->setTransactionType(HeraldRuleNameTransaction::TRANSACTIONTYPE)
|
2016-03-29 01:02:41 +02:00
|
|
|
->setNewValue($new_name);
|
Fix almost all remaining schemata issues
Summary:
Ref T1191. This fixes nearly every remaining blocker for utf8mb4 -- primarily, overlong keys.
Remaining issue is https://secure.phabricator.com/T1191#77467
Test Plan: I'll annotate inline.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley, hach-que
Maniphest Tasks: T6099, T6129, T6133, T6134, T6150, T6148, T6147, T6146, T6105, T1191
Differential Revision: https://secure.phabricator.com/D10601
2014-10-01 17:18:36 +02:00
|
|
|
|
2016-03-29 01:02:41 +02:00
|
|
|
try {
|
|
|
|
id(new HeraldRuleEditor())
|
|
|
|
->setActor($this->getViewer())
|
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->setContentSourceFromRequest($request)
|
|
|
|
->applyTransactions($rule, $xactions);
|
|
|
|
return array(null, null);
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
$errors[] = $ex->getMessage();
|
|
|
|
}
|
2011-10-22 03:34:38 +02:00
|
|
|
}
|
|
|
|
|
2016-03-29 01:02:41 +02:00
|
|
|
// mutate current rule, so it would be sent to the client in the right state
|
|
|
|
$rule->setMustMatchAll((int)$match_all);
|
|
|
|
$rule->setName($new_name);
|
2018-02-05 14:58:21 +01:00
|
|
|
$rule->setRepetitionPolicyStringConstant($repetition_policy);
|
2016-03-29 01:02:41 +02:00
|
|
|
$rule->attachConditions($conditions);
|
|
|
|
$rule->attachActions($actions);
|
|
|
|
|
2011-10-22 03:34:38 +02:00
|
|
|
return array($e_name, $errors);
|
|
|
|
}
|
|
|
|
|
2013-08-02 19:25:45 +02:00
|
|
|
private function setupEditorBehavior(
|
|
|
|
HeraldRule $rule,
|
|
|
|
array $handles,
|
|
|
|
HeraldAdapter $adapter) {
|
|
|
|
|
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
|
|
|
$all_rules = $this->loadRulesThisRuleMayDependUpon($rule);
|
2019-09-09 22:24:27 +02:00
|
|
|
$all_rules = msortv($all_rules, 'getEditorSortVector');
|
|
|
|
$all_rules = mpull($all_rules, 'getEditorDisplayName', 'getPHID');
|
2011-03-22 23:27:52 +01:00
|
|
|
|
2013-08-02 19:54:19 +02:00
|
|
|
$all_fields = $adapter->getFieldNameMap();
|
|
|
|
$all_conditions = $adapter->getConditionNameMap();
|
2013-08-02 20:32:50 +02:00
|
|
|
$all_actions = $adapter->getActionNameMap($rule->getRuleType());
|
2013-08-02 19:54:19 +02:00
|
|
|
|
2013-08-02 19:25:45 +02:00
|
|
|
$fields = $adapter->getFields();
|
2013-08-02 19:54:19 +02:00
|
|
|
$field_map = array_select_keys($all_fields, $fields);
|
2013-08-02 19:25:45 +02:00
|
|
|
|
2014-04-04 03:43:49 +02:00
|
|
|
// Populate any fields which exist in the rule but which we don't know the
|
|
|
|
// names of, so that saving a rule without touching anything doesn't change
|
|
|
|
// it.
|
|
|
|
foreach ($rule->getConditions() as $condition) {
|
2015-05-25 11:02:49 +02:00
|
|
|
$field_name = $condition->getFieldName();
|
|
|
|
|
|
|
|
if (empty($field_map[$field_name])) {
|
|
|
|
$field_map[$field_name] = pht('<Unknown Field "%s">', $field_name);
|
2014-04-04 03:43:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-02 20:32:50 +02:00
|
|
|
$actions = $adapter->getActions($rule->getRuleType());
|
|
|
|
$action_map = array_select_keys($all_actions, $actions);
|
|
|
|
|
2015-05-25 11:02:49 +02:00
|
|
|
// Populate any actions which exist in the rule but which we don't know the
|
|
|
|
// names of, so that saving a rule without touching anything doesn't change
|
|
|
|
// it.
|
|
|
|
foreach ($rule->getActions() as $action) {
|
|
|
|
$action_name = $action->getAction();
|
|
|
|
|
|
|
|
if (empty($action_map[$action_name])) {
|
|
|
|
$action_map[$action_name] = pht('<Unknown Action "%s">', $action_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-22 23:27:52 +01:00
|
|
|
$config_info = array();
|
2015-07-17 19:27:38 +02:00
|
|
|
$config_info['fields'] = $this->getFieldGroups($adapter, $field_map);
|
2013-08-02 19:54:19 +02:00
|
|
|
$config_info['conditions'] = $all_conditions;
|
2015-07-17 19:27:38 +02:00
|
|
|
$config_info['actions'] = $this->getActionGroups($adapter, $action_map);
|
2015-07-16 23:12:00 +02:00
|
|
|
$config_info['valueMap'] = array();
|
2013-08-02 20:32:50 +02:00
|
|
|
|
2015-07-16 23:13:13 +02:00
|
|
|
foreach ($field_map as $field => $name) {
|
2015-05-25 11:02:49 +02:00
|
|
|
try {
|
|
|
|
$field_conditions = $adapter->getConditionsForField($field);
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
$field_conditions = array(HeraldAdapter::CONDITION_UNCONDITIONALLY);
|
|
|
|
}
|
2013-08-02 19:54:19 +02:00
|
|
|
$config_info['conditionMap'][$field] = $field_conditions;
|
2011-03-22 23:27:52 +01:00
|
|
|
}
|
2013-08-02 19:54:19 +02:00
|
|
|
|
2015-07-16 23:13:13 +02:00
|
|
|
foreach ($field_map as $field => $fname) {
|
2013-08-02 19:54:19 +02:00
|
|
|
foreach ($config_info['conditionMap'][$field] as $condition) {
|
2015-07-16 23:12:00 +02:00
|
|
|
$value_key = $adapter->getValueTypeForFieldAndCondition(
|
2013-08-02 20:32:50 +02:00
|
|
|
$field,
|
|
|
|
$condition);
|
2015-07-16 23:12:00 +02:00
|
|
|
|
|
|
|
if ($value_key instanceof HeraldFieldValue) {
|
2015-07-16 23:12:44 +02:00
|
|
|
$value_key->setViewer($this->getViewer());
|
|
|
|
|
2015-07-16 23:12:00 +02:00
|
|
|
$spec = $value_key->getControlSpecificationDictionary();
|
|
|
|
$value_key = $value_key->getFieldValueKey();
|
|
|
|
$config_info['valueMap'][$value_key] = $spec;
|
|
|
|
}
|
|
|
|
|
|
|
|
$config_info['values'][$field][$condition] = $value_key;
|
2011-03-22 23:27:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-14 00:24:56 +01:00
|
|
|
$config_info['rule_type'] = $rule->getRuleType();
|
2011-03-22 23:27:52 +01:00
|
|
|
|
2015-07-17 19:27:38 +02:00
|
|
|
foreach ($action_map as $action => $name) {
|
2015-05-25 11:02:49 +02:00
|
|
|
try {
|
2015-07-16 23:12:23 +02:00
|
|
|
$value_key = $adapter->getValueTypeForAction(
|
2015-05-25 11:02:49 +02:00
|
|
|
$action,
|
|
|
|
$rule->getRuleType());
|
|
|
|
} catch (Exception $ex) {
|
2015-07-16 23:12:23 +02:00
|
|
|
$value_key = new HeraldEmptyFieldValue();
|
2015-05-25 11:02:49 +02:00
|
|
|
}
|
|
|
|
|
2015-07-16 23:12:23 +02:00
|
|
|
if ($value_key instanceof HeraldFieldValue) {
|
2015-07-16 23:12:44 +02:00
|
|
|
$value_key->setViewer($this->getViewer());
|
|
|
|
|
2015-07-16 23:12:23 +02:00
|
|
|
$spec = $value_key->getControlSpecificationDictionary();
|
|
|
|
$value_key = $value_key->getFieldValueKey();
|
|
|
|
$config_info['valueMap'][$value_key] = $spec;
|
|
|
|
}
|
|
|
|
|
|
|
|
$config_info['targets'][$action] = $value_key;
|
2011-03-22 23:27:52 +01:00
|
|
|
}
|
|
|
|
|
2016-03-22 17:08:26 +01:00
|
|
|
$default_group = head($config_info['fields']);
|
|
|
|
$default_field = head_key($default_group['options']);
|
|
|
|
$default_condition = head($config_info['conditionMap'][$default_field]);
|
|
|
|
$default_actions = head($config_info['actions']);
|
|
|
|
$default_action = head_key($default_actions['options']);
|
|
|
|
|
|
|
|
if ($rule->getConditions()) {
|
|
|
|
$serial_conditions = array();
|
|
|
|
foreach ($rule->getConditions() as $condition) {
|
|
|
|
$value = $adapter->getEditorValueForCondition(
|
|
|
|
$this->getViewer(),
|
|
|
|
$condition);
|
|
|
|
|
|
|
|
$serial_conditions[] = array(
|
|
|
|
$condition->getFieldName(),
|
|
|
|
$condition->getFieldCondition(),
|
|
|
|
$value,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$serial_conditions = array(
|
|
|
|
array($default_field, $default_condition, null),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($rule->getActions()) {
|
|
|
|
$serial_actions = array();
|
|
|
|
foreach ($rule->getActions() as $action) {
|
|
|
|
$value = $adapter->getEditorValueForAction(
|
|
|
|
$this->getViewer(),
|
|
|
|
$action);
|
|
|
|
|
|
|
|
$serial_actions[] = array(
|
|
|
|
$action->getAction(),
|
|
|
|
$value,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$serial_actions = array(
|
|
|
|
array($default_action, null),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-03-22 23:27:52 +01:00
|
|
|
Javelin::initBehavior(
|
|
|
|
'herald-rule-editor',
|
|
|
|
array(
|
2011-03-23 01:08:08 +01:00
|
|
|
'root' => 'herald-rule-edit-form',
|
2016-03-22 17:08:26 +01:00
|
|
|
'default' => array(
|
|
|
|
'field' => $default_field,
|
|
|
|
'condition' => $default_condition,
|
|
|
|
'action' => $default_action,
|
|
|
|
),
|
2011-10-22 03:34:38 +02:00
|
|
|
'conditions' => (object)$serial_conditions,
|
|
|
|
'actions' => (object)$serial_actions,
|
2015-07-16 23:12:44 +02:00
|
|
|
'template' => $this->buildTokenizerTemplates() + array(
|
2011-03-22 23:27:52 +01:00
|
|
|
'rules' => $all_rules,
|
|
|
|
),
|
|
|
|
'info' => $config_info,
|
|
|
|
));
|
2011-10-22 03:34:38 +02:00
|
|
|
}
|
2011-03-22 23:27:52 +01:00
|
|
|
|
2012-08-15 23:11:40 +02:00
|
|
|
private function loadHandlesForRule($rule) {
|
2011-10-22 03:34:38 +02:00
|
|
|
$phids = array();
|
2011-03-22 23:27:52 +01:00
|
|
|
|
2011-10-22 03:34:38 +02:00
|
|
|
foreach ($rule->getActions() as $action) {
|
|
|
|
if (!is_array($action->getTarget())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
foreach ($action->getTarget() as $target) {
|
|
|
|
$target = (array)$target;
|
|
|
|
foreach ($target as $phid) {
|
|
|
|
$phids[] = $phid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($rule->getConditions() as $condition) {
|
|
|
|
$value = $condition->getValue();
|
|
|
|
if (is_array($value)) {
|
|
|
|
foreach ($value as $phid) {
|
|
|
|
$phids[] = $phid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
$phids[] = $rule->getAuthorPHID();
|
2011-10-22 03:34:38 +02:00
|
|
|
|
2013-12-31 01:48:14 +01:00
|
|
|
if ($rule->isObjectRule()) {
|
|
|
|
$phids[] = $rule->getTriggerObjectPHID();
|
|
|
|
}
|
|
|
|
|
2012-09-05 04:02:56 +02:00
|
|
|
return $this->loadViewerHandles($phids);
|
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
|
|
|
}
|
2011-10-22 03:34:38 +02:00
|
|
|
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Render the selector for the "When (all of | any of) these conditions are
|
|
|
|
* met:" element.
|
|
|
|
*/
|
|
|
|
private function renderMustMatchSelector($rule) {
|
|
|
|
return AphrontFormSelectControl::renderSelectTag(
|
|
|
|
$rule->getMustMatchAll() ? 'all' : 'any',
|
|
|
|
array(
|
2013-05-20 17:24:07 +02:00
|
|
|
'all' => pht('all of'),
|
|
|
|
'any' => pht('any of'),
|
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
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'must_match',
|
|
|
|
));
|
2011-10-22 03:34:38 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the selector for "Take these actions (every time | only the first
|
|
|
|
* time) this rule matches..." element.
|
|
|
|
*/
|
2013-08-02 21:35:33 +02:00
|
|
|
private function renderRepetitionSelector($rule, HeraldAdapter $adapter) {
|
2018-01-25 05:03:06 +01:00
|
|
|
$repetition_policy = $rule->getRepetitionPolicyStringConstant();
|
2018-02-05 14:58:21 +01:00
|
|
|
$repetition_map = $this->getRepetitionOptionMap($adapter);
|
2013-08-02 21:35:33 +02:00
|
|
|
if (count($repetition_map) < 2) {
|
2018-02-05 14:58:21 +01:00
|
|
|
return head($repetition_map);
|
2011-10-22 03:34:38 +02:00
|
|
|
} else {
|
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
|
|
|
return AphrontFormSelectControl::renderSelectTag(
|
|
|
|
$repetition_policy,
|
2013-08-02 21:35:33 +02:00
|
|
|
$repetition_map,
|
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
|
|
|
array(
|
|
|
|
'name' => 'repetition_policy',
|
|
|
|
));
|
2011-10-22 03:34:38 +02:00
|
|
|
}
|
2011-03-22 23:27:52 +01:00
|
|
|
}
|
|
|
|
|
2018-02-05 14:58:21 +01:00
|
|
|
private function getRepetitionOptionMap(HeraldAdapter $adapter) {
|
|
|
|
$repetition_options = $adapter->getRepetitionOptions();
|
|
|
|
$repetition_names = HeraldRule::getRepetitionPolicySelectOptionMap();
|
|
|
|
return array_select_keys($repetition_names, $repetition_options);
|
|
|
|
}
|
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
|
|
|
|
2015-07-16 23:12:44 +02:00
|
|
|
protected function buildTokenizerTemplates() {
|
2011-03-23 04:41:02 +01:00
|
|
|
$template = new AphrontTokenizerTemplateView();
|
|
|
|
$template = $template->render();
|
2011-03-22 23:27:52 +01:00
|
|
|
return array(
|
2011-03-23 04:41:02 +01:00
|
|
|
'markup' => $template,
|
2011-03-22 23:27:52 +01:00
|
|
|
);
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load rules for the "Another Herald rule..." condition dropdown, which
|
|
|
|
* allows one rule to depend upon the success or failure of another rule.
|
|
|
|
*/
|
|
|
|
private function loadRulesThisRuleMayDependUpon(HeraldRule $rule) {
|
2013-08-02 15:38:17 +02:00
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
|
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
|
|
|
// Any rule can depend on a global rule.
|
|
|
|
$all_rules = id(new HeraldRuleQuery())
|
2013-08-02 15:38:17 +02:00
|
|
|
->setViewer($viewer)
|
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
|
|
|
->withRuleTypes(array(HeraldRuleTypeConfig::RULE_TYPE_GLOBAL))
|
|
|
|
->withContentTypes(array($rule->getContentType()))
|
|
|
|
->execute();
|
|
|
|
|
2013-12-27 22:17:10 +01:00
|
|
|
if ($rule->isObjectRule()) {
|
|
|
|
// Object rules may depend on other rules for the same object.
|
|
|
|
$all_rules += id(new HeraldRuleQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withRuleTypes(array(HeraldRuleTypeConfig::RULE_TYPE_OBJECT))
|
|
|
|
->withContentTypes(array($rule->getContentType()))
|
|
|
|
->withTriggerObjectPHIDs(array($rule->getTriggerObjectPHID()))
|
|
|
|
->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($rule->isPersonalRule()) {
|
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
|
|
|
// Personal rules may depend upon your other personal rules.
|
|
|
|
$all_rules += id(new HeraldRuleQuery())
|
2013-08-02 15:38:17 +02:00
|
|
|
->setViewer($viewer)
|
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
|
|
|
->withRuleTypes(array(HeraldRuleTypeConfig::RULE_TYPE_PERSONAL))
|
|
|
|
->withContentTypes(array($rule->getContentType()))
|
|
|
|
->withAuthorPHIDs(array($rule->getAuthorPHID()))
|
|
|
|
->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
// A rule can not depend upon itself.
|
|
|
|
unset($all_rules[$rule->getID()]);
|
|
|
|
|
|
|
|
return $all_rules;
|
|
|
|
}
|
|
|
|
|
2015-07-17 19:27:38 +02:00
|
|
|
private function getFieldGroups(HeraldAdapter $adapter, array $field_map) {
|
|
|
|
$group_map = array();
|
|
|
|
foreach ($field_map as $field_key => $field_name) {
|
|
|
|
$group_key = $adapter->getFieldGroupKey($field_key);
|
2019-09-12 21:54:08 +02:00
|
|
|
$group_map[$group_key][$field_key] = array(
|
|
|
|
'name' => $field_name,
|
|
|
|
'available' => $adapter->isFieldAvailable($field_key),
|
|
|
|
);
|
2015-07-17 19:27:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->getGroups(
|
|
|
|
$group_map,
|
|
|
|
HeraldFieldGroup::getAllFieldGroups());
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getActionGroups(HeraldAdapter $adapter, array $action_map) {
|
|
|
|
$group_map = array();
|
|
|
|
foreach ($action_map as $action_key => $action_name) {
|
|
|
|
$group_key = $adapter->getActionGroupKey($action_key);
|
2019-09-12 21:54:08 +02:00
|
|
|
$group_map[$group_key][$action_key] = array(
|
|
|
|
'name' => $action_name,
|
|
|
|
'available' => $adapter->isActionAvailable($action_key),
|
|
|
|
);
|
2015-07-17 19:27:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->getGroups(
|
|
|
|
$group_map,
|
|
|
|
HeraldActionGroup::getAllActionGroups());
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getGroups(array $item_map, array $group_list) {
|
|
|
|
assert_instances_of($group_list, 'HeraldGroup');
|
|
|
|
|
|
|
|
$groups = array();
|
|
|
|
foreach ($item_map as $group_key => $options) {
|
|
|
|
asort($options);
|
|
|
|
|
|
|
|
$group_object = idx($group_list, $group_key);
|
|
|
|
if ($group_object) {
|
|
|
|
$group_label = $group_object->getGroupLabel();
|
|
|
|
$group_order = $group_object->getSortKey();
|
|
|
|
} else {
|
|
|
|
$group_label = nonempty($group_key, pht('Other'));
|
|
|
|
$group_order = 'Z';
|
|
|
|
}
|
|
|
|
|
|
|
|
$groups[] = array(
|
|
|
|
'label' => $group_label,
|
|
|
|
'options' => $options,
|
|
|
|
'order' => $group_order,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return array_values(isort($groups, 'order'));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-22 23:27:52 +01:00
|
|
|
}
|