1
- from gitlab import cli ,types
2
- from gitlab import exceptions as exc
1
+ from gitlab import types
3
2
from gitlab .base import RequiredOptional ,RESTManager ,RESTObject
4
- from gitlab .mixins import CRUDMixin ,ObjectDeleteMixin ,SaveMixin
5
-
3
+ from gitlab .mixins import (
4
+ CRUDMixin ,
5
+ ObjectDeleteMixin ,
6
+ SaveMixin ,
7
+ RetrieveMixin ,
8
+ MemberAllMixin ,
9
+ )
6
10
7
11
__all__ = [
8
12
"GroupMember" ,
9
13
"GroupMemberManager" ,
14
+ "GroupMemberAllManager" ,
10
15
"ProjectMember" ,
11
16
"ProjectMemberManager" ,
17
+ "ProjectMemberAllManager" ,
12
18
]
13
19
14
20
15
21
class GroupMember (SaveMixin ,ObjectDeleteMixin ,RESTObject ):
16
22
_short_print_attr = "username"
17
23
18
24
19
- class GroupMemberManager (CRUDMixin ,RESTManager ):
25
+ class GroupMemberManager (MemberAllMixin , CRUDMixin ,RESTManager ):
20
26
_path = "/groups/%(group_id)s/members"
21
27
_obj_cls = GroupMember
22
28
_from_parent_attrs = {"group_id" :"id" }
@@ -28,37 +34,18 @@ class GroupMemberManager(CRUDMixin, RESTManager):
28
34
)
29
35
_types = {"user_ids" :types .ListAttribute }
30
36
31
- @cli .register_custom_action ("GroupMemberManager" )
32
- @exc .on_http_error (exc .GitlabListError )
33
- def all (self ,** kwargs ):
34
- """List all the members, included inherited ones.
35
-
36
- Args:
37
- all (bool): If True, return all the items, without pagination
38
- per_page (int): Number of items to retrieve per request
39
- page (int): ID of the page to return (starts with page 1)
40
- as_list (bool): If set to False and no pagination option is
41
- defined, return a generator instead of a list
42
- **kwargs: Extra options to send to the server (e.g. sudo)
43
-
44
- Raises:
45
- GitlabAuthenticationError: If authentication is not correct
46
- GitlabListError: If the list could not be retrieved
47
37
48
- Returns:
49
- RESTObjectList: The list of members
50
- """
51
-
52
- path = "%s/all" % self .path
53
- obj = self .gitlab .http_list (path ,** kwargs )
54
- return [self ._obj_cls (self ,item )for item in obj ]
38
+ class GroupMemberAllManager (RetrieveMixin ,RESTManager ):
39
+ _path = "/groups/%(group_id)s/members/all"
40
+ _obj_cls = GroupMember
41
+ _from_parent_attrs = {"group_id" :"id" }
55
42
56
43
57
44
class ProjectMember (SaveMixin ,ObjectDeleteMixin ,RESTObject ):
58
45
_short_print_attr = "username"
59
46
60
47
61
- class ProjectMemberManager (CRUDMixin ,RESTManager ):
48
+ class ProjectMemberManager (MemberAllMixin , CRUDMixin ,RESTManager ):
62
49
_path = "/projects/%(project_id)s/members"
63
50
_obj_cls = ProjectMember
64
51
_from_parent_attrs = {"project_id" :"id" }
@@ -70,27 +57,8 @@ class ProjectMemberManager(CRUDMixin, RESTManager):
70
57
)
71
58
_types = {"user_ids" :types .ListAttribute }
72
59
73
- @cli .register_custom_action ("ProjectMemberManager" )
74
- @exc .on_http_error (exc .GitlabListError )
75
- def all (self ,** kwargs ):
76
- """List all the members, included inherited ones.
77
60
78
- Args:
79
- all (bool): If True, return all the items, without pagination
80
- per_page (int): Number of items to retrieve per request
81
- page (int): ID of the page to return (starts with page 1)
82
- as_list (bool): If set to False and no pagination option is
83
- defined, return a generator instead of a list
84
- **kwargs: Extra options to send to the server (e.g. sudo)
85
-
86
- Raises:
87
- GitlabAuthenticationError: If authentication is not correct
88
- GitlabListError: If the list could not be retrieved
89
-
90
- Returns:
91
- RESTObjectList: The list of members
92
- """
93
-
94
- path = "%s/all" % self .path
95
- obj = self .gitlab .http_list (path ,** kwargs )
96
- return [self ._obj_cls (self ,item )for item in obj ]
61
+ class ProjectMemberAllManager (RetrieveMixin ,RESTManager ):
62
+ _path = "/projects/%(project_id)s/members/all"
63
+ _obj_cls = ProjectMember
64
+ _from_parent_attrs = {"project_id" :"id" }