1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-10-19 15:18:51 +02:00
phorge-phorge/resources/sql/patches/098.heraldruletypemigration.php
awyler 6080d74112 Created personal vs. global herald rule distingtion
Summary:
A personal rule only has actions targeting the owner.  Likewise, only they can
edit the rule. OTOH, a global may affect any target and is editable by anyone.

There are no new action types.  Instead, type of the rule modifies the available
targets and the messaging in the ui.  This is beneficial because herald rule
adapters don't need to be aware of the difference between emailing the owner of
a personal rule and emailing an arbitrary user.

This diff sets up the logic and ui for creating personal/global rules.  All
existing rules have been defaulted to global.

TODO: Filter all existing rules into personal/global
TODO: Create a UI for surfacing (relevant?) global rules.

Test Plan:
1. Created a personal rule to email myself.  Created a dumby revision satisfying
the conditions of that rule.  Verified that I recieved a herald email.
2. Removed my adminship, change the owner of a personal rule. verified that I
couldn't edit the rule.
3.Changed rule type to global. verified that I could edit the rule.
4. Verified that admins can edit both global and personal rules.

Reviewers: epriestley, jungejason

Reviewed By: epriestley

CC: aran, zizzy

Differential Revision: https://secure.phabricator.com/D1449
2012-01-19 11:21:49 -08:00

62 lines
1.8 KiB
PHP

<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
echo "Checking for rules that can be converted to 'personal'. ";
$rules = id(new HeraldRule())->loadAll();
foreach ($rules as $rule) {
if ($rule->getRuleType() !== HeraldRuleTypeConfig::RULE_TYPE_PERSONAL) {
$actions = $rule->loadActions();
$can_be_personal = true;
foreach ($actions as $action) {
$target = $action->getTarget();
if (is_array($target)) {
if (count($target) > 1) {
$can_be_personal = false;
break;
} else {
$targetPHID = head($target);
if ($targetPHID !== $rule->getAuthorPHID()) {
$can_be_personal = false;
break;
}
}
} else if ($target) {
if ($target !== $rule->getAuthorPHID()) {
$can_be_personal = false;
break;
}
}
}
if ($can_be_personal) {
$rule->setRuleType(HeraldRuleTypeConfig::RULE_TYPE_PERSONAL);
queryfx(
$rule->establishConnection('w'),
'UPDATE %T SET ruleType = %s WHERE id = %d',
$rule->getTableName(),
$rule->getRuleType(),
$rule->getID());
echo "Setting rule '" . $rule->getName() . "' to personal. ";
}
}
}
echo "Done. ";