From 635b94fc8891135f5fe51d33f6be1fb5ab7d9900 Mon Sep 17 00:00:00 2001 From: Johannes Nussbaum Date: Wed, 11 Oct 2023 09:43:09 +0200 Subject: [PATCH] edit --- dsp_permissions_scripts/models/scope.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/dsp_permissions_scripts/models/scope.py b/dsp_permissions_scripts/models/scope.py index 2acead56..111b1365 100644 --- a/dsp_permissions_scripts/models/scope.py +++ b/dsp_permissions_scripts/models/scope.py @@ -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(