/**
  * Execute the action
  *
  * @access public
  * @param  array   $data   Event data dictionary
  * @return bool            True if the action was executed or false when not executed
  */
 public function execute(array $data)
 {
     $values = $this->getTemplateData($data);
     // Get the list of users to be notified
     $users = $this->notification->getUsersList($values['task']['project_id']);
     // Send notifications
     if ($users) {
         $this->notification->sendEmails($this->template, $users, $values);
         return true;
     }
     return false;
 }
Esempio n. 2
0
 public function testGetUserList()
 {
     $u = new User($this->registry);
     $p = new Project($this->registry);
     $n = new Notification($this->registry);
     $this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
     $this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
     // Email + Notifications enabled
     $this->assertTrue($u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1)));
     // No email + Notifications enabled
     $this->assertTrue($u->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1)));
     // Email + Notifications enabled
     $this->assertTrue($u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1)));
     // No email + notifications disabled
     $this->assertTrue($u->create(array('username' => 'user4')));
     $users = $n->getUsersList(1);
     $this->assertNotEmpty($users);
     $this->assertEquals(2, count($users));
     $this->assertEquals('user1@here', $users[0]['email']);
     $this->assertEquals('user3@here', $users[1]['email']);
     $users = $n->getUsersList(2);
     $this->assertNotEmpty($users);
     $this->assertEquals(2, count($users));
     $this->assertEquals('user1@here', $users[0]['email']);
     $this->assertEquals('user3@here', $users[1]['email']);
     // User 3 choose to receive notification only for project 2
     $n->saveSettings(4, array('notifications_enabled' => 1, 'projects' => array(2 => true)));
     $users = $n->getUsersList(1);
     $this->assertNotEmpty($users);
     $this->assertEquals(1, count($users));
     $this->assertEquals('user1@here', $users[0]['email']);
     $users = $n->getUsersList(2);
     $this->assertNotEmpty($users);
     $this->assertEquals(2, count($users));
     $this->assertEquals('user1@here', $users[0]['email']);
     $this->assertEquals('user3@here', $users[1]['email']);
     // User 1 excluded
     $users = $n->getUsersList(1, array(2));
     $this->assertEmpty($users);
     $users = $n->getUsersList(2, array(2));
     $this->assertNotEmpty($users);
     $this->assertEquals(1, count($users));
     $this->assertEquals('user3@here', $users[0]['email']);
 }
Esempio n. 3
0
use Model\SubTask;
use Model\Board;
use Model\Action;
use Model\Webhook;
use Model\Notification;
$config = new Config($registry);
$project = new Project($registry);
$task = new Task($registry);
$user = new User($registry);
$category = new Category($registry);
$comment = new Comment($registry);
$subtask = new SubTask($registry);
$board = new Board($registry);
$action = new Action($registry);
$webhook = new Webhook($registry);
$notification = new Notification($registry);
$action->attachEvents();
$project->attachEvents();
$webhook->attachEvents();
$notification->attachEvents();
// Load translations
$language = $config->get('language', 'en_US');
if ($language !== 'en_US') {
    Translator::load($language);
}
$server = new Server();
$server->authentication(array('jsonrpc' => $config->get('api_token')));
/**
 * Project procedures
 */
$server->register('createProject', function ($name) use($project) {
Esempio n. 4
0
 public function testFilterUserWithBothFilterAndProjectSelected()
 {
     $u = new User($this->container);
     $n = new Notification($this->container);
     $nf = new NotificationFilter($this->container);
     $p = new Project($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
     $this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
     $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => NotificationFilter::FILTER_BOTH)));
     $n->saveSettings(2, array('notifications_enabled' => 1, 'notification_projects' => array(2 => true)));
     $this->assertFalse($nf->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 2, 'owner_id' => 3))));
     $this->assertFalse($nf->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 0, 'owner_id' => 2))));
     $this->assertTrue($nf->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 2, 'creator_id' => 2, 'owner_id' => 3))));
     $this->assertTrue($nf->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 2, 'creator_id' => 0, 'owner_id' => 2))));
 }
Esempio n. 5
0
 public function testSendNotificationsToNotMember()
 {
     $u = new User($this->container);
     $p = new Project($this->container);
     $n = new Notification($this->container);
     $pp = new ProjectPermission($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
     $this->assertEquals(2, $u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1)));
     $this->container['emailClient']->expects($this->never())->method('send');
     $n->sendNotifications('task.open', array('task' => array('id' => 2, 'title' => 'blah', 'project_name' => 'test', 'project_id' => 1, 'owner_id' => 0, 'creator_id' => 2)));
 }
