mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-30 09:20:58 +01:00
Maniphest + Herald - add support for assigning tasks and adding projects
Summary: This ends up living in HeraldAdapter even though its "task only" stuff. Reason being There are 4 or 5 functions that have little hooks; see diff. Ref T1638. Test Plan: made a rule to assign tasks to me if made on web - great success. made a rule to assign tasks to other guy and add a project if title contained "foobar" - great success, including some confusion as ther two herald rules fought each other for task ownership. Reviewers: epriestley Reviewed By: epriestley CC: Korvin, aran Maniphest Tasks: T1638 Differential Revision: https://secure.phabricator.com/D7146
This commit is contained in:
parent
477d4e9db1
commit
fb4c9b6345
3 changed files with 92 additions and 18 deletions
|
@ -45,6 +45,8 @@ abstract class HeraldAdapter {
|
|||
const ACTION_NOTHING = 'nothing';
|
||||
const ACTION_AUDIT = 'audit';
|
||||
const ACTION_FLAG = 'flag';
|
||||
const ACTION_ASSIGN_TASK = 'assigntask';
|
||||
const ACTION_ADD_PROJECTS = 'addprojects';
|
||||
|
||||
const VALUE_TEXT = 'text';
|
||||
const VALUE_NONE = 'none';
|
||||
|
@ -446,6 +448,8 @@ abstract class HeraldAdapter {
|
|||
self::ACTION_EMAIL => pht('Send an email to'),
|
||||
self::ACTION_AUDIT => pht('Trigger an Audit by'),
|
||||
self::ACTION_FLAG => pht('Mark with flag'),
|
||||
self::ACTION_ASSIGN_TASK => pht('Assign task to'),
|
||||
self::ACTION_ADD_PROJECTS => pht('Add projects'),
|
||||
);
|
||||
case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
|
||||
return array(
|
||||
|
@ -455,6 +459,8 @@ abstract class HeraldAdapter {
|
|||
self::ACTION_EMAIL => pht('Send me an email'),
|
||||
self::ACTION_AUDIT => pht('Trigger an Audit by me'),
|
||||
self::ACTION_FLAG => pht('Mark with flag'),
|
||||
self::ACTION_ASSIGN_TASK => pht('Assign task to me.'),
|
||||
self::ACTION_ADD_PROJECTS => pht('Add projects'),
|
||||
);
|
||||
default:
|
||||
throw new Exception("Unknown rule type '{$rule_type}'!");
|
||||
|
@ -479,6 +485,7 @@ abstract class HeraldAdapter {
|
|||
case self::ACTION_ADD_CC:
|
||||
case self::ACTION_REMOVE_CC:
|
||||
case self::ACTION_AUDIT:
|
||||
case self::ACTION_ASSIGN_TASK:
|
||||
// For personal rules, force these actions to target the rule owner.
|
||||
$target = array($author_phid);
|
||||
break;
|
||||
|
@ -571,9 +578,12 @@ abstract class HeraldAdapter {
|
|||
case self::ACTION_EMAIL:
|
||||
case self::ACTION_NOTHING:
|
||||
case self::ACTION_AUDIT:
|
||||
case self::ACTION_ASSIGN_TASK:
|
||||
return self::VALUE_NONE;
|
||||
case self::ACTION_FLAG:
|
||||
return self::VALUE_FLAG_COLOR;
|
||||
case self::ACTION_ADD_PROJECTS:
|
||||
return self::VALUE_PROJECT;
|
||||
default:
|
||||
throw new Exception("Unknown or invalid action '{$action}'.");
|
||||
}
|
||||
|
@ -586,9 +596,12 @@ abstract class HeraldAdapter {
|
|||
case self::ACTION_NOTHING:
|
||||
return self::VALUE_NONE;
|
||||
case self::ACTION_AUDIT:
|
||||
case self::ACTION_ADD_PROJECTS:
|
||||
return self::VALUE_PROJECT;
|
||||
case self::ACTION_FLAG:
|
||||
return self::VALUE_FLAG_COLOR;
|
||||
case self::ACTION_ASSIGN_TASK:
|
||||
return self::VALUE_USER;
|
||||
default:
|
||||
throw new Exception("Unknown or invalid action '{$action}'.");
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter {
|
|||
|
||||
private $task;
|
||||
private $ccPHIDs = array();
|
||||
private $assignPHID;
|
||||
private $projectPHIDs = array();
|
||||
|
||||
public function setTask(ManiphestTask $task) {
|
||||
$this->task = $task;
|
||||
|
@ -24,6 +26,22 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter {
|
|||
return $this->ccPHIDs;
|
||||
}
|
||||
|
||||
public function setAssignPHID($assign_phid) {
|
||||
$this->assignPHID = $assign_phid;
|
||||
return $this;
|
||||
}
|
||||
public function getAssignPHID() {
|
||||
return $this->assignPHID;
|
||||
}
|
||||
|
||||
public function setProjectPHIDs(array $project_phids) {
|
||||
$this->projectPHIDs = $project_phids;
|
||||
return $this;
|
||||
}
|
||||
public function getProjectPHIDs() {
|
||||
return $this->projectPHIDs;
|
||||
}
|
||||
|
||||
public function getAdapterContentName() {
|
||||
return pht('Maniphest Tasks');
|
||||
}
|
||||
|
@ -43,12 +61,15 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter {
|
|||
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
|
||||
return array(
|
||||
self::ACTION_ADD_CC,
|
||||
self::ACTION_ASSIGN_TASK,
|
||||
self::ACTION_ADD_PROJECTS,
|
||||
self::ACTION_NOTHING,
|
||||
);
|
||||
case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
|
||||
return array(
|
||||
self::ACTION_ADD_CC,
|
||||
self::ACTION_FLAG,
|
||||
self::ACTION_ASSIGN_TASK,
|
||||
self::ACTION_NOTHING,
|
||||
);
|
||||
}
|
||||
|
@ -106,6 +127,26 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter {
|
|||
$effect,
|
||||
$this->getTask()->getPHID());
|
||||
break;
|
||||
case self::ACTION_ASSIGN_TASK:
|
||||
$target_array = $effect->getTarget();
|
||||
$assign_phid = reset($target_array);
|
||||
$this->setAssignPHID($assign_phid);
|
||||
$result[] = new HeraldApplyTranscript(
|
||||
$effect,
|
||||
true,
|
||||
pht('Assigned task.'));
|
||||
break;
|
||||
case self::ACTION_ADD_PROJECTS:
|
||||
$add_projects = array();
|
||||
foreach ($effect->getTarget() as $phid) {
|
||||
$add_projects[$phid] = true;
|
||||
}
|
||||
$this->setProjectPHIDs(array_keys($add_projects));
|
||||
$result[] = new HeraldApplyTranscript(
|
||||
$effect,
|
||||
true,
|
||||
pht('Added projects.'));
|
||||
break;
|
||||
default:
|
||||
throw new Exception("No rules to handle action '{$action}'.");
|
||||
}
|
||||
|
|
|
@ -217,11 +217,31 @@ final class ManiphestTransactionEditorPro
|
|||
HeraldAdapter $adapter,
|
||||
HeraldTranscript $transcript) {
|
||||
|
||||
$save_again = false;
|
||||
$cc_phids = $adapter->getCcPHIDs();
|
||||
if ($cc_phids) {
|
||||
$existing_cc = $object->getCCPHIDs();
|
||||
$new_cc = array_unique(array_merge($cc_phids, $existing_cc));
|
||||
$object->setCCPHIDs($new_cc);
|
||||
$save_again = true;
|
||||
}
|
||||
|
||||
$assign_phid = $adapter->getAssignPHID();
|
||||
if ($assign_phid) {
|
||||
$object->setOwnerPHID($assign_phid);
|
||||
$save_again = true;
|
||||
}
|
||||
|
||||
$project_phids = $adapter->getProjectPHIDs();
|
||||
if ($project_phids) {
|
||||
$existing_projects = $object->getProjectPHIDs();
|
||||
$new_projects = array_unique(
|
||||
array_merge($project_phids, $existing_projects));
|
||||
$object->setProjectPHIDs($new_projects);
|
||||
$save_again = true;
|
||||
}
|
||||
|
||||
if ($save_again) {
|
||||
$object->save();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue