Debian Codegraph @

src/globus_sdk/services/groups/manager.py

raw
1 from __future__ import annotations
2
3 import typing as t
4 import uuid
5
6 from globus_sdk import response
7
8 from .client import GroupsClient
9 from .data import (
10 _GROUP_MEMBER_VISIBILITY_T,
11 _GROUP_REQUIRED_SIGNUP_FIELDS_T,
12 _GROUP_ROLE_T,
13 _GROUP_VISIBILITY_T,
14 BatchMembershipActions,
15 GroupPolicies,
16 )
17
18
19 class GroupsManager:
20 """
21 A wrapper for the groups client with common membership and group actions
22 wrapped in convenient methods with parameters and type hints.
23
24 .. automethodlist:: globus_sdk.GroupsManager
25 """
26
27 def __init__(self, client: GroupsClient | None = None) -> None:
28 self.client = client or GroupsClient()
29
30 def create_group(
31 self,
32 name: str,
33 description: str,
34 *,
35 parent_id: uuid.UUID | str | None = None,
36 ) -> response.GlobusHTTPResponse:
37 """
38 Create a group with the given name. If a parent ID is included, the
39 group will be a subgroup of the given parent group.
40
41 :param name: The name of the group
42 :param description: A description of the group
43 :param parent_id: The ID of the parent group, if there is one
44 """
45 data = {
46 "name": name,
47 "description": description,
48 "parent_id": str(parent_id) if parent_id is not None else None,
49 }
50 return self.client.create_group(data=data)
51
52 def set_group_policies(
53 self,
54 group_id: uuid.UUID | str,
55 *,
56 is_high_assurance: bool,
57 group_visibility: _GROUP_VISIBILITY_T,
58 group_members_visibility: _GROUP_MEMBER_VISIBILITY_T,
59 join_requests: bool,
60 signup_fields: t.Iterable[_GROUP_REQUIRED_SIGNUP_FIELDS_T],
61 authentication_assurance_timeout: int | None = None,
62 ) -> response.GlobusHTTPResponse:
63 """
64 Set the group policies for the given group.
65
66 :param group_id: The ID of the group on which to set policies
67 :param is_high_assurance: Whether the group can provide a High Assurance
68 guarantee when used for access controls
69 :param group_visibility: The visibility of the group
70 :param group_members_visibility: The visibility of memberships within the group
71 :param join_requests: Whether the group allows users to request to join
72 :param signup_fields: The required fields for a user to sign up for the group
73 :param authentication_assurance_timeout: The timeout used when this group is
74 used to apply a High Assurance authentication guarantee
75 """
76 data = GroupPolicies(
77 is_high_assurance=is_high_assurance,
78 group_visibility=group_visibility,
79 group_members_visibility=group_members_visibility,
80 join_requests=join_requests,
81 signup_fields=signup_fields,
82 authentication_assurance_timeout=authentication_assurance_timeout,
83 )
84 return self.client.set_group_policies(group_id, data=data)
85
86 def accept_invite(
87 self, group_id: uuid.UUID | str, identity_id: uuid.UUID | str
88 ) -> response.GlobusHTTPResponse:
89 """
90 Accept invite for an identity. The identity must belong to
91 the identity set of the authenticated user.
92
93 :param group_id: The ID of the group
94 :param identity_id: The identity for whom to accept the invite
95 """
96 actions = BatchMembershipActions().accept_invites([identity_id])
97 return self.client.batch_membership_action(group_id, actions)
98
99 def add_member(
100 self,
101 group_id: uuid.UUID | str,
102 identity_id: uuid.UUID | str,
103 *,
104 role: _GROUP_ROLE_T = "member",
105 ) -> response.GlobusHTTPResponse:
106 """
107 Add an identity to a group with the given role.
108
109 :param group_id: The ID of the group
110 :param identity_id: The identity to add to the group
111 :param role: The role for the new group member
112 """
113 actions = BatchMembershipActions().add_members([identity_id], role=role)
114 return self.client.batch_membership_action(group_id, actions)
115
116 def approve_pending(
117 self, group_id: uuid.UUID | str, identity_id: uuid.UUID | str
118 ) -> response.GlobusHTTPResponse:
119 """
120 Approve an identity with a pending join request.
121
122 :param group_id: The ID of the group
123 :param identity_id: The identity to approve as a member of the group
124 """
125 actions = BatchMembershipActions().approve_pending([identity_id])
126 return self.client.batch_membership_action(group_id, actions)
127
128 def change_role(
129 self,
130 group_id: uuid.UUID | str,
131 identity_id: uuid.UUID | str,
132 role: _GROUP_ROLE_T,
133 ) -> response.GlobusHTTPResponse:
134 """
135 Change the role of the given identity in the given group.
136
137 :param group_id: The ID of the group
138 :param identity_id: The identity to assign the *role* to
139 :param role: The role that will be assigned to the *identity_id*
140 """
141 actions = BatchMembershipActions().change_roles(role, [identity_id])
142 return self.client.batch_membership_action(group_id, actions)
143
144 def decline_invite(
145 self, group_id: uuid.UUID | str, identity_id: uuid.UUID | str
146 ) -> response.GlobusHTTPResponse:
147 """
148 Decline an invitation for a given identity.
149
150 :param group_id: The ID of the group
151 :param identity_id: The identity for whom to decline the invitation
152 """
153 actions = BatchMembershipActions().decline_invites([identity_id])
154 return self.client.batch_membership_action(group_id, actions)
155
156 def invite_member(
157 self,
158 group_id: uuid.UUID | str,
159 identity_id: uuid.UUID | str,
160 *,
161 role: _GROUP_ROLE_T = "member",
162 ) -> response.GlobusHTTPResponse:
163 """
164 Invite an identity to a group with the given role.
165
166 :param group_id: The ID of the group
167 :param identity_id: The identity to invite as a new group member
168 :param role: The role for the invited group member
169 """
170 actions = BatchMembershipActions().invite_members([identity_id], role=role)
171 return self.client.batch_membership_action(group_id, actions)
172
173 def join(
174 self, group_id: uuid.UUID | str, identity_id: uuid.UUID | str
175 ) -> response.GlobusHTTPResponse:
176 """
177 Join a group with the given identity. The identity must be in the
178 authenticated users identity set.
179
180 :param group_id: The ID of the group
181 :param identity_id: The identity to use to join the group
182 """
183 actions = BatchMembershipActions().join([identity_id])
184 return self.client.batch_membership_action(group_id, actions)
185
186 def leave(
187 self, group_id: uuid.UUID | str, identity_id: uuid.UUID | str
188 ) -> response.GlobusHTTPResponse:
189 """
190 Leave a group that one of the identities in the authenticated user's
191 identity set is a member of.
192
193 :param group_id: The ID of the group
194 :param identity_id: The identity to remove from the group
195 """
196 actions = BatchMembershipActions().leave([identity_id])
197 return self.client.batch_membership_action(group_id, actions)
198
199 def reject_join_request(
200 self, group_id: uuid.UUID | str, identity_id: uuid.UUID | str
201 ) -> response.GlobusHTTPResponse:
202 """
203 Reject a member that has requested to join the group.
204
205 :param group_id: The ID of the group
206 :param identity_id: The identity to reject from the group
207 """
208 actions = BatchMembershipActions().reject_join_requests([identity_id])
209 return self.client.batch_membership_action(group_id, actions)
210
211 def remove_member(
212 self, group_id: uuid.UUID | str, identity_id: uuid.UUID | str
213 ) -> response.GlobusHTTPResponse:
214 """
215 Remove a member from a group. This must be done as an admin or manager
216 of the group.
217
218 :param group_id: The ID of the group
219 :param identity_id: The identity to remove from the group
220 """
221 actions = BatchMembershipActions().remove_members([identity_id])
222 return self.client.batch_membership_action(group_id, actions)
223
224 def request_join(
225 self, group_id: uuid.UUID | str, identity_id: uuid.UUID | str
226 ) -> response.GlobusHTTPResponse:
227 """
228 Request to join a group.
229
230 :param group_id: The ID of the group
231 :param identity_id: The identity to use to request membership in the group
232 """
233 actions = BatchMembershipActions().request_join([identity_id])
234 return self.client.batch_membership_action(group_id, actions)