diff options
23 files changed, 174 insertions, 17 deletions
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 @@ -52,6 +52,17 @@ abstract class BaseNotificationListener implements Listener } /** + * Return class information + * + * @access public + * @return string + */ + public function __toString() + { + return get_called_class(); + } + + /** * Execute the action * * @access public 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 @@ -33,6 +33,17 @@ class CommentHistoryListener implements Listener } /** + * Return class information + * + * @access public + * @return string + */ + public function __toString() + { + return get_called_class(); + } + + /** * Execute the action * * @access public 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 @@ -35,6 +35,17 @@ class ProjectModificationDate implements Listener } /** + * Return class information + * + * @access public + * @return string + */ + public function __toString() + { + return get_called_class(); + } + + /** * Execute the action * * @access public 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 @@ -33,6 +33,17 @@ class SubtaskHistoryListener implements Listener } /** + * Return class information + * + * @access public + * @return string + */ + public function __toString() + { + return get_called_class(); + } + + /** * Execute the action * * @access public 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 @@ -33,6 +33,17 @@ class TaskHistoryListener implements Listener } /** + * Return class information + * + * @access public + * @return string + */ + public function __toString() + { + return get_called_class(); + } + + /** * Execute the action * * @access public 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 @@ -43,6 +43,17 @@ class WebhookListener implements Listener } /** + * Return class information + * + * @access public + * @return string + */ + public function __toString() + { + return get_called_class(); + } + + /** * Execute the action * * @access public 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 <a href="?controller=task&action=show&task_id=%d">#%d</a>' => '%s a changé la personne assignée sur la tâche <a href="?controller=task&action=show&task_id=%d">n°%d</a>', + '[%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 @@ +<p class="activity-title"> + <?= e('%s change the assignee of the task <a href="?controller=task&action=show&task_id=%d">#%d</a>', Helper\escape($author), $task_id, $task_id) ?> +</p> +<p class="activity-description"> + <em><?= Helper\escape($task_title) ?></em> +</p>
\ 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 @@ +<h2><?= Helper\escape($task['title']) ?> (#<?= $task['id'] ?>)</h2> + +<ul> + <li> + <strong> + <?php if ($task['assignee_username']): ?> + <?= t('Assigned to %s', $task['assignee_name'] ?: $task['assignee_username']) ?> + <?php else: ?> + <?= t('There is nobody assigned') ?> + <?php endif ?> + </strong> + </li> +</ul> + +<?php if (! empty($task['description'])): ?> + <h2><?= t('Description') ?></h2> + <?= Helper\parse($task['description']) ?: t('There is no description.') ?> +<?php endif ?> + +<?= Helper\template('notification_footer', array('task' => $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 @@ +<h2><?= Helper\escape($task['title']) ?> (#<?= $task['id'] ?>)</h2> + +<ul> + <li> + <?= t('Column on the board:') ?> + <strong><?= Helper\escape($task['column_title']) ?></strong> + </li> + <li><?= t('Task position:').' '.Helper\escape($task['position']) ?></li> +</ul> + +<?= Helper\template('notification_footer', array('task' => $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 @@ +<h2><?= Helper\escape($task['title']) ?> (#<?= $task['id'] ?>)</h2> + +<ul> + <li> + <?= t('Column on the board:') ?> + <strong><?= Helper\escape($task['column_title']) ?></strong> + </li> + <li><?= t('Task position:').' '.Helper\escape($task['position']) ?></li> +</ul> + +<?= Helper\template('notification_footer', array('task' => $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)); } } |