Do not send notifications to disabled users

This commit is contained in:
Frederic Guillot 2016-05-24 22:14:29 -04:00
parent 8ba05940e9
commit 47ec4d89bc
3 changed files with 28 additions and 12 deletions

View File

@ -17,6 +17,10 @@ Improvements:
* Use Gulp and Bower to manage assets
* Controller and Middleware refactoring
Bug fixes:
* Do not send notifications to disabled users
Version 1.0.28
--------------

View File

@ -162,8 +162,9 @@ class UserNotification extends Base
->table(ProjectUserRole::TABLE)
->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name', User::TABLE.'.email', User::TABLE.'.language', User::TABLE.'.notifications_filter')
->join(User::TABLE, 'id', 'user_id')
->eq('project_id', $project_id)
->eq('notifications_enabled', '1')
->eq(ProjectUserRole::TABLE.'.project_id', $project_id)
->eq(User::TABLE.'.notifications_enabled', '1')
->eq(User::TABLE.'.is_active', 1)
->neq(User::TABLE.'.id', $exclude_user_id)
->findAll();
}
@ -178,6 +179,7 @@ class UserNotification extends Base
->eq(ProjectGroupRole::TABLE.'.project_id', $project_id)
->eq(User::TABLE.'.notifications_enabled', '1')
->neq(User::TABLE.'.id', $exclude_user_id)
->eq(User::TABLE.'.is_active', 1)
->findAll();
}
@ -195,6 +197,7 @@ class UserNotification extends Base
->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name', User::TABLE.'.email', User::TABLE.'.language', User::TABLE.'.notifications_filter')
->eq('notifications_enabled', '1')
->neq(User::TABLE.'.id', $exclude_user_id)
->eq(User::TABLE.'.is_active', 1)
->findAll();
}
}

View File

@ -109,7 +109,8 @@ class UserNotificationTest extends Base
$this->assertEquals(2, $userModel->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1)));
$this->assertEquals(3, $userModel->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1)));
$this->assertEquals(4, $userModel->create(array('username' => 'user3')));
$this->assertEquals(4, $userModel->create(array('username' => 'user3', 'email' => '', 'notifications_enabled' => 1, 'is_active' => 0)));
$this->assertEquals(5, $userModel->create(array('username' => 'user4')));
$this->assertEquals(1, $groupModel->create('G1'));
$this->assertEquals(2, $groupModel->create('G2'));
@ -117,6 +118,7 @@ class UserNotificationTest extends Base
$this->assertTrue($groupMemberModel->addUser(1, 2));
$this->assertTrue($groupMemberModel->addUser(1, 3));
$this->assertTrue($groupMemberModel->addUser(1, 4));
$this->assertTrue($groupMemberModel->addUser(1, 5));
$this->assertTrue($groupMemberModel->addUser(2, 2));
$this->assertTrue($groupMemberModel->addUser(2, 3));
@ -143,26 +145,30 @@ class UserNotificationTest extends Base
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
// Email + Notifications enabled
$this->assertNotFalse($u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1)));
$this->assertEquals(2, $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)));
$this->assertEquals(3, $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)));
$this->assertEquals(4, $u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1)));
// User disabled
$this->assertEquals(5, $u->create(array('username' => 'user4', 'email' => 'user3@here', 'notifications_enabled' => 1, 'is_active' => 0)));
// No email + notifications disabled
$this->assertNotFalse($u->create(array('username' => 'user4')));
$this->assertEquals(6, $u->create(array('username' => 'user5')));
// Nobody is member of any projects
$this->assertEmpty($pp->getUsers(1));
$this->assertEmpty($n->getUsersWithNotificationEnabled(1));
// We allow all users to be member of our projects
$this->assertTrue($pp->addUser(1, 1, Role::PROJECT_MEMBER));
$this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER));
$this->assertTrue($pp->addUser(1, 3, Role::PROJECT_MEMBER));
$this->assertTrue($pp->addUser(1, 4, Role::PROJECT_MEMBER));
$this->assertTrue($pp->addUser(1, 5, Role::PROJECT_MEMBER));
$this->assertTrue($pp->addUser(1, 6, Role::PROJECT_MEMBER));
$this->assertNotEmpty($pp->getUsers(1));
$users = $n->getUsersWithNotificationEnabled(1);
@ -185,16 +191,19 @@ class UserNotificationTest extends Base
$this->assertTrue($pp->isEverybodyAllowed(1));
// Email + Notifications enabled
$this->assertNotFalse($u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1)));
$this->assertEquals(2, $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)));
$this->assertEquals(3, $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)));
$this->assertEquals(4, $u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1)));
// User disabled
$this->assertEquals(5, $u->create(array('username' => 'user4', 'email' => 'user3@here', 'notifications_enabled' => 1, 'is_active' => 0)));
// No email + notifications disabled
$this->assertNotFalse($u->create(array('username' => 'user4')));
$this->assertEquals(6, $u->create(array('username' => 'user5')));
$users = $n->getUsersWithNotificationEnabled(1);