Esempio n. 6
0
 public function testGetUserList()
 {
     $u = new User($this->container);
     $p = new Project($this->container);
     $pp = new ProjectPermission($this->container);
     $n = new Notification($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
     $this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
     $this->assertEquals(3, $p->create(array('name' => 'UnitTest3', 'is_everybody_allowed' => 1)));
     // Email + Notifications enabled
     $this->assertNotFalse($u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1)));
     // No email + Notifications enabled
     $this->assertNotFalse($u->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1)));
     // Email + Notifications enabled
     $this->assertNotFalse($u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1)));
     // No email + notifications disabled
     $this->assertNotFalse($u->create(array('username' => 'user4')));
     // We allow all users to be member of our projects
     $this->assertTrue($pp->allowUser(1, 1));
     $this->assertTrue($pp->allowUser(1, 2));
     $this->assertTrue($pp->allowUser(1, 3));
     $this->assertTrue($pp->allowUser(1, 4));
     $this->assertTrue($pp->allowUser(2, 1));
     $this->assertTrue($pp->allowUser(2, 2));
     $this->assertTrue($pp->allowUser(2, 3));
     $this->assertTrue($pp->allowUser(2, 4));
     $users = $n->getUsersList(1);
     $this->assertNotEmpty($users);
     $this->assertEquals(2, count($users));
     $this->assertEquals('user1@here', $users[0]['email']);
     $this->assertEquals('user3@here', $users[1]['email']);
     $users = $n->getUsersList(2);
     $this->assertNotEmpty($users);
     $this->assertEquals(2, count($users));
     $this->assertEquals('user1@here', $users[0]['email']);
     $this->assertEquals('user3@here', $users[1]['email']);
     // User 3 choose to receive notification only for project 2
     $n->saveSettings(4, array('notifications_enabled' => 1, 'projects' => array(2 => true)));
     $users = $n->getUsersList(1);
     $this->assertNotEmpty($users);
     $this->assertEquals(1, count($users));
     $this->assertEquals('user1@here', $users[0]['email']);
     $users = $n->getUsersList(2);
     $this->assertNotEmpty($users);
     $this->assertEquals(2, count($users));
     $this->assertEquals('user1@here', $users[0]['email']);
     $this->assertEquals('user3@here', $users[1]['email']);
     // User 1 excluded
     $users = $n->getUsersList(1, array(2));
     $this->assertEmpty($users);
     $users = $n->getUsersList(2, array(2));
     $this->assertNotEmpty($users);
     $this->assertEquals(1, count($users));
     $this->assertEquals('user3@here', $users[0]['email']);
     // Project #3 allow everybody
     $users = $n->getUsersList(3);
     $this->assertNotEmpty($users);
     $this->assertEquals(1, count($users));
     $this->assertEquals('user1@here', $users[0]['email']);
     $users = $n->getUsersWithNotification(3);
     $this->assertNotEmpty($users);
     $this->assertEquals(2, count($users));
     $this->assertEquals('user1@here', $users[0]['email']);
     $this->assertEquals('user3@here', $users[1]['email']);
 }
Esempio n. 7
0
 public function testSendNotifications()
 {
     $u = new User($this->container);
     $n = new Notification($this->container);
     $p = new Project($this->container);
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $pp = new ProjectPermission($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'is_everybody_allowed' => 1)));
     $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
     $this->assertTrue($u->update(array('id' => 1, 'email' => 'test@localhost')));
     $this->assertTrue($pp->isEverybodyAllowed(1));
     $n->saveSettings(1, array('notifications_enabled' => 1, 'notifications_filter' => NotificationFilter::FILTER_NONE, 'notification_types' => array(NotificationType::TYPE_WEB => 1, NotificationType::TYPE_EMAIL => 1)));
     $this->container['emailNotification'] = $this->getMockBuilder('\\Model\\EmailNotification')->setConstructorArgs(array($this->container))->setMethods(array('send'))->getMock();
     $this->container['webNotification'] = $this->getMockBuilder('\\Model\\WebNotification')->setConstructorArgs(array($this->container))->setMethods(array('send'))->getMock();
     $this->container['emailNotification']->expects($this->once())->method('send');
     $this->container['webNotification']->expects($this->once())->method('send');
     $n->sendNotifications(Task::EVENT_CREATE, array('task' => $tf->getDetails(1)));
 }