summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Model/ProjectActivity.php2
-rw-r--r--app/Notification/ActivityStream.php58
-rw-r--r--app/Notification/Webhook.php2
-rw-r--r--app/ServiceProvider/ClassProvider.php3
-rw-r--r--app/ServiceProvider/EventDispatcherProvider.php2
-rw-r--r--app/Subscriber/ProjectActivitySubscriber.php74
-rw-r--r--tests/units/Model/ProjectActivityTest.php43
7 files changed, 106 insertions, 78 deletions
diff --git a/app/Model/ProjectActivity.php b/app/Model/ProjectActivity.php
index 2cc1c975..032c1fa6 100644
--- a/app/Model/ProjectActivity.php
+++ b/app/Model/ProjectActivity.php
@@ -238,6 +238,8 @@ class ProjectActivity extends Base
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 '';
}
diff --git a/app/Notification/ActivityStream.php b/app/Notification/ActivityStream.php
new file mode 100644
index 00000000..65ae64b1
--- /dev/null
+++ b/app/Notification/ActivityStream.php
@@ -0,0 +1,58 @@
+<?php
+
+namespace Kanboard\Notification;
+
+use Kanboard\Core\Base;
+
+/**
+ * Activity Stream Notification
+ *
+ * @package notification
+ * @author Frederic Guillot
+ */
+class ActivityStream extends Base implements NotificationInterface
+{
+ /**
+ * Send notification to a user
+ *
+ * @access public
+ * @param array $user
+ * @param string $event_name
+ * @param array $event_data
+ */
+ public function notifyUser(array $user, $event_name, array $event_data)
+ {
+ }
+
+ /**
+ * Send notification to a project
+ *
+ * @access public
+ * @param array $project
+ * @param string $event_name
+ * @param array $event_data
+ */
+ public function notifyProject(array $project, $event_name, array $event_data)
+ {
+ if ($this->userSession->isLogged()) {
+
+ $this->projectActivity->createEvent(
+ $project['id'],
+ $event_data['task']['id'],
+ $this->userSession->getId(),
+ $event_name,
+ $event_data
+ );
+
+ // TODO: need to be moved to external plugins
+ foreach (array('slackWebhook', 'hipchatWebhook', 'jabber') as $model) {
+ $this->$model->notify(
+ $project['id'],
+ $event_data['task']['id'],
+ $event_name,
+ $event_data
+ );
+ }
+ }
+ }
+}
diff --git a/app/Notification/Webhook.php b/app/Notification/Webhook.php
index feeee5d6..e187909f 100644
--- a/app/Notification/Webhook.php
+++ b/app/Notification/Webhook.php
@@ -49,7 +49,7 @@ class Webhook extends Base implements NotificationInterface
'event_data' => $event_data,
);
- return $this->httpClient->postJson($url, $payload);
+ $this->httpClient->postJson($url, $payload);
}
}
}
diff --git a/app/ServiceProvider/ClassProvider.php b/app/ServiceProvider/ClassProvider.php
index 182ecf26..b969c289 100644
--- a/app/ServiceProvider/ClassProvider.php
+++ b/app/ServiceProvider/ClassProvider.php
@@ -138,7 +138,8 @@ class ClassProvider implements ServiceProviderInterface
$container['projectNotificationType'] = function ($container) {
$type = new ProjectNotificationType($container);
- $type->setType('webhook', t('Webhook'), '\Kanboard\Notification\Webhook', true);
+ $type->setType('webhook', 'Webhook', '\Kanboard\Notification\Webhook', true);
+ $type->setType('activity_stream', 'ActivityStream', '\Kanboard\Notification\ActivityStream', true);
return $type;
};
diff --git a/app/ServiceProvider/EventDispatcherProvider.php b/app/ServiceProvider/EventDispatcherProvider.php
index 3c9404d0..1711919e 100644
--- a/app/ServiceProvider/EventDispatcherProvider.php
+++ b/app/ServiceProvider/EventDispatcherProvider.php
@@ -8,7 +8,6 @@ use Symfony\Component\EventDispatcher\EventDispatcher;
use Kanboard\Subscriber\AuthSubscriber;
use Kanboard\Subscriber\BootstrapSubscriber;
use Kanboard\Subscriber\NotificationSubscriber;
-use Kanboard\Subscriber\ProjectActivitySubscriber;
use Kanboard\Subscriber\ProjectDailySummarySubscriber;
use Kanboard\Subscriber\ProjectModificationDateSubscriber;
use Kanboard\Subscriber\SubtaskTimeTrackingSubscriber;
@@ -23,7 +22,6 @@ class EventDispatcherProvider implements ServiceProviderInterface
$container['dispatcher'] = new EventDispatcher;
$container['dispatcher']->addSubscriber(new BootstrapSubscriber($container));
$container['dispatcher']->addSubscriber(new AuthSubscriber($container));
- $container['dispatcher']->addSubscriber(new ProjectActivitySubscriber($container));
$container['dispatcher']->addSubscriber(new ProjectDailySummarySubscriber($container));
$container['dispatcher']->addSubscriber(new ProjectModificationDateSubscriber($container));
$container['dispatcher']->addSubscriber(new NotificationSubscriber($container));
diff --git a/app/Subscriber/ProjectActivitySubscriber.php b/app/Subscriber/ProjectActivitySubscriber.php
deleted file mode 100644
index a49a00ed..00000000
--- a/app/Subscriber/ProjectActivitySubscriber.php
+++ /dev/null
@@ -1,74 +0,0 @@
-<?php
-
-namespace Kanboard\Subscriber;
-
-use Kanboard\Event\GenericEvent;
-use Kanboard\Model\Task;
-use Kanboard\Model\Comment;
-use Kanboard\Model\Subtask;
-use Symfony\Component\EventDispatcher\EventSubscriberInterface;
-
-class ProjectActivitySubscriber extends \Kanboard\Core\Base implements EventSubscriberInterface
-{
- public static function getSubscribedEvents()
- {
- return array(
- Task::EVENT_ASSIGNEE_CHANGE => array('execute', 0),
- Task::EVENT_UPDATE => array('execute', 0),
- Task::EVENT_CREATE => array('execute', 0),
- Task::EVENT_CLOSE => array('execute', 0),
- Task::EVENT_OPEN => array('execute', 0),
- Task::EVENT_MOVE_COLUMN => array('execute', 0),
- Task::EVENT_MOVE_POSITION => array('execute', 0),
- Task::EVENT_MOVE_SWIMLANE => array('execute', 0),
- Comment::EVENT_UPDATE => array('execute', 0),
- Comment::EVENT_CREATE => array('execute', 0),
- Subtask::EVENT_UPDATE => array('execute', 0),
- Subtask::EVENT_CREATE => array('execute', 0),
- );
- }
-
- public function execute(GenericEvent $event, $event_name)
- {
- // Executed only when someone is logged
- if ($this->userSession->isLogged() && isset($event['task_id'])) {
- $values = $this->getValues($event);
-
- $this->projectActivity->createEvent(
- $values['task']['project_id'],
- $values['task']['id'],
- $this->userSession->getId(),
- $event_name,
- $values
- );
-
- // Send notifications to third-party services
- foreach (array('slackWebhook', 'hipchatWebhook', 'jabber') as $model) {
- $this->$model->notify(
- $values['task']['project_id'],
- $values['task']['id'],
- $event_name,
- $values
- );
- }
- }
- }
-
- private function getValues(GenericEvent $event)
- {
- $values = array();
- $values['task'] = $this->taskFinder->getDetails($event['task_id']);
- $values['changes'] = isset($event['changes']) ? $event['changes'] : array();
-
- switch (get_class($event)) {
- case 'Kanboard\Event\SubtaskEvent':
- $values['subtask'] = $this->subtask->getById($event['id'], true);
- break;
- case 'Kanboard\Event\CommentEvent':
- $values['comment'] = $this->comment->getById($event['id']);
- break;
- }
-
- return $values;
- }
-}
diff --git a/tests/units/Model/ProjectActivityTest.php b/tests/units/Model/ProjectActivityTest.php
index e8adc10d..ead74e08 100644
--- a/tests/units/Model/ProjectActivityTest.php
+++ b/tests/units/Model/ProjectActivityTest.php
@@ -7,9 +7,52 @@ use Kanboard\Model\TaskFinder;
use Kanboard\Model\TaskCreation;
use Kanboard\Model\ProjectActivity;
use Kanboard\Model\Project;
+use Kanboard\Model\Subtask;
+use Kanboard\Model\Comment;
+use Kanboard\Model\File;
+use Kanboard\Subscriber\NotificationSubscriber;
class ProjectActivityTest extends Base
{
+ public function testGetTitle()
+ {
+ $pa = new ProjectActivity($this->container);
+ $p = new Project($this->container);
+ $tf = new TaskFinder($this->container);
+ $tc = new TaskCreation($this->container);
+ $s = new Subtask($this->container);
+ $c = new Comment($this->container);
+ $f = new File($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $s->create(array('title' => 'test', 'task_id' => 1)));
+ $this->assertEquals(1, $c->create(array('comment' => 'test', 'task_id' => 1, 'user_id' => 1)));
+ $this->assertEquals(1, $f->create(1, 'test', 'blah', 123));
+
+ $task = $tf->getDetails(1);
+ $subtask = $s->getById(1, true);
+ $comment = $c->getById(1);
+ $file = $c->getById(1);
+
+ $this->assertNotEmpty($task);
+ $this->assertNotEmpty($subtask);
+ $this->assertNotEmpty($comment);
+ $this->assertNotEmpty($file);
+
+ foreach (NotificationSubscriber::getSubscribedEvents() as $event_name => $listeners) {
+ $this->assertNotEmpty($pa->getTitle(array(
+ 'event_name' => $event_name,
+ 'task' => $task,
+ 'comment' => $comment,
+ 'subtask' => $subtask,
+ 'file' => $file,
+ 'author' => 'bob',
+ 'changes' => array())
+ ));
+ }
+ }
+
public function testDecode()
{
$e = new ProjectActivity($this->container);