diff --git a/lib/Gitlab/Api/Groups.php b/lib/Gitlab/Api/Groups.php index 38039b787..b771dc579 100644 --- a/lib/Gitlab/Api/Groups.php +++ b/lib/Gitlab/Api/Groups.php @@ -91,15 +91,16 @@ public function transfer($group_id, $project_id) /** * @param integer $id + * @param integer|null $user_id * @param array $parameters * @return mixed */ - public function allMembers($id, array $parameters = []) + public function allMembers($id, $user_id = null, array $parameters = []) { $resolver = $this->createOptionsResolver(); $resolver->setDefined('query'); - return $this->get('groups/'.$this->encodePath($id).'/members/all', $resolver->resolve($parameters)); + return $this->get('groups/'.$this->encodePath($id).'/members/all/'.$this->encodePath($user_id), $resolver->resolve($parameters)); } /** diff --git a/lib/Gitlab/Api/Projects.php b/lib/Gitlab/Api/Projects.php index e5ea9b6cc..2569162e1 100644 --- a/lib/Gitlab/Api/Projects.php +++ b/lib/Gitlab/Api/Projects.php @@ -286,18 +286,19 @@ public function deletePipeline($project_id, $pipeline_id) { return $this->delete($this->getProjectPath($project_id, 'pipelines/'.$this->encodePath($pipeline_id))); } - + /** * @param integer $project_id + * @param integer|null $user_id * @param array $parameters * @return mixed */ - public function allMembers($project_id, $parameters = []) + public function allMembers($project_id, $user_id = null, $parameters = []) { $resolver = $this->createOptionsResolver(); $resolver->setDefined('query'); - return $this->get('projects/'.$this->encodePath($project_id).'/members/all', $resolver->resolve($parameters)); + return $this->get('projects/'.$this->encodePath($project_id).'/members/all/'.$this->encodePath($user_id), $resolver->resolve($parameters)); } /** diff --git a/lib/Gitlab/Model/Group.php b/lib/Gitlab/Model/Group.php index 97628f3d2..89f867ce4 100644 --- a/lib/Gitlab/Model/Group.php +++ b/lib/Gitlab/Model/Group.php @@ -116,6 +116,30 @@ public function transfer($project_id) return Group::fromArray($this->getClient(), $data); } + /** + * @param integer|null $user_id + * @param bool $all + * @return array|User + */ + public function allMembers($user_id = null, $all = false) + { + if ($all) { + $data = (new \Gitlab\ResultPager($this->client))->fetchAll($this->client->groups(), "allMembers", [$this->id, $user_id]); + } else { + $data = $this->client->groups()->allMembers($this->id, $user_id); + } + + if ($user_id != null) { + return User::fromArray($this->getClient(), $data); + } else { + $members = array(); + foreach ($data as $member) { + $members[] = User::fromArray($this->getClient(), $member); + } + return $members; + } + } + /** * @return User[] */ diff --git a/lib/Gitlab/Model/Project.php b/lib/Gitlab/Model/Project.php index 8d08c1165..471bdfa15 100644 --- a/lib/Gitlab/Model/Project.php +++ b/lib/Gitlab/Model/Project.php @@ -217,6 +217,30 @@ public function remove() return true; } + /** + * @param integer|null $user_id + * @param bool $all + * @return array|User + */ + public function allMembers($user_id = null, $all = false) + { + if ($all) { + $data = (new \Gitlab\ResultPager($this->client))->fetchAll($this->client->projects(), "allMembers", [$this->id, $user_id]); + } else { + $data = $this->client->projects()->allMembers($this->id, $user_id); + } + + if ($user_id != null) { + return User::fromArray($this->getClient(), $data); + } else { + $members = array(); + foreach ($data as $member) { + $members[] = User::fromArray($this->getClient(), $member); + } + return $members; + } + } + /** * @param string $username_query * @return User[] diff --git a/test/Gitlab/Tests/Api/GroupsTest.php b/test/Gitlab/Tests/Api/GroupsTest.php index b4da1de4d..571cf3193 100644 --- a/test/Gitlab/Tests/Api/GroupsTest.php +++ b/test/Gitlab/Tests/Api/GroupsTest.php @@ -199,13 +199,29 @@ public function shouldGetAllMembers() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('groups/1/members/all') + ->with('groups/1/members/all/') ->will($this->returnValue($expectedArray)) ; $this->assertEquals($expectedArray, $api->allMembers(1)); } + /** + * @test + */ + public function shouldGetAllMembersUserID() + { + $expectedArray = array('id' => 2, 'name' => 'Bob'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('groups/1/members/all/2') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->allMembers(1, 2)); + } + /** * @test */ diff --git a/test/Gitlab/Tests/Api/ProjectsTest.php b/test/Gitlab/Tests/Api/ProjectsTest.php index 043c4216b..9d85b61a4 100644 --- a/test/Gitlab/Tests/Api/ProjectsTest.php +++ b/test/Gitlab/Tests/Api/ProjectsTest.php @@ -661,12 +661,28 @@ public function shouldGetAllMembers() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('projects/1/members/all') + ->with('projects/1/members/all/') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->allMembers(1)); } + /** + * @test + */ + public function shouldGetAllMembersUserID() + { + $expectedArray = array('id' => 2, 'name' => 'Bob'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/members/all/2') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->allMembers(1, 2)); + } + /** * @test */