1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +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:
Bob Trahan 2013-09-26 15:04:55 -07:00
parent 477d4e9db1
commit fb4c9b6345
3 changed files with 92 additions and 18 deletions

View file

@ -39,12 +39,14 @@ abstract class HeraldAdapter {
const CONDITION_NOT_EXISTS = '!exists';
const CONDITION_REGEXP_PAIR = 'regexp-pair';
const ACTION_ADD_CC = 'addcc';
const ACTION_REMOVE_CC = 'remcc';
const ACTION_EMAIL = 'email';
const ACTION_NOTHING = 'nothing';
const ACTION_AUDIT = 'audit';
const ACTION_FLAG = 'flag';
const ACTION_ADD_CC = 'addcc';
const ACTION_REMOVE_CC = 'remcc';
const ACTION_EMAIL = 'email';
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';
@ -440,21 +442,25 @@ abstract class HeraldAdapter {
switch ($rule_type) {
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
return array(
self::ACTION_NOTHING => pht('Do nothing'),
self::ACTION_ADD_CC => pht('Add emails to CC'),
self::ACTION_REMOVE_CC => pht('Remove emails from CC'),
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_NOTHING => pht('Do nothing'),
self::ACTION_ADD_CC => pht('Add emails to CC'),
self::ACTION_REMOVE_CC => pht('Remove emails from CC'),
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(
self::ACTION_NOTHING => pht('Do nothing'),
self::ACTION_ADD_CC => pht('Add me to CC'),
self::ACTION_REMOVE_CC => pht('Remove me from CC'),
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_NOTHING => pht('Do nothing'),
self::ACTION_ADD_CC => pht('Add me to CC'),
self::ACTION_REMOVE_CC => pht('Remove me from CC'),
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}'.");
}

View file

@ -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}'.");
}

View file

@ -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();
}
}