From a76939066b01b9dd39ff44a8d3aa3165dc7b3eaf Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Tue, 16 Sep 2014 16:35:43 +0200 Subject: Add more events and notifications for tasks --- app/Action/Base.php | 11 +++++++++ app/Action/TaskAssignCategoryColor.php | 2 +- app/Action/TaskAssignColorCategory.php | 2 +- app/Action/TaskAssignColorUser.php | 2 +- app/Action/TaskAssignCurrentUser.php | 2 +- app/Action/TaskAssignSpecificUser.php | 2 +- app/Event/BaseNotificationListener.php | 11 +++++++++ app/Event/CommentHistoryListener.php | 11 +++++++++ app/Event/ProjectModificationDate.php | 11 +++++++++ app/Event/SubtaskHistoryListener.php | 11 +++++++++ app/Event/TaskHistoryListener.php | 11 +++++++++ app/Event/WebhookListener.php | 11 +++++++++ app/Locales/fr_FR/translations.php | 6 +++++ app/Model/Action.php | 1 + app/Model/Notification.php | 13 ++++++++++- app/Model/Task.php | 27 ++++++++++++++-------- app/Model/TaskHistory.php | 2 ++ app/Templates/event_task_assignee_change.php | 6 +++++ .../notification_task_assignee_change.php | 20 ++++++++++++++++ app/Templates/notification_task_move_column.php | 11 +++++++++ app/Templates/notification_task_move_position.php | 11 +++++++++ docs/automatic-actions.markdown | 3 ++- tests/units/TaskTest.php | 4 ++++ 23 files changed, 174 insertions(+), 17 deletions(-) create mode 100644 app/Templates/event_task_assignee_change.php create mode 100644 app/Templates/notification_task_assignee_change.php create mode 100644 app/Templates/notification_task_move_column.php create mode 100644 app/Templates/notification_task_move_position.php diff --git a/app/Action/Base.php b/app/Action/Base.php index 14b0a3c0..5b7b3502 100644 --- a/app/Action/Base.php +++ b/app/Action/Base.php @@ -139,4 +139,15 @@ abstract class Base implements Listener return false; } + + /** + * Return class information + * + * @access public + * @return string + */ + public function __toString() + { + return get_called_class(); + } } diff --git a/app/Action/TaskAssignCategoryColor.php b/app/Action/TaskAssignCategoryColor.php index 19d7fa9c..3e5b9304 100644 --- a/app/Action/TaskAssignCategoryColor.php +++ b/app/Action/TaskAssignCategoryColor.php @@ -75,7 +75,7 @@ class TaskAssignCategoryColor extends Base $this->task->update(array( 'id' => $data['task_id'], 'category_id' => $this->getParam('category_id'), - )); + ), false); return true; } diff --git a/app/Action/TaskAssignColorCategory.php b/app/Action/TaskAssignColorCategory.php index 4304d084..e7aad01f 100644 --- a/app/Action/TaskAssignColorCategory.php +++ b/app/Action/TaskAssignColorCategory.php @@ -75,7 +75,7 @@ class TaskAssignColorCategory extends Base $this->task->update(array( 'id' => $data['task_id'], 'color_id' => $this->getParam('color_id'), - )); + ), false); return true; } diff --git a/app/Action/TaskAssignColorUser.php b/app/Action/TaskAssignColorUser.php index 9ff140b3..dad46bf9 100644 --- a/app/Action/TaskAssignColorUser.php +++ b/app/Action/TaskAssignColorUser.php @@ -75,7 +75,7 @@ class TaskAssignColorUser extends Base $this->task->update(array( 'id' => $data['task_id'], 'color_id' => $this->getParam('color_id'), - )); + ), false); return true; } diff --git a/app/Action/TaskAssignCurrentUser.php b/app/Action/TaskAssignCurrentUser.php index 1c038966..8ae87ff9 100644 --- a/app/Action/TaskAssignCurrentUser.php +++ b/app/Action/TaskAssignCurrentUser.php @@ -85,7 +85,7 @@ class TaskAssignCurrentUser extends Base $this->task->update(array( 'id' => $data['task_id'], 'owner_id' => $this->acl->getUserId(), - )); + ), false); return true; } diff --git a/app/Action/TaskAssignSpecificUser.php b/app/Action/TaskAssignSpecificUser.php index 8c379bcc..a903327b 100644 --- a/app/Action/TaskAssignSpecificUser.php +++ b/app/Action/TaskAssignSpecificUser.php @@ -75,7 +75,7 @@ class TaskAssignSpecificUser extends Base $this->task->update(array( 'id' => $data['task_id'], 'owner_id' => $this->getParam('user_id'), - )); + ), false); return true; } diff --git a/app/Event/BaseNotificationListener.php b/app/Event/BaseNotificationListener.php index 6c1728cb..fdabaf57 100644 --- a/app/Event/BaseNotificationListener.php +++ b/app/Event/BaseNotificationListener.php @@ -51,6 +51,17 @@ abstract class BaseNotificationListener implements Listener $this->notification = $notification; } + /** + * Return class information + * + * @access public + * @return string + */ + public function __toString() + { + return get_called_class(); + } + /** * Execute the action * diff --git a/app/Event/CommentHistoryListener.php b/app/Event/CommentHistoryListener.php index a89ecbae..e5e92b01 100644 --- a/app/Event/CommentHistoryListener.php +++ b/app/Event/CommentHistoryListener.php @@ -32,6 +32,17 @@ class CommentHistoryListener implements Listener $this->model = $model; } + /** + * Return class information + * + * @access public + * @return string + */ + public function __toString() + { + return get_called_class(); + } + /** * Execute the action * diff --git a/app/Event/ProjectModificationDate.php b/app/Event/ProjectModificationDate.php index 8fbaee73..d0d1e846 100644 --- a/app/Event/ProjectModificationDate.php +++ b/app/Event/ProjectModificationDate.php @@ -34,6 +34,17 @@ class ProjectModificationDate implements Listener $this->project = $project; } + /** + * Return class information + * + * @access public + * @return string + */ + public function __toString() + { + return get_called_class(); + } + /** * Execute the action * diff --git a/app/Event/SubtaskHistoryListener.php b/app/Event/SubtaskHistoryListener.php index e859828c..8cc7a7fd 100644 --- a/app/Event/SubtaskHistoryListener.php +++ b/app/Event/SubtaskHistoryListener.php @@ -32,6 +32,17 @@ class SubtaskHistoryListener implements Listener $this->model = $model; } + /** + * Return class information + * + * @access public + * @return string + */ + public function __toString() + { + return get_called_class(); + } + /** * Execute the action * diff --git a/app/Event/TaskHistoryListener.php b/app/Event/TaskHistoryListener.php index c8a880e8..d963fa71 100644 --- a/app/Event/TaskHistoryListener.php +++ b/app/Event/TaskHistoryListener.php @@ -32,6 +32,17 @@ class TaskHistoryListener implements Listener $this->model = $model; } + /** + * Return class information + * + * @access public + * @return string + */ + public function __toString() + { + return get_called_class(); + } + /** * Execute the action * diff --git a/app/Event/WebhookListener.php b/app/Event/WebhookListener.php index 4668b66e..c2f6d56a 100644 --- a/app/Event/WebhookListener.php +++ b/app/Event/WebhookListener.php @@ -42,6 +42,17 @@ class WebhookListener implements Listener $this->webhook = $webhook; } + /** + * Return class information + * + * @access public + * @return string + */ + public function __toString() + { + return get_called_class(); + } + /** * Execute the action * diff --git a/app/Locales/fr_FR/translations.php b/app/Locales/fr_FR/translations.php index 2cb65b76..5084477a 100644 --- a/app/Locales/fr_FR/translations.php +++ b/app/Locales/fr_FR/translations.php @@ -496,4 +496,10 @@ return array( 'Activity' => 'Activité', 'Default values are "%s"' => 'Les valeurs par défaut sont « %s »', 'Default columns for new projects (Comma-separated)' => 'Colonnes par défaut pour les nouveaux projets (séparé par des virgules)', + 'Task assignee change' => 'Modification de la personne assignée sur une tâche', + '%s change the assignee of the task #%d' => '%s a changé la personne assignée sur la tâche #%d', + '%s change the assignee of the task #%d' => '%s a changé la personne assignée sur la tâche n°%d', + '[%s][Column Change] %s (#%d)' => '[%s][Changement de colonne] %s (#%d)', + '[%s][Position Change] %s (#%d)' => '[%s][Changement de position] %s (#%d)', + '[%s][Assignee Change] %s (#%d)' => '[%s][Changement d\'assigné] %s (#%d)', ); diff --git a/app/Model/Action.php b/app/Model/Action.php index ad995991..a318c5b0 100644 --- a/app/Model/Action.php +++ b/app/Model/Action.php @@ -64,6 +64,7 @@ class Action extends Base Task::EVENT_OPEN => t('Open a closed task'), Task::EVENT_CLOSE => t('Closing a task'), Task::EVENT_CREATE_UPDATE => t('Task creation or modification'), + Task::EVENT_ASSIGNEE_CHANGE => t('Task assignee change'), ); } diff --git a/app/Model/Notification.php b/app/Model/Notification.php index 0cb17076..89439f37 100644 --- a/app/Model/Notification.php +++ b/app/Model/Notification.php @@ -79,6 +79,9 @@ class Notification extends Base $this->event->attach(Task::EVENT_UPDATE, new TaskNotificationListener($this, 'notification_task_update')); $this->event->attach(Task::EVENT_CLOSE, new TaskNotificationListener($this, 'notification_task_close')); $this->event->attach(Task::EVENT_OPEN, new TaskNotificationListener($this, 'notification_task_open')); + $this->event->attach(Task::EVENT_MOVE_COLUMN, new TaskNotificationListener($this, 'notification_task_move_column')); + $this->event->attach(Task::EVENT_MOVE_POSITION, new TaskNotificationListener($this, 'notification_task_move_position')); + $this->event->attach(Task::EVENT_ASSIGNEE_CHANGE, new TaskNotificationListener($this, 'notification_task_assignee_change')); } /** @@ -97,7 +100,6 @@ class Notification extends Base $message = Swift_Message::newInstance() ->setSubject($this->getMailSubject($template, $data)) ->setFrom(array(MAIL_FROM => 'Kanboard')) - //->setTo(array($user['email'] => $user['name'])) ->setBody($this->getMailContent($template, $data), 'text/html'); foreach ($users as $user) { @@ -143,6 +145,15 @@ class Notification extends Base case 'notification_task_open': $subject = e('[%s][Task opened] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']); break; + case 'notification_task_move_column': + $subject = e('[%s][Column Change] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']); + break; + case 'notification_task_move_position': + $subject = e('[%s][Position Change] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']); + break; + case 'notification_task_assignee_change': + $subject = e('[%s][Assignee Change] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']); + break; case 'notification_task_due': $subject = e('[%s][Due tasks]', $data['project']); break; diff --git a/app/Model/Task.php b/app/Model/Task.php index fcee67f7..ddeb8a2b 100644 --- a/app/Model/Task.php +++ b/app/Model/Task.php @@ -35,13 +35,14 @@ class Task extends Base * * @var string */ - const EVENT_MOVE_COLUMN = 'task.move.column'; - const EVENT_MOVE_POSITION = 'task.move.position'; - const EVENT_UPDATE = 'task.update'; - const EVENT_CREATE = 'task.create'; - const EVENT_CLOSE = 'task.close'; - const EVENT_OPEN = 'task.open'; - const EVENT_CREATE_UPDATE = 'task.create_update'; + const EVENT_MOVE_COLUMN = 'task.move.column'; + const EVENT_MOVE_POSITION = 'task.move.position'; + const EVENT_UPDATE = 'task.update'; + const EVENT_CREATE = 'task.create'; + const EVENT_CLOSE = 'task.close'; + const EVENT_OPEN = 'task.open'; + const EVENT_CREATE_UPDATE = 'task.create_update'; + const EVENT_ASSIGNEE_CHANGE = 'task.assignee_change'; /** * Get available colors @@ -437,9 +438,10 @@ class Task extends Base * * @access public * @param array $values Form values + * @param boolean $trigger_Events Trigger events * @return boolean */ - public function update(array $values) + public function update(array $values, $trigger_events = true) { // Fetch original task $original_task = $this->getById($values['id']); @@ -454,7 +456,9 @@ class Task extends Base $updated_task['date_modification'] = time(); unset($updated_task['id']); - if ($this->db->table(self::TABLE)->eq('id', $values['id'])->update($updated_task)) { + $result = $this->db->table(self::TABLE)->eq('id', $values['id'])->update($updated_task); + + if ($result && $trigger_events) { $this->triggerUpdateEvents($original_task, $updated_task); } @@ -472,7 +476,10 @@ class Task extends Base { $events = array(); - if (isset($updated_task['column_id']) && $original_task['column_id'] != $updated_task['column_id']) { + if (isset($updated_task['owner_id']) && $original_task['owner_id'] != $updated_task['owner_id']) { + $events[] = self::EVENT_ASSIGNEE_CHANGE; + } + else if (isset($updated_task['column_id']) && $original_task['column_id'] != $updated_task['column_id']) { $events[] = self::EVENT_MOVE_COLUMN; } else if (isset($updated_task['position']) && $original_task['position'] != $updated_task['position']) { diff --git a/app/Model/TaskHistory.php b/app/Model/TaskHistory.php index c81e3eb4..0615cba0 100644 --- a/app/Model/TaskHistory.php +++ b/app/Model/TaskHistory.php @@ -122,6 +122,7 @@ class TaskHistory extends BaseHistory public function getTitle(array $event) { $titles = array( + Task::EVENT_ASSIGNEE_CHANGE => t('%s change the assignee of the task #%d', $event['author'], $event['task_id']), Task::EVENT_UPDATE => t('%s updated the task #%d', $event['author'], $event['task_id']), Task::EVENT_CREATE => t('%s created the task #%d', $event['author'], $event['task_id']), Task::EVENT_CLOSE => t('%s closed the task #%d', $event['author'], $event['task_id']), @@ -141,6 +142,7 @@ class TaskHistory extends BaseHistory public function attachEvents() { $events = array( + Task::EVENT_ASSIGNEE_CHANGE, Task::EVENT_UPDATE, Task::EVENT_CREATE, Task::EVENT_CLOSE, diff --git a/app/Templates/event_task_assignee_change.php b/app/Templates/event_task_assignee_change.php new file mode 100644 index 00000000..ac18af2f --- /dev/null +++ b/app/Templates/event_task_assignee_change.php @@ -0,0 +1,6 @@ +

+ #%d', Helper\escape($author), $task_id, $task_id) ?> +

+

+ +

\ No newline at end of file diff --git a/app/Templates/notification_task_assignee_change.php b/app/Templates/notification_task_assignee_change.php new file mode 100644 index 00000000..9c2bee56 --- /dev/null +++ b/app/Templates/notification_task_assignee_change.php @@ -0,0 +1,20 @@ +

(#)

+ + + + +

+ + + + $task)) ?> \ No newline at end of file diff --git a/app/Templates/notification_task_move_column.php b/app/Templates/notification_task_move_column.php new file mode 100644 index 00000000..026db776 --- /dev/null +++ b/app/Templates/notification_task_move_column.php @@ -0,0 +1,11 @@ +

