summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog1
-rw-r--r--app/Model/ProjectGroupRole.php6
-rw-r--r--app/Model/UserNotification.php29
-rw-r--r--tests/units/Model/UserNotificationTest.php39
4 files changed, 69 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 18456293..fe7bde6a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,7 @@ New features:
Improvements:
+* Handle notification for group members attached to a project
* Return the highest role for a project when a user is member of multiple groups
* Show in user interface the saving state of the task
* Add dropdown menu for subtasks, categories, swimlanes, columns, custom filters, task links and groups
diff --git a/app/Model/ProjectGroupRole.php b/app/Model/ProjectGroupRole.php
index ee6ee7cb..591b28c6 100644
--- a/app/Model/ProjectGroupRole.php
+++ b/app/Model/ProjectGroupRole.php
@@ -101,10 +101,10 @@ class ProjectGroupRole extends Base
*/
public function getAssignableUsers($project_id)
{
- return $this->db->table(self::TABLE)
+ return $this->db->table(User::TABLE)
->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name')
- ->join(GroupMember::TABLE, 'group_id', 'group_id', self::TABLE)
- ->join(User::TABLE, 'id', 'user_id', GroupMember::TABLE)
+ ->join(GroupMember::TABLE, 'user_id', 'id', User::TABLE)
+ ->join(self::TABLE, 'group_id', 'group_id', GroupMember::TABLE)
->eq(self::TABLE.'.project_id', $project_id)
->in(self::TABLE.'.role', array(Role::PROJECT_MANAGER, Role::PROJECT_MEMBER))
->asc(User::TABLE.'.username')
diff --git a/app/Model/UserNotification.php b/app/Model/UserNotification.php
index 8161288c..e8a967ac 100644
--- a/app/Model/UserNotification.php
+++ b/app/Model/UserNotification.php
@@ -71,7 +71,17 @@ class UserNotification extends Base
return $this->getEverybodyWithNotificationEnabled($exclude_user_id);
}
- return $this->getProjectMembersWithNotificationEnabled($project_id, $exclude_user_id);
+ $users = array();
+ $members = $this->getProjectUserMembersWithNotificationEnabled($project_id, $exclude_user_id);
+ $groups = $this->getProjectGroupMembersWithNotificationEnabled($project_id, $exclude_user_id);
+
+ foreach (array_merge($members, $groups) as $user) {
+ if (! isset($users[$user['id']])) {
+ $users[$user['id']] = $user;
+ }
+ }
+
+ return array_values($users);
}
/**
@@ -142,14 +152,14 @@ class UserNotification extends Base
}
/**
- * Get a list of project members with notification enabled
+ * Get a list of group members with notification enabled
*
* @access private
* @param integer $project_id Project id
* @param integer $exclude_user_id User id to exclude
* @return array
*/
- private function getProjectMembersWithNotificationEnabled($project_id, $exclude_user_id)
+ private function getProjectUserMembersWithNotificationEnabled($project_id, $exclude_user_id)
{
return $this->db
->table(ProjectUserRole::TABLE)
@@ -161,6 +171,19 @@ class UserNotification extends Base
->findAll();
}
+ private function getProjectGroupMembersWithNotificationEnabled($project_id, $exclude_user_id)
+ {
+ return $this->db
+ ->table(ProjectGroupRole::TABLE)
+ ->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name', User::TABLE.'.email', User::TABLE.'.language', User::TABLE.'.notifications_filter')
+ ->join(GroupMember::TABLE, 'group_id', 'group_id', ProjectGroupRole::TABLE)
+ ->join(User::TABLE, 'id', 'user_id', GroupMember::TABLE)
+ ->eq(ProjectGroupRole::TABLE.'.project_id', $project_id)
+ ->eq(User::TABLE.'.notifications_enabled', '1')
+ ->neq(User::TABLE.'.id', $exclude_user_id)
+ ->findAll();
+ }
+
/**
* Get a list of project members with notification enabled
*
diff --git a/tests/units/Model/UserNotificationTest.php b/tests/units/Model/UserNotificationTest.php
index bf3b1b3f..8168a375 100644
--- a/tests/units/Model/UserNotificationTest.php
+++ b/tests/units/Model/UserNotificationTest.php
@@ -7,11 +7,14 @@ use Kanboard\Model\TaskCreation;
use Kanboard\Model\Subtask;
use Kanboard\Model\Comment;
use Kanboard\Model\User;
+use Kanboard\Model\Group;
+use Kanboard\Model\GroupMember;
use Kanboard\Model\File;
use Kanboard\Model\Project;
use Kanboard\Model\ProjectPermission;
use Kanboard\Model\Task;
use Kanboard\Model\ProjectUserRole;
+use Kanboard\Model\ProjectGroupRole;
use Kanboard\Model\UserNotification;
use Kanboard\Model\UserNotificationFilter;
use Kanboard\Model\UserNotificationType;
@@ -98,6 +101,42 @@ class UserNotificationTest extends Base
$this->assertEquals(array(1), $settings['notification_projects']);
}
+ public function testGetGroupMembersWithNotificationEnabled()
+ {
+ $userModel = new User($this->container);
+ $groupModel = new Group($this->container);
+ $groupMemberModel = new GroupMember($this->container);
+ $projectModel = new Project($this->container);
+ $userNotificationModel = new UserNotification($this->container);
+ $projectGroupRole = new ProjectGroupRole($this->container);
+ $projectUserRole = new ProjectUserRole($this->container);
+
+ $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(1, $groupModel->create('G1'));
+ $this->assertEquals(2, $groupModel->create('G2'));
+
+ $this->assertTrue($groupMemberModel->addUser(1, 2));
+ $this->assertTrue($groupMemberModel->addUser(1, 3));
+ $this->assertTrue($groupMemberModel->addUser(1, 4));
+ $this->assertTrue($groupMemberModel->addUser(2, 2));
+ $this->assertTrue($groupMemberModel->addUser(2, 3));
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+
+ $this->assertTrue($projectGroupRole->addGroup(1, 1, Role::PROJECT_MEMBER));
+ $this->assertTrue($projectGroupRole->addGroup(1, 2, Role::PROJECT_VIEWER));
+
+ $this->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_MEMBER));
+
+ $users = $userNotificationModel->getUsersWithNotificationEnabled(1);
+ $this->assertCount(2, $users);
+ $this->assertEquals('user1', $users[0]['username']);
+ $this->assertEquals('user2', $users[1]['username']);
+ }
+
public function testGetProjectMembersWithNotifications()
{
$u = new User($this->container);