Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Added
-----

- Add ``.change_role()`` to the Globus Groups ``BatchMembershipActions`` helper class. (:pr:`NUMBER`)
- Add ``.change_roles()`` to the Globus Groups ``GroupsManager`` class. (:pr:`NUMBER`)
16 changes: 16 additions & 0 deletions src/globus_sdk/services/groups/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,22 @@ def approve_pending(
)
return self

def change_roles(
self,
role: _GROUP_ROLE_T,
identity_ids: t.Iterable[uuid.UUID | str],
) -> BatchMembershipActions:
"""
Assign a new role to a list of identities.

:param role: The new role to assign.
:param identity_ids: The identities to assign to the new role.
"""
self.setdefault("change_role", []).extend(
{"role": role, "identity_id": identity_id} for identity_id in identity_ids
)
return self

def decline_invites(
self, identity_ids: t.Iterable[uuid.UUID | str]
) -> BatchMembershipActions:
Expand Down
16 changes: 16 additions & 0 deletions src/globus_sdk/services/groups/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ def approve_pending(
actions = BatchMembershipActions().approve_pending([identity_id])
return self.client.batch_membership_action(group_id, actions)

def change_role(
self,
group_id: uuid.UUID | str,
identity_id: uuid.UUID | str,
role: _GROUP_ROLE_T,
) -> response.GlobusHTTPResponse:
"""
Change the role of the given identity in the given group.

:param group_id: The ID of the group
:param identity_id: The identity to assign the *role* to
:param role: The role that will be assigned to the *identity_id*
"""
actions = BatchMembershipActions().change_roles(role, [identity_id])
return self.client.batch_membership_action(group_id, actions)

def decline_invite(
self, group_id: uuid.UUID | str, identity_id: uuid.UUID | str
) -> response.GlobusHTTPResponse:
Expand Down
6 changes: 6 additions & 0 deletions tests/functional/services/groups/test_group_memberships.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def test_batch_action_payload(groups_client, role):
[uuid.uuid1(), uuid.uuid1()],
role=role,
)
.change_roles("admin", [uuid.uuid1(), uuid.uuid1()])
.invite_members([uuid.uuid1(), uuid.uuid1()])
.join([uuid.uuid1(), uuid.uuid1()])
)
Expand All @@ -86,6 +87,11 @@ def test_batch_action_payload(groups_client, role):
assert "accept" in batch_action
assert len(batch_action["accept"]) == 1

assert "change_role" in batch_action
assert len(batch_action["change_role"]) == 2
for change_role in batch_action["change_role"]:
assert change_role["role"] == "admin"

assert "invite" in batch_action
assert len(batch_action["invite"]) == 2

Expand Down
Loading