-
Notifications
You must be signed in to change notification settings - Fork 671
feat: add feature to get inherited member for project/group #1187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1b62c2e
50f4b9c
565151a
55cdad8
323c279
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1163,37 +1163,18 @@ class GroupMember(SaveMixin, ObjectDeleteMixin, RESTObject): | |
_short_print_attr = "username" | ||
|
||
|
||
class GroupMemberManager(CRUDMixin, RESTManager): | ||
class GroupMemberManager(MemberAllMixin, CRUDMixin, RESTManager): | ||
_path = "/groups/%(group_id)s/members" | ||
_obj_cls = GroupMember | ||
_from_parent_attrs = {"group_id": "id"} | ||
_create_attrs = (("access_level", "user_id"), ("expires_at",)) | ||
_update_attrs = (("access_level",), ("expires_at",)) | ||
|
||
@cli.register_custom_action("GroupMemberManager") | ||
@exc.on_http_error(exc.GitlabListError) | ||
def all(self, **kwargs): | ||
"""List all the members, included inherited ones. | ||
|
||
Args: | ||
all (bool): If True, return all the items, without pagination | ||
per_page (int): Number of items to retrieve per request | ||
page (int): ID of the page to return (starts with page 1) | ||
as_list (bool): If set to False and no pagination option is | ||
defined, return a generator instead of a list | ||
**kwargs: Extra options to send to the server (e.g. sudo) | ||
|
||
Raises: | ||
GitlabAuthenticationError: If authentication is not correct | ||
GitlabListError: If the list could not be retrieved | ||
|
||
Returns: | ||
RESTObjectList: The list of members | ||
""" | ||
|
||
path = "%s/all" % self.path | ||
obj = self.gitlab.http_list(path, **kwargs) | ||
return [self._obj_cls(self, item) for item in obj] | ||
class GroupMemberAllManager(RetrieveMixin, RESTManager): | ||
_path = "/groups/%(group_id)s/members/all" | ||
_obj_cls = GroupMember | ||
_from_parent_attrs = {"group_id": "id"} | ||
|
||
|
||
class GroupMergeRequest(RESTObject): | ||
|
@@ -1394,6 +1375,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject): | |
("issues", "GroupIssueManager"), | ||
("labels", "GroupLabelManager"), | ||
("members", "GroupMemberManager"), | ||
("members_all", "GroupMemberAllManager"), | ||
("mergerequests", "GroupMergeRequestManager"), | ||
("milestones", "GroupMilestoneManager"), | ||
("notificationsettings", "GroupNotificationSettingsManager"), | ||
|
@@ -2831,37 +2813,18 @@ class ProjectMember(SaveMixin, ObjectDeleteMixin, RESTObject): | |
_short_print_attr = "username" | ||
|
||
|
||
class ProjectMemberManager(CRUDMixin, RESTManager): | ||
class ProjectMemberManager(MemberAllMixin, CRUDMixin, RESTManager): | ||
_path = "/projects/%(project_id)s/members" | ||
_obj_cls = ProjectMember | ||
_from_parent_attrs = {"project_id": "id"} | ||
_create_attrs = (("access_level", "user_id"), ("expires_at",)) | ||
_update_attrs = (("access_level",), ("expires_at",)) | ||
|
||
@cli.register_custom_action("ProjectMemberManager") | ||
@exc.on_http_error(exc.GitlabListError) | ||
def all(self, **kwargs): | ||
"""List all the members, included inherited ones. | ||
|
||
Args: | ||
all (bool): If True, return all the items, without pagination | ||
per_page (int): Number of items to retrieve per request | ||
page (int): ID of the page to return (starts with page 1) | ||
as_list (bool): If set to False and no pagination option is | ||
defined, return a generator instead of a list | ||
**kwargs: Extra options to send to the server (e.g. sudo) | ||
|
||
Raises: | ||
GitlabAuthenticationError: If authentication is not correct | ||
GitlabListError: If the list could not be retrieved | ||
|
||
Returns: | ||
RESTObjectList: The list of members | ||
""" | ||
|
||
path = "%s/all" % self.path | ||
obj = self.gitlab.http_list(path, **kwargs) | ||
return [self._obj_cls(self, item) for item in obj] | ||
class ProjectMemberAllManager(RetrieveMixin, RESTManager): | ||
_path = "/projects/%(project_id)s/members/all" | ||
_obj_cls = ProjectMember | ||
_from_parent_attrs = {"project_id": "id"} | ||
|
||
|
||
class ProjectNote(RESTObject): | ||
|
@@ -4595,6 +4558,7 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject): | |
("issues", "ProjectIssueManager"), | ||
("labels", "ProjectLabelManager"), | ||
("members", "ProjectMemberManager"), | ||
("members_all", "ProjectMemberAllManager"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For me the dilemma here is: Just asking because this pattern can be a precedent for improving other There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I spent a few minutes scanning the GitLab API and looks GitLab doesn't tend to make its addresses natural. Anyway, I am not a python Pro, final conclusion is up to you. |
||
("mergerequests", "ProjectMergeRequestManager"), | ||
("milestones", "ProjectMilestoneManager"), | ||
("notes", "ProjectNoteManager"), | ||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -312,7 +312,8 @@ | |||||||
|
||||||||
group1.members.delete(user1.id) | ||||||||
assert len(group1.members.list()) == 2 | ||||||||
assert len(group1.members.all()) | ||||||||
assert len(group1.members.all()) # Deprecated | ||||||||
assert len(group1.members_all.list()) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
As you can see in the test you've had to change in 50f4b9c, this would break the existing behavior for anyone who has relied on Maybe that can be done (temporarily) with a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I rolled back the test case group1.members.all() and added MemberAllMixin with |
||||||||
member = group1.members.get(user2.id) | ||||||||
member.access_level = gitlab.const.OWNER_ACCESS | ||||||||
member.save() | ||||||||
|
Uh oh!
There was an error while loading. Please reload this page.