Herald actions: Allow setting subtype on Maniphest tasks

Summary:
https://secure.phabricator.com/T12314 introduced task subtypes. Allow Herald rules which change/set the subtype of a task.
Code originally written by @20after4 for Wikimedia.

Closes T16022

Test Plan:
1. Have the default subtype configuration with three types under http://phorge.localhost/config/edit/maniphest.subtypes/ defined in src/applications/maniphest/config/PhabricatorManiphestConfigOptions.php
2. Go to http://phorge.localhost/herald/edit/?content_type=HeraldManiphestTaskAdapter&rule_type=global
3. Under "Action", select the new "Change subtype to" option. Test the subtype search by clicking the magnifier icon, set up a Herald rule to test execution.
4. Remove the config for http://phorge.localhost/config/edit/maniphest.subtypes/
5. Repeat step 3, no explosions, default "Task" subtype still exists after removing the config.

Reviewers: O1 Blessed Committers, valerio.bozzolan

Reviewed By: O1 Blessed Committers, valerio.bozzolan

Subscribers: tobiaswiese, valerio.bozzolan, Matthew, 20after4, Cigaryno

Maniphest Tasks: T16022

Differential Revision: https://we.phorge.it/D25913
This commit is contained in:
Andre Klapper 2025-03-22 11:13:17 +01:00
parent fcd6a4c28a
commit 56797b17ed
2 changed files with 76 additions and 0 deletions

View file

@ -5899,6 +5899,7 @@ phutil_register_library_map(array(
'RemarkupValue' => 'applications/remarkup/RemarkupValue.php',
'RepositoryConduitAPIMethod' => 'applications/repository/conduit/RepositoryConduitAPIMethod.php',
'RepositoryQueryConduitAPIMethod' => 'applications/repository/conduit/RepositoryQueryConduitAPIMethod.php',
'SetSubtypeHeraldAction' => 'applications/maniphest/herald/SetSubtypeHeraldAction.php',
'ShellLogView' => 'applications/harbormaster/view/ShellLogView.php',
'SlowvoteConduitAPIMethod' => 'applications/slowvote/conduit/SlowvoteConduitAPIMethod.php',
'SlowvoteEmbedView' => 'applications/slowvote/view/SlowvoteEmbedView.php',
@ -12836,6 +12837,7 @@ phutil_register_library_map(array(
'RemarkupValue' => 'Phobject',
'RepositoryConduitAPIMethod' => 'ConduitAPIMethod',
'RepositoryQueryConduitAPIMethod' => 'RepositoryConduitAPIMethod',
'SetSubtypeHeraldAction' => 'HeraldAction',
'ShellLogView' => 'AphrontView',
'SlowvoteConduitAPIMethod' => 'ConduitAPIMethod',
'SlowvoteEmbedView' => 'AphrontView',

View file

@ -0,0 +1,74 @@
<?php
final class SetSubtypeHeraldAction extends HeraldAction {
const ACTIONCONST = 'maniphest.subtype';
const DO_SUBTYPE = 'do.subtype';
public function getActionGroupKey() {
return HeraldApplicationActionGroup::ACTIONGROUPKEY;
}
public function supportsObject($object) {
return $object instanceof ManiphestTask;
}
public function supportsRuleType($rule_type) {
return $rule_type == HeraldRuleTypeConfig::RULE_TYPE_GLOBAL;
}
public function getActionKey() {
return self::ACTIONCONST;
}
public function getHeraldActionName() {
return pht('Change subtype to');
}
public function renderActionDescription($value) {
$type = head($value);
return pht('Change subtype to "%s"', $type);
}
public function getHeraldActionStandardType() {
return self::STANDARD_PHID_LIST;
}
protected function getDatasource() {
return id(new ManiphestTaskSubtypeDatasource())
->setLimit(1);
}
protected function getDatasourceValueMap() {
$map = id(new ManiphestTask())->newEditEngineSubtypeMap();
return $map->getSubtypes();
}
public function applyEffect($object, HeraldEffect $effect) {
$new_subtype = head($effect->getTarget());
$adapter = $this->getAdapter();
$adapter->queueTransaction(id(new ManiphestTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_SUBTYPE)
->setNewValue($new_subtype));
$this->logEffect(self::DO_SUBTYPE, $new_subtype);
}
protected function getActionEffectMap() {
return array(
self::DO_SUBTYPE => array(
'icon' => 'fa-pencil',
'color' => 'green',
'name' => pht('Changed Subtype'),
),
);
}
protected function renderActionEffectDescription($type, $data) {
switch ($type) {
case self::DO_SUBTYPE:
return pht('Change subtype to "%s."', $data);
}
}
}