Move slack, hipchat and jabber integrations to plugins
This commit is contained in:
@@ -64,7 +64,7 @@ class Acl extends Base
|
||||
'column' => '*',
|
||||
'export' => '*',
|
||||
'taskimport' => '*',
|
||||
'project' => array('edit', 'update', 'share', 'integration', 'users', 'alloweverybody', 'allow', 'setowner', 'revoke', 'duplicate', 'disable', 'enable'),
|
||||
'project' => array('edit', 'update', 'share', 'integrations', 'notifications', 'users', 'alloweverybody', 'allow', 'setowner', 'revoke', 'duplicate', 'disable', 'enable'),
|
||||
'swimlane' => '*',
|
||||
'gantt' => array('project', 'savetaskdate', 'task', 'savetask'),
|
||||
);
|
||||
|
||||
142
app/Model/Notification.php
Normal file
142
app/Model/Notification.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Model;
|
||||
|
||||
/**
|
||||
* Notification
|
||||
*
|
||||
* @package model
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class Notification extends Base
|
||||
{
|
||||
/**
|
||||
* Get the event title with author
|
||||
*
|
||||
* @access public
|
||||
* @param string $event_author
|
||||
* @param string $event_name
|
||||
* @param array $event_data
|
||||
* @return string
|
||||
*/
|
||||
public function getTitleWithAuthor($event_author, $event_name, array $event_data)
|
||||
{
|
||||
switch ($event_name) {
|
||||
case Task::EVENT_ASSIGNEE_CHANGE:
|
||||
$assignee = $event_data['task']['assignee_name'] ?: $event_data['task']['assignee_username'];
|
||||
|
||||
if (! empty($assignee)) {
|
||||
return e('%s change the assignee of the task #%d to %s', $event_author, $event_data['task']['id'], $assignee);
|
||||
}
|
||||
|
||||
return e('%s remove the assignee of the task %s', $event_author, e('#%d', $event_data['task']['id']));
|
||||
case Task::EVENT_UPDATE:
|
||||
return e('%s updated the task #%d', $event_author, $event_data['task']['id']);
|
||||
case Task::EVENT_CREATE:
|
||||
return e('%s created the task #%d', $event_author, $event_data['task']['id']);
|
||||
case Task::EVENT_CLOSE:
|
||||
return e('%s closed the task #%d', $event_author, $event_data['task']['id']);
|
||||
case Task::EVENT_OPEN:
|
||||
return e('%s open the task #%d', $event_author, $event_data['task']['id']);
|
||||
case Task::EVENT_MOVE_COLUMN:
|
||||
return e(
|
||||
'%s moved the task #%d to the column "%s"',
|
||||
$event_author,
|
||||
$event_data['task']['id'],
|
||||
$event_data['task']['column_title']
|
||||
);
|
||||
case Task::EVENT_MOVE_POSITION:
|
||||
return e(
|
||||
'%s moved the task #%d to the position %d in the column "%s"',
|
||||
$event_author,
|
||||
$event_data['task']['id'],
|
||||
$event_data['task']['position'],
|
||||
$event_data['task']['column_title']
|
||||
);
|
||||
case Task::EVENT_MOVE_SWIMLANE:
|
||||
if ($event_data['task']['swimlane_id'] == 0) {
|
||||
return e('%s moved the task #%d to the first swimlane', $event_author, $event_data['task']['id']);
|
||||
}
|
||||
|
||||
return e(
|
||||
'%s moved the task #%d to the swimlane "%s"',
|
||||
$event_author,
|
||||
$event_data['task']['id'],
|
||||
$event_data['task']['swimlane_name']
|
||||
);
|
||||
case Subtask::EVENT_UPDATE:
|
||||
return e('%s updated a subtask for the task #%d', $event_author, $event_data['task']['id']);
|
||||
case Subtask::EVENT_CREATE:
|
||||
return e('%s created a subtask for the task #%d', $event_author, $event_data['task']['id']);
|
||||
case Comment::EVENT_UPDATE:
|
||||
return e('%s updated a comment on the task #%d', $event_author, $event_data['task']['id']);
|
||||
case Comment::EVENT_CREATE:
|
||||
return e('%s commented on the task #%d', $event_author, $event_data['task']['id']);
|
||||
case File::EVENT_CREATE:
|
||||
return e('%s attached a file to the task #%d', $event_author, $event_data['task']['id']);
|
||||
default:
|
||||
return e('Notification');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the event title without author
|
||||
*
|
||||
* @access public
|
||||
* @param string $event_name
|
||||
* @param array $event_data
|
||||
* @return string
|
||||
*/
|
||||
public function getTitleWithoutAuthor($event_name, array $event_data)
|
||||
{
|
||||
switch ($event_name) {
|
||||
case File::EVENT_CREATE:
|
||||
$title = e('New attachment on task #%d: %s', $event_data['file']['task_id'], $event_data['file']['name']);
|
||||
break;
|
||||
case Comment::EVENT_CREATE:
|
||||
$title = e('New comment on task #%d', $event_data['comment']['task_id']);
|
||||
break;
|
||||
case Comment::EVENT_UPDATE:
|
||||
$title = e('Comment updated on task #%d', $event_data['comment']['task_id']);
|
||||
break;
|
||||
case Subtask::EVENT_CREATE:
|
||||
$title = e('New subtask on task #%d', $event_data['subtask']['task_id']);
|
||||
break;
|
||||
case Subtask::EVENT_UPDATE:
|
||||
$title = e('Subtask updated on task #%d', $event_data['subtask']['task_id']);
|
||||
break;
|
||||
case Task::EVENT_CREATE:
|
||||
$title = e('New task #%d: %s', $event_data['task']['id'], $event_data['task']['title']);
|
||||
break;
|
||||
case Task::EVENT_UPDATE:
|
||||
$title = e('Task updated #%d', $event_data['task']['id']);
|
||||
break;
|
||||
case Task::EVENT_CLOSE:
|
||||
$title = e('Task #%d closed', $event_data['task']['id']);
|
||||
break;
|
||||
case Task::EVENT_OPEN:
|
||||
$title = e('Task #%d opened', $event_data['task']['id']);
|
||||
break;
|
||||
case Task::EVENT_MOVE_COLUMN:
|
||||
$title = e('Column changed for task #%d', $event_data['task']['id']);
|
||||
break;
|
||||
case Task::EVENT_MOVE_POSITION:
|
||||
$title = e('New position for task #%d', $event_data['task']['id']);
|
||||
break;
|
||||
case Task::EVENT_MOVE_SWIMLANE:
|
||||
$title = e('Swimlane changed for task #%d', $event_data['task']['id']);
|
||||
break;
|
||||
case Task::EVENT_ASSIGNEE_CHANGE:
|
||||
$title = e('Assignee changed on task #%d', $event_data['task']['id']);
|
||||
break;
|
||||
case Task::EVENT_OVERDUE:
|
||||
$nb = count($event_data['tasks']);
|
||||
$title = $nb > 1 ? e('%d overdue tasks', $nb) : e('Task #%d is overdue', $event_data['tasks'][0]['id']);
|
||||
break;
|
||||
default:
|
||||
$title = e('Notification');
|
||||
}
|
||||
|
||||
return $title;
|
||||
}
|
||||
}
|
||||
@@ -108,4 +108,20 @@ abstract class NotificationType extends Base
|
||||
{
|
||||
return $this->hiddens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep only loaded notification types
|
||||
*
|
||||
* @access public
|
||||
* @param string[] $types
|
||||
* @return array
|
||||
*/
|
||||
public function filterTypes(array $types)
|
||||
{
|
||||
$classes = $this->classes;
|
||||
|
||||
return array_filter($types, function($type) use ($classes) {
|
||||
return isset($classes[$type]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ class ProjectActivity extends Base
|
||||
unset($event['data']);
|
||||
|
||||
$event['author'] = $event['author_name'] ?: $event['author_username'];
|
||||
$event['event_title'] = $this->getTitle($event);
|
||||
$event['event_title'] = $this->notification->getTitleWithAuthor($event['author'], $event['event_name'], $event);
|
||||
$event['event_content'] = $this->getContent($event);
|
||||
}
|
||||
|
||||
@@ -195,56 +195,6 @@ class ProjectActivity extends Base
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the event title (translated)
|
||||
*
|
||||
* @access public
|
||||
* @param array $event Event properties
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle(array $event)
|
||||
{
|
||||
switch ($event['event_name']) {
|
||||
case Task::EVENT_ASSIGNEE_CHANGE:
|
||||
$assignee = $event['task']['assignee_name'] ?: $event['task']['assignee_username'];
|
||||
|
||||
if (! empty($assignee)) {
|
||||
return t('%s change the assignee of the task #%d to %s', $event['author'], $event['task']['id'], $assignee);
|
||||
}
|
||||
|
||||
return t('%s remove the assignee of the task %s', $event['author'], e('#%d', $event['task']['id']));
|
||||
case Task::EVENT_UPDATE:
|
||||
return t('%s updated the task #%d', $event['author'], $event['task']['id']);
|
||||
case Task::EVENT_CREATE:
|
||||
return t('%s created the task #%d', $event['author'], $event['task']['id']);
|
||||
case Task::EVENT_CLOSE:
|
||||
return t('%s closed the task #%d', $event['author'], $event['task']['id']);
|
||||
case Task::EVENT_OPEN:
|
||||
return t('%s open the task #%d', $event['author'], $event['task']['id']);
|
||||
case Task::EVENT_MOVE_COLUMN:
|
||||
return t('%s moved the task #%d to the column "%s"', $event['author'], $event['task']['id'], $event['task']['column_title']);
|
||||
case Task::EVENT_MOVE_POSITION:
|
||||
return t('%s moved the task #%d to the position %d in the column "%s"', $event['author'], $event['task']['id'], $event['task']['position'], $event['task']['column_title']);
|
||||
case Task::EVENT_MOVE_SWIMLANE:
|
||||
if ($event['task']['swimlane_id'] == 0) {
|
||||
return t('%s moved the task #%d to the first swimlane', $event['author'], $event['task']['id']);
|
||||
}
|
||||
return t('%s moved the task #%d to the swimlane "%s"', $event['author'], $event['task']['id'], $event['task']['swimlane_name']);
|
||||
case Subtask::EVENT_UPDATE:
|
||||
return t('%s updated a subtask for the task #%d', $event['author'], $event['task']['id']);
|
||||
case Subtask::EVENT_CREATE:
|
||||
return t('%s created a subtask for the task #%d', $event['author'], $event['task']['id']);
|
||||
case Comment::EVENT_UPDATE:
|
||||
return t('%s updated a comment on the task #%d', $event['author'], $event['task']['id']);
|
||||
case Comment::EVENT_CREATE:
|
||||
return t('%s commented on the task #%d', $event['author'], $event['task']['id']);
|
||||
case File::EVENT_CREATE:
|
||||
return t('%s attached a file to the task #%d', $event['author'], $event['task']['id']);
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode event data, supports unserialize() and json_decode()
|
||||
*
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Model;
|
||||
|
||||
/**
|
||||
* Project integration
|
||||
*
|
||||
* @package model
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class ProjectIntegration extends Base
|
||||
{
|
||||
/**
|
||||
* SQL table name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const TABLE = 'project_integrations';
|
||||
|
||||
/**
|
||||
* Get all parameters for a project
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id
|
||||
* @return array
|
||||
*/
|
||||
public function getParameters($project_id)
|
||||
{
|
||||
return $this->db->table(self::TABLE)->eq('project_id', $project_id)->findOne() ?: array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save parameters for a project
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id
|
||||
* @param array $values
|
||||
* @return boolean
|
||||
*/
|
||||
public function saveParameters($project_id, array $values)
|
||||
{
|
||||
if ($this->db->table(self::TABLE)->eq('project_id', $project_id)->exists()) {
|
||||
return $this->db->table(self::TABLE)->eq('project_id', $project_id)->update($values);
|
||||
}
|
||||
|
||||
return $this->db->table(self::TABLE)->insert($values + array('project_id' => $project_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a project has the given parameter/value
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id
|
||||
* @param string $option
|
||||
* @param string $value
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasValue($project_id, $option, $value)
|
||||
{
|
||||
return $this->db
|
||||
->table(self::TABLE)
|
||||
->eq('project_id', $project_id)
|
||||
->eq($option, $value)
|
||||
->exists();
|
||||
}
|
||||
}
|
||||
@@ -22,8 +22,44 @@ class ProjectNotification extends Base
|
||||
{
|
||||
$project = $this->project->getById($project_id);
|
||||
|
||||
foreach ($this->projectNotificationType->getSelectedTypes($project_id) as $type) {
|
||||
$types = array_merge(
|
||||
$this->projectNotificationType->getHiddenTypes(),
|
||||
$this->projectNotificationType->getSelectedTypes($project_id)
|
||||
);
|
||||
|
||||
foreach ($types as $type) {
|
||||
$this->projectNotificationType->getType($type)->notifyProject($project, $event_name, $event_data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save settings for the given project
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id
|
||||
* @param array $values
|
||||
*/
|
||||
public function saveSettings($project_id, array $values)
|
||||
{
|
||||
$this->db->startTransaction();
|
||||
|
||||
$types = empty($values['notification_types']) ? array() : array_keys($values['notification_types']);
|
||||
$this->projectNotificationType->saveSelectedTypes($project_id, $types);
|
||||
|
||||
$this->db->closeTransaction();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read user settings to display the form
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id
|
||||
* @return array
|
||||
*/
|
||||
public function readSettings($project_id)
|
||||
{
|
||||
return array(
|
||||
'notification_types' => $this->projectNotificationType->getSelectedTypes($project_id),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,13 +26,13 @@ class ProjectNotificationType extends NotificationType
|
||||
*/
|
||||
public function getSelectedTypes($project_id)
|
||||
{
|
||||
$selectedTypes = $this->db
|
||||
$types = $this->db
|
||||
->table(self::TABLE)
|
||||
->eq('project_id', $project_id)
|
||||
->asc('notification_type')
|
||||
->findAllByColumn('notification_type');
|
||||
|
||||
return array_merge($this->getHiddenTypes(), $selectedTypes);
|
||||
return $this->filterTypes($types);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,6 +52,6 @@ class ProjectNotificationType extends NotificationType
|
||||
$results[] = $this->db->table(self::TABLE)->insert(array('project_id' => $project_id, 'notification_type' => $type));
|
||||
}
|
||||
|
||||
return ! in_array(false, $results);
|
||||
return ! in_array(false, $results, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,8 @@ class UserNotificationType extends NotificationType
|
||||
*/
|
||||
public function getSelectedTypes($user_id)
|
||||
{
|
||||
return $this->db->table(self::TABLE)->eq('user_id', $user_id)->asc('notification_type')->findAllByColumn('notification_type');
|
||||
$types = $this->db->table(self::TABLE)->eq('user_id', $user_id)->asc('notification_type')->findAllByColumn('notification_type');
|
||||
return $this->filterTypes($types);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,6 +47,6 @@ class UserNotificationType extends NotificationType
|
||||
$results[] = $this->db->table(self::TABLE)->insert(array('user_id' => $user_id, 'notification_type' => $type));
|
||||
}
|
||||
|
||||
return ! in_array(false, $results);
|
||||
return ! in_array(false, $results, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class UserUnreadNotification extends Base
|
||||
|
||||
foreach ($events as &$event) {
|
||||
$event['event_data'] = json_decode($event['event_data'], true);
|
||||
$event['title'] = $this->getTitleFromEvent($event['event_name'], $event['event_data']);
|
||||
$event['title'] = $this->notification->getTitleWithoutAuthor($event['event_name'], $event['event_data']);
|
||||
}
|
||||
|
||||
return $events;
|
||||
@@ -90,65 +90,4 @@ class UserUnreadNotification extends Base
|
||||
{
|
||||
return $this->db->table(self::TABLE)->eq('user_id', $user_id)->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title from event
|
||||
*
|
||||
* @access public
|
||||
* @param string $event_name
|
||||
* @param array $event_data
|
||||
* @return string
|
||||
*/
|
||||
public function getTitleFromEvent($event_name, array $event_data)
|
||||
{
|
||||
switch ($event_name) {
|
||||
case File::EVENT_CREATE:
|
||||
$title = t('New attachment on task #%d: %s', $event_data['file']['task_id'], $event_data['file']['name']);
|
||||
break;
|
||||
case Comment::EVENT_CREATE:
|
||||
$title = t('New comment on task #%d', $event_data['comment']['task_id']);
|
||||
break;
|
||||
case Comment::EVENT_UPDATE:
|
||||
$title = t('Comment updated on task #%d', $event_data['comment']['task_id']);
|
||||
break;
|
||||
case Subtask::EVENT_CREATE:
|
||||
$title = t('New subtask on task #%d', $event_data['subtask']['task_id']);
|
||||
break;
|
||||
case Subtask::EVENT_UPDATE:
|
||||
$title = t('Subtask updated on task #%d', $event_data['subtask']['task_id']);
|
||||
break;
|
||||
case Task::EVENT_CREATE:
|
||||
$title = t('New task #%d: %s', $event_data['task']['id'], $event_data['task']['title']);
|
||||
break;
|
||||
case Task::EVENT_UPDATE:
|
||||
$title = t('Task updated #%d', $event_data['task']['id']);
|
||||
break;
|
||||
case Task::EVENT_CLOSE:
|
||||
$title = t('Task #%d closed', $event_data['task']['id']);
|
||||
break;
|
||||
case Task::EVENT_OPEN:
|
||||
$title = t('Task #%d opened', $event_data['task']['id']);
|
||||
break;
|
||||
case Task::EVENT_MOVE_COLUMN:
|
||||
$title = t('Column changed for task #%d', $event_data['task']['id']);
|
||||
break;
|
||||
case Task::EVENT_MOVE_POSITION:
|
||||
$title = t('New position for task #%d', $event_data['task']['id']);
|
||||
break;
|
||||
case Task::EVENT_MOVE_SWIMLANE:
|
||||
$title = t('Swimlane changed for task #%d', $event_data['task']['id']);
|
||||
break;
|
||||
case Task::EVENT_ASSIGNEE_CHANGE:
|
||||
$title = t('Assignee changed on task #%d', $event_data['task']['id']);
|
||||
break;
|
||||
case Task::EVENT_OVERDUE:
|
||||
$nb = count($event_data['tasks']);
|
||||
$title = $nb > 1 ? t('%d overdue tasks', $nb) : t('Task #%d is overdue', $event_data['tasks'][0]['id']);
|
||||
break;
|
||||
default:
|
||||
$title = e('Notification');
|
||||
}
|
||||
|
||||
return $title;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user