Skip to content

Commit

Permalink
edit
Browse files Browse the repository at this point in the history
  • Loading branch information
jnussbaum committed Oct 11, 2023
1 parent 569df84 commit 635b94f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions dsp_permissions_scripts/models/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,23 @@ def add(
if perm != permission:
kwargs[perm] = getattr(self, perm)
return PermissionScope.create(**kwargs)

def remove(
self,
permission: Literal["CR", "D", "M", "V", "RV"],
group: str | BuiltinGroup,
) -> PermissionScope:
"""Return a copy of the PermissionScope instance with group removed from permission."""
groups = [g.value if isinstance(g, BuiltinGroup) else g for g in getattr(self, permission)]
group = group.value if isinstance(group, BuiltinGroup) else group
if group not in groups:
raise ValueError(f"Group '{group}' is not in permission '{permission}'")
groups.remove(group)
kwargs: dict[str, list[str]] = {permission: groups}
for perm in ["CR", "D", "M", "V", "RV"]:
if perm != permission:
kwargs[perm] = getattr(self, perm)
return PermissionScope.create(**kwargs)


PUBLIC = PermissionScope.create(
Expand Down

0 comments on commit 635b94f

Please sign in to comment.