summaryrefslogtreecommitdiff
path: root/gitlab/v4
diff options
context:
space:
mode:
authorOleksii Shkurupii <Oleksii.Shkurupii@playtech.com>2021-03-15 18:10:03 +0200
committerNejc Habjan <hab.nejc@gmail.com>2021-05-07 00:47:11 +0200
commite444b39f9423b4a4c85cdb199afbad987df026f1 (patch)
tree6aabf2f22b5134ad6291209b4792446010e50999 /gitlab/v4
parent0d3b8aea752f487db22f22be87de3cde247f9ffb (diff)
downloadgitlab-e444b39f9423b4a4c85cdb199afbad987df026f1.tar.gz
feat: add feature to get inherited member for project/group
Diffstat (limited to 'gitlab/v4')
-rw-r--r--gitlab/v4/objects/groups.py3
-rw-r--r--gitlab/v4/objects/members.py72
-rw-r--r--gitlab/v4/objects/projects.py3
3 files changed, 24 insertions, 54 deletions
diff --git a/gitlab/v4/objects/groups.py b/gitlab/v4/objects/groups.py
index 9e27601..574c57b 100644
--- a/gitlab/v4/objects/groups.py
+++ b/gitlab/v4/objects/groups.py
@@ -11,7 +11,7 @@ from .export_import import GroupExportManager, GroupImportManager # noqa: F401
from .epics import GroupEpicManager # noqa: F401
from .issues import GroupIssueManager # noqa: F401
from .labels import GroupLabelManager # noqa: F401
-from .members import GroupMemberManager # noqa: F401
+from .members import GroupMemberManager, GroupMemberAllManager # noqa: F401
from .merge_requests import GroupMergeRequestManager # noqa: F401
from .milestones import GroupMilestoneManager # noqa: F401
from .notification_settings import GroupNotificationSettingsManager # noqa: F401
@@ -45,6 +45,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject):
("issues", "GroupIssueManager"),
("labels", "GroupLabelManager"),
("members", "GroupMemberManager"),
+ ("members_all", "GroupMemberAllManager"),
("mergerequests", "GroupMergeRequestManager"),
("milestones", "GroupMilestoneManager"),
("notificationsettings", "GroupNotificationSettingsManager"),
diff --git a/gitlab/v4/objects/members.py b/gitlab/v4/objects/members.py
index 2686587..839c89e 100644
--- a/gitlab/v4/objects/members.py
+++ b/gitlab/v4/objects/members.py
@@ -1,14 +1,20 @@
-from gitlab import cli, types
-from gitlab import exceptions as exc
+from gitlab import types
from gitlab.base import RequiredOptional, RESTManager, RESTObject
-from gitlab.mixins import CRUDMixin, ObjectDeleteMixin, SaveMixin
-
+from gitlab.mixins import (
+ CRUDMixin,
+ ObjectDeleteMixin,
+ SaveMixin,
+ RetrieveMixin,
+ MemberAllMixin,
+)
__all__ = [
"GroupMember",
"GroupMemberManager",
+ "GroupMemberAllManager",
"ProjectMember",
"ProjectMemberManager",
+ "ProjectMemberAllManager",
]
@@ -16,7 +22,7 @@ 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"}
@@ -28,37 +34,18 @@ class GroupMemberManager(CRUDMixin, RESTManager):
)
_types = {"user_ids": types.ListAttribute}
- @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 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"}
@@ -70,27 +57,8 @@ class ProjectMemberManager(CRUDMixin, RESTManager):
)
_types = {"user_ids": types.ListAttribute}
- @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"}
diff --git a/gitlab/v4/objects/projects.py b/gitlab/v4/objects/projects.py
index 4618292..4223b18 100644
--- a/gitlab/v4/objects/projects.py
+++ b/gitlab/v4/objects/projects.py
@@ -32,7 +32,7 @@ from .hooks import ProjectHookManager # noqa: F401
from .issues import ProjectIssueManager # noqa: F401
from .jobs import ProjectJobManager # noqa: F401
from .labels import ProjectLabelManager # noqa: F401
-from .members import ProjectMemberManager # noqa: F401
+from .members import ProjectMemberManager, ProjectMemberAllManager # noqa: F401
from .merge_request_approvals import ( # noqa: F401
ProjectApprovalManager,
ProjectApprovalRuleManager,
@@ -130,6 +130,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO
("issues", "ProjectIssueManager"),
("labels", "ProjectLabelManager"),
("members", "ProjectMemberManager"),
+ ("members_all", "ProjectMemberAllManager"),
("mergerequests", "ProjectMergeRequestManager"),
("milestones", "ProjectMilestoneManager"),
("notes", "ProjectNoteManager"),