diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-04-21 21:10:04 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-04-21 21:10:04 -0400 |
commit | 60e0753b90838120510861ebc674f826140b31de (patch) | |
tree | f85b81e439adad8b3011c3127442c822740b02d0 | |
parent | b0e41bc81b40cfdc5e067bf1eb4d05e3aa438c7d (diff) |
Added API procedure "getMemberGroups"
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | app/Api/GroupMember.php | 5 | ||||
-rw-r--r-- | app/Model/GroupMember.php | 17 | ||||
-rw-r--r-- | doc/api-group-member-procedures.markdown | 36 | ||||
-rw-r--r-- | tests/integration/GroupMemberTest.php | 8 | ||||
-rw-r--r-- | tests/units/Model/GroupMemberTest.php | 30 |
6 files changed, 97 insertions, 0 deletions
@@ -10,6 +10,7 @@ New features: Improvements: +* Added API procedure "getMemberGroups" * Added parameters for overdue tasks notifications: group by projects and send only to managers * Allow people to install Kanboard outside of the DocumentRoot * Allow plugins to be loaded from another folder diff --git a/app/Api/GroupMember.php b/app/Api/GroupMember.php index de62f0c6..9d2a4796 100644 --- a/app/Api/GroupMember.php +++ b/app/Api/GroupMember.php @@ -10,6 +10,11 @@ namespace Kanboard\Api; */ class GroupMember extends \Kanboard\Core\Base { + public function getMemberGroups($user_id) + { + return $this->groupMember->getGroups($user_id); + } + public function getGroupMembers($group_id) { return $this->groupMember->getMembers($group_id); diff --git a/app/Model/GroupMember.php b/app/Model/GroupMember.php index 7ed5f733..14041704 100644 --- a/app/Model/GroupMember.php +++ b/app/Model/GroupMember.php @@ -108,4 +108,21 @@ class GroupMember extends Base ->eq('user_id', $user_id) ->exists(); } + + /** + * Get all groups for a given user + * + * @access public + * @param integer $user_id + * @return array + */ + public function getGroups($user_id) + { + return $this->db->table(self::TABLE) + ->columns(Group::TABLE.'.id', Group::TABLE.'.name') + ->join(Group::TABLE, 'id', 'group_id') + ->eq(self::TABLE.'.user_id', $user_id) + ->asc(Group::TABLE.'.name') + ->findAll(); + } } diff --git a/doc/api-group-member-procedures.markdown b/doc/api-group-member-procedures.markdown index c4889265..1065ba11 100644 --- a/doc/api-group-member-procedures.markdown +++ b/doc/api-group-member-procedures.markdown @@ -1,6 +1,42 @@ Group Member API Procedures =========================== +## getMemberGroups + +- Purpose: **Get all groups for a given user** +- Parameters: + - **user_id** (integer, required) +- Result on success: **List of groups** +- Result on failure: **false** + +Request example: + +```json +{ + "jsonrpc": "2.0", + "method": "getMemberGroups", + "id": 1987176726, + "params": [ + "1" + ] +} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "id": 1987176726, + "result": [ + { + "id": "1", + "name": "My Group A" + } + ] +} +``` + ## getGroupMembers - Purpose: **Get all members of a group** diff --git a/tests/integration/GroupMemberTest.php b/tests/integration/GroupMemberTest.php index e84c0734..d49945b5 100644 --- a/tests/integration/GroupMemberTest.php +++ b/tests/integration/GroupMemberTest.php @@ -30,6 +30,14 @@ class GroupMemberTest extends Base $this->assertFalse($this->app->isGroupMember($groupId, 2)); } + public function testGetGroups() + { + $groups = $this->app->getMemberGroups(1); + $this->assertCount(1, $groups); + $this->assertEquals(1, $groups[0]['id']); + $this->assertEquals('My Group A', $groups[0]['name']); + } + public function testRemove() { $groupId = $this->getGroupId(); diff --git a/tests/units/Model/GroupMemberTest.php b/tests/units/Model/GroupMemberTest.php index 16f769e8..0ff9fdf6 100644 --- a/tests/units/Model/GroupMemberTest.php +++ b/tests/units/Model/GroupMemberTest.php @@ -72,5 +72,35 @@ class GroupMemberTest extends Base $this->assertCount(2, $users); $this->assertEquals('admin', $users[0]['username']); $this->assertEquals('user1', $users[1]['username']); + + $groups = $groupMemberModel->getGroups(1); + $this->assertCount(1, $groups); + $this->assertEquals(1, $groups[0]['id']); + $this->assertEquals('Group A', $groups[0]['name']); + + $groups = $groupMemberModel->getGroups(2); + $this->assertCount(1, $groups); + $this->assertEquals(1, $groups[0]['id']); + $this->assertEquals('Group A', $groups[0]['name']); + + $groups = $groupMemberModel->getGroups(3); + $this->assertCount(1, $groups); + $this->assertEquals(2, $groups[0]['id']); + $this->assertEquals('Group B', $groups[0]['name']); + + $groups = $groupMemberModel->getGroups(4); + $this->assertCount(1, $groups); + $this->assertEquals(2, $groups[0]['id']); + $this->assertEquals('Group B', $groups[0]['name']); + + $groups = $groupMemberModel->getGroups(5); + $this->assertCount(2, $groups); + $this->assertEquals(1, $groups[0]['id']); + $this->assertEquals('Group A', $groups[0]['name']); + $this->assertEquals(2, $groups[1]['id']); + $this->assertEquals('Group B', $groups[1]['name']); + + $groups = $groupMemberModel->getGroups(6); + $this->assertCount(0, $groups); } } |