(#)

+ + + + $task)) ?> \ No newline at end of file diff --git a/app/Templates/notification_task_move_position.php b/app/Templates/notification_task_move_position.php new file mode 100644 index 00000000..026db776 --- /dev/null +++ b/app/Templates/notification_task_move_position.php @@ -0,0 +1,11 @@ +

(#)

+ + + + $task)) ?> \ No newline at end of file diff --git a/docs/automatic-actions.markdown b/docs/automatic-actions.markdown index 6d46b053..c1dc3e10 100644 --- a/docs/automatic-actions.markdown +++ b/docs/automatic-actions.markdown @@ -25,6 +25,7 @@ List of available events - Open a closed task - Closing a task - Task creation or modification +- Task assignee change List of available actions ------------------------- @@ -79,7 +80,7 @@ Let's say we have two projects "Ideas" and "Development", once the idea is valid ### I want to assign automatically a color to the user Bob -- Choose the event: **Task creation** +- Choose the event: **Task assignee change** - Choose the action: **Assign a color to a specific user** - Define the action parameters: **Color = Green** and **Assignee = Bob** diff --git a/tests/units/TaskTest.php b/tests/units/TaskTest.php index 739214fc..98553428 100644 --- a/tests/units/TaskTest.php +++ b/tests/units/TaskTest.php @@ -648,5 +648,9 @@ class TaskTest extends Base // We change the column and the position of our task $this->assertTrue($t->movePosition(1, 1, 1, 1)); $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_COLUMN)); + + // We change the assignee + $this->assertTrue($t->update(array('owner_id' => 1, 'id' => 1))); + $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_ASSIGNEE_CHANGE)); } } -- cgit v1.2.3