mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-29 18:22:41 +01:00
Add a "Remove flag" action to Herald
Summary: Fixes T13409. This is a companion to the existing "Mark with flag" rule. Test Plan: Used a "remove flag" rule on an object with no flag (not removed), the right type of flag (removed), and a different type of flag (not removed). Maniphest Tasks: T13409 Differential Revision: https://secure.phabricator.com/D20796
This commit is contained in:
parent
d965d9a669
commit
4547714463
4 changed files with 104 additions and 14 deletions
|
@ -3438,8 +3438,10 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorFlagDeleteController' => 'applications/flag/controller/PhabricatorFlagDeleteController.php',
|
'PhabricatorFlagDeleteController' => 'applications/flag/controller/PhabricatorFlagDeleteController.php',
|
||||||
'PhabricatorFlagDestructionEngineExtension' => 'applications/flag/engineextension/PhabricatorFlagDestructionEngineExtension.php',
|
'PhabricatorFlagDestructionEngineExtension' => 'applications/flag/engineextension/PhabricatorFlagDestructionEngineExtension.php',
|
||||||
'PhabricatorFlagEditController' => 'applications/flag/controller/PhabricatorFlagEditController.php',
|
'PhabricatorFlagEditController' => 'applications/flag/controller/PhabricatorFlagEditController.php',
|
||||||
|
'PhabricatorFlagHeraldAction' => 'applications/flag/herald/PhabricatorFlagHeraldAction.php',
|
||||||
'PhabricatorFlagListController' => 'applications/flag/controller/PhabricatorFlagListController.php',
|
'PhabricatorFlagListController' => 'applications/flag/controller/PhabricatorFlagListController.php',
|
||||||
'PhabricatorFlagQuery' => 'applications/flag/query/PhabricatorFlagQuery.php',
|
'PhabricatorFlagQuery' => 'applications/flag/query/PhabricatorFlagQuery.php',
|
||||||
|
'PhabricatorFlagRemoveFlagHeraldAction' => 'applications/flag/herald/PhabricatorFlagRemoveFlagHeraldAction.php',
|
||||||
'PhabricatorFlagSearchEngine' => 'applications/flag/query/PhabricatorFlagSearchEngine.php',
|
'PhabricatorFlagSearchEngine' => 'applications/flag/query/PhabricatorFlagSearchEngine.php',
|
||||||
'PhabricatorFlagSelectControl' => 'applications/flag/view/PhabricatorFlagSelectControl.php',
|
'PhabricatorFlagSelectControl' => 'applications/flag/view/PhabricatorFlagSelectControl.php',
|
||||||
'PhabricatorFlaggableInterface' => 'applications/flag/interface/PhabricatorFlaggableInterface.php',
|
'PhabricatorFlaggableInterface' => 'applications/flag/interface/PhabricatorFlaggableInterface.php',
|
||||||
|
@ -9799,7 +9801,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorFlagDAO',
|
'PhabricatorFlagDAO',
|
||||||
'PhabricatorPolicyInterface',
|
'PhabricatorPolicyInterface',
|
||||||
),
|
),
|
||||||
'PhabricatorFlagAddFlagHeraldAction' => 'HeraldAction',
|
'PhabricatorFlagAddFlagHeraldAction' => 'PhabricatorFlagHeraldAction',
|
||||||
'PhabricatorFlagColor' => 'PhabricatorFlagConstants',
|
'PhabricatorFlagColor' => 'PhabricatorFlagConstants',
|
||||||
'PhabricatorFlagConstants' => 'Phobject',
|
'PhabricatorFlagConstants' => 'Phobject',
|
||||||
'PhabricatorFlagController' => 'PhabricatorController',
|
'PhabricatorFlagController' => 'PhabricatorController',
|
||||||
|
@ -9807,8 +9809,10 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorFlagDeleteController' => 'PhabricatorFlagController',
|
'PhabricatorFlagDeleteController' => 'PhabricatorFlagController',
|
||||||
'PhabricatorFlagDestructionEngineExtension' => 'PhabricatorDestructionEngineExtension',
|
'PhabricatorFlagDestructionEngineExtension' => 'PhabricatorDestructionEngineExtension',
|
||||||
'PhabricatorFlagEditController' => 'PhabricatorFlagController',
|
'PhabricatorFlagEditController' => 'PhabricatorFlagController',
|
||||||
|
'PhabricatorFlagHeraldAction' => 'HeraldAction',
|
||||||
'PhabricatorFlagListController' => 'PhabricatorFlagController',
|
'PhabricatorFlagListController' => 'PhabricatorFlagController',
|
||||||
'PhabricatorFlagQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
'PhabricatorFlagQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
|
'PhabricatorFlagRemoveFlagHeraldAction' => 'PhabricatorFlagHeraldAction',
|
||||||
'PhabricatorFlagSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
'PhabricatorFlagSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||||
'PhabricatorFlagSelectControl' => 'AphrontFormControl',
|
'PhabricatorFlagSelectControl' => 'AphrontFormControl',
|
||||||
'PhabricatorFlaggableInterface' => 'PhabricatorPHIDInterface',
|
'PhabricatorFlaggableInterface' => 'PhabricatorPHIDInterface',
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
final class PhabricatorFlagAddFlagHeraldAction extends HeraldAction {
|
final class PhabricatorFlagAddFlagHeraldAction
|
||||||
|
extends PhabricatorFlagHeraldAction {
|
||||||
|
|
||||||
const ACTIONCONST = 'flag';
|
const ACTIONCONST = 'flag';
|
||||||
|
|
||||||
|
@ -11,18 +12,6 @@ final class PhabricatorFlagAddFlagHeraldAction extends HeraldAction {
|
||||||
return pht('Mark with flag');
|
return pht('Mark with flag');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getActionGroupKey() {
|
|
||||||
return HeraldSupportActionGroup::ACTIONGROUPKEY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function supportsObject($object) {
|
|
||||||
return ($object instanceof PhabricatorFlaggableInterface);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function supportsRuleType($rule_type) {
|
|
||||||
return ($rule_type == HeraldRuleTypeConfig::RULE_TYPE_PERSONAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function applyEffect($object, HeraldEffect $effect) {
|
public function applyEffect($object, HeraldEffect $effect) {
|
||||||
$phid = $this->getAdapter()->getPHID();
|
$phid = $this->getAdapter()->getPHID();
|
||||||
$rule = $effect->getRule();
|
$rule = $effect->getRule();
|
||||||
|
|
18
src/applications/flag/herald/PhabricatorFlagHeraldAction.php
Normal file
18
src/applications/flag/herald/PhabricatorFlagHeraldAction.php
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
abstract class PhabricatorFlagHeraldAction
|
||||||
|
extends HeraldAction {
|
||||||
|
|
||||||
|
public function getActionGroupKey() {
|
||||||
|
return HeraldSupportActionGroup::ACTIONGROUPKEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function supportsObject($object) {
|
||||||
|
return ($object instanceof PhabricatorFlaggableInterface);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function supportsRuleType($rule_type) {
|
||||||
|
return ($rule_type === HeraldRuleTypeConfig::RULE_TYPE_PERSONAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,79 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorFlagRemoveFlagHeraldAction
|
||||||
|
extends PhabricatorFlagHeraldAction {
|
||||||
|
|
||||||
|
const ACTIONCONST = 'unflag';
|
||||||
|
|
||||||
|
const DO_UNFLAG = 'do.unflag';
|
||||||
|
const DO_IGNORE_UNFLAG = 'do.ignore-unflag';
|
||||||
|
|
||||||
|
public function getHeraldActionName() {
|
||||||
|
return pht('Remove flag');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function applyEffect($object, HeraldEffect $effect) {
|
||||||
|
$phid = $this->getAdapter()->getPHID();
|
||||||
|
$rule = $effect->getRule();
|
||||||
|
$author = $rule->getAuthor();
|
||||||
|
|
||||||
|
$flag = PhabricatorFlagQuery::loadUserFlag($author, $phid);
|
||||||
|
if (!$flag) {
|
||||||
|
$this->logEffect(self::DO_IGNORE_UNFLAG, null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($flag->getColor() !== $effect->getTarget()) {
|
||||||
|
$this->logEffect(self::DO_IGNORE_UNFLAG, $flag->getColor());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$flag->delete();
|
||||||
|
|
||||||
|
$this->logEffect(self::DO_UNFLAG, $flag->getColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHeraldActionValueType() {
|
||||||
|
return id(new HeraldSelectFieldValue())
|
||||||
|
->setKey('flag.color')
|
||||||
|
->setOptions(PhabricatorFlagColor::getColorNameMap())
|
||||||
|
->setDefault(PhabricatorFlagColor::COLOR_BLUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getActionEffectMap() {
|
||||||
|
return array(
|
||||||
|
self::DO_IGNORE_UNFLAG => array(
|
||||||
|
'icon' => 'fa-times',
|
||||||
|
'color' => 'grey',
|
||||||
|
'name' => pht('Did Not Remove Flag'),
|
||||||
|
),
|
||||||
|
self::DO_UNFLAG => array(
|
||||||
|
'icon' => 'fa-flag',
|
||||||
|
'name' => pht('Removed Flag'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renderActionDescription($value) {
|
||||||
|
$color = PhabricatorFlagColor::getColorName($value);
|
||||||
|
return pht('Remove %s flag.', $color);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function renderActionEffectDescription($type, $data) {
|
||||||
|
switch ($type) {
|
||||||
|
case self::DO_IGNORE_UNFLAG:
|
||||||
|
if (!$data) {
|
||||||
|
return pht('Not marked with any flag.');
|
||||||
|
} else {
|
||||||
|
return pht(
|
||||||
|
'Marked with flag of the wrong color ("%s").',
|
||||||
|
PhabricatorFlagColor::getColorName($data));
|
||||||
|
}
|
||||||
|
case self::DO_UNFLAG:
|
||||||
|
return pht(
|
||||||
|
'Removed "%s" flag.',
|
||||||
|
PhabricatorFlagColor::getColorName($data));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue