Commit 8482a5d7 authored by Roald Nefs's avatar Roald Nefs Committed by Sander van Harmelen

Add option to list inherited members (#485)

Add option to list inherited project and group members. Updated the
documentation of the existing `ListProjectMembers` and
`ListGroupMembers` functions for clarity.

Fixes #484
parent 2a9bc9a2
...@@ -44,8 +44,8 @@ type GroupMember struct { ...@@ -44,8 +44,8 @@ type GroupMember struct {
ExpiresAt *ISOTime `json:"expires_at"` ExpiresAt *ISOTime `json:"expires_at"`
} }
// ListGroupMembersOptions represents the available ListGroupMembers() // ListGroupMembersOptions represents the available ListGroupMembers() and
// options. // ListAllGroupMembers() options.
// //
// GitLab API docs: // GitLab API docs:
// https://docs.gitlab.com/ce/api/members.html#list-all-members-of-a-group-or-project // https://docs.gitlab.com/ce/api/members.html#list-all-members-of-a-group-or-project
...@@ -55,7 +55,7 @@ type ListGroupMembersOptions struct { ...@@ -55,7 +55,7 @@ type ListGroupMembersOptions struct {
} }
// ListGroupMembers get a list of group members viewable by the authenticated // ListGroupMembers get a list of group members viewable by the authenticated
// user. // user. Returns a list including inherited members through ancestor groups.
// //
// GitLab API docs: // GitLab API docs:
// https://docs.gitlab.com/ce/api/members.html#list-all-members-of-a-group-or-project // https://docs.gitlab.com/ce/api/members.html#list-all-members-of-a-group-or-project
...@@ -80,6 +80,32 @@ func (s *GroupsService) ListGroupMembers(gid interface{}, opt *ListGroupMembersO ...@@ -80,6 +80,32 @@ func (s *GroupsService) ListGroupMembers(gid interface{}, opt *ListGroupMembersO
return gm, resp, err return gm, resp, err
} }
// ListAllGroupMembers get a list of group members viewable by the authenticated
// user. Returns a list including inherited members through ancestor groups.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/members.html#list-all-members-of-a-group-or-project-including-inherited-members
func (s *GroupsService) ListAllGroupMembers(gid interface{}, opt *ListGroupMembersOptions, options ...OptionFunc) ([]*GroupMember, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/members/all", url.QueryEscape(group))
req, err := s.client.NewRequest("GET", u, opt, options)
if err != nil {
return nil, nil, err
}
var gm []*GroupMember
resp, err := s.client.Do(req, &gm)
if err != nil {
return nil, resp, err
}
return gm, resp, err
}
// AddGroupMemberOptions represents the available AddGroupMember() options. // AddGroupMemberOptions represents the available AddGroupMember() options.
// //
// GitLab API docs: // GitLab API docs:
......
...@@ -29,8 +29,8 @@ type ProjectMembersService struct { ...@@ -29,8 +29,8 @@ type ProjectMembersService struct {
client *Client client *Client
} }
// ListProjectMembersOptions represents the available ListProjectMembers() // ListProjectMembersOptions represents the available ListProjectMembers() and
// options. // ListAllProjectMembers() options.
// //
// GitLab API docs: // GitLab API docs:
// https://docs.gitlab.com/ce/api/members.html#list-all-members-of-a-group-or-project // https://docs.gitlab.com/ce/api/members.html#list-all-members-of-a-group-or-project
...@@ -39,7 +39,9 @@ type ListProjectMembersOptions struct { ...@@ -39,7 +39,9 @@ type ListProjectMembersOptions struct {
Query *string `url:"query,omitempty" json:"query,omitempty"` Query *string `url:"query,omitempty" json:"query,omitempty"`
} }
// ListProjectMembers gets a list of a project's team members. // ListProjectMembers gets a list of a project's team members viewable by the
// authenticated user. Returns only direct members and not inherited members
// through ancestors groups.
// //
// GitLab API docs: // GitLab API docs:
// https://docs.gitlab.com/ce/api/members.html#list-all-members-of-a-group-or-project // https://docs.gitlab.com/ce/api/members.html#list-all-members-of-a-group-or-project
...@@ -64,6 +66,33 @@ func (s *ProjectMembersService) ListProjectMembers(pid interface{}, opt *ListPro ...@@ -64,6 +66,33 @@ func (s *ProjectMembersService) ListProjectMembers(pid interface{}, opt *ListPro
return pm, resp, err return pm, resp, err
} }
// ListAllProjectMembers gets a list of a project's team members viewable by the
// authenticated user. Returns a list including inherited members through
// ancestor groups.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/members.html#list-all-members-of-a-group-or-project-including-inherited-members
func (s *ProjectMembersService) ListAllProjectMembers(pid interface{}, opt *ListProjectMembersOptions, options ...OptionFunc) ([]*ProjectMember, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/members/all", url.QueryEscape(project))
req, err := s.client.NewRequest("GET", u, opt, options)
if err != nil {
return nil, nil, err
}
var pm []*ProjectMember
resp, err := s.client.Do(req, &pm)
if err != nil {
return nil, resp, err
}
return pm, resp, err
}
// GetProjectMember gets a project team member. // GetProjectMember gets a project team member.
// //
// GitLab API docs: // GitLab API docs:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment