Skip to content

Commit

Permalink
chore: replace class StandardScope by module-level constant (DEV-2725) (
Browse files Browse the repository at this point in the history
  • Loading branch information
jnussbaum authored Sep 29, 2023
1 parent b32f5ad commit dd809ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
4 changes: 2 additions & 2 deletions dsp_permissions_scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from dsp_permissions_scripts.models.groups import BuiltinGroup
from dsp_permissions_scripts.models.host import Hosts
from dsp_permissions_scripts.models.scope import StandardScope
from dsp_permissions_scripts.models.scope import PUBLIC
from dsp_permissions_scripts.utils.authentication import login
from dsp_permissions_scripts.utils.permissions import (
get_doaps_of_project,
Expand All @@ -29,7 +29,7 @@ def main() -> None:
)
token = login(host)

new_scope = StandardScope().PUBLIC
new_scope = PUBLIC
groups = [BuiltinGroup.PROJECT_ADMIN, BuiltinGroup.PROJECT_MEMBER]

doaps = get_doaps_of_project(
Expand Down
26 changes: 9 additions & 17 deletions dsp_permissions_scripts/models/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,19 @@


class PermissionScope(BaseModel):
"""
A scope is an object encoding the information:
"Which user group gets which permissions on a resource/value?"
"""
CR: list[str | BuiltinGroup] = []
D: list[str | BuiltinGroup] = []
M: list[str | BuiltinGroup] = []
V: list[str | BuiltinGroup] = []
RV: list[str | BuiltinGroup] = []


class StandardScope:
"""
A scope is an object encoding the information:
"Which user group gets which permissions on a resource/value?"
This class offers some predefined scopes.
If your preferred scope is not available,
please add a new class attribute and implement it in the __init__ method.
"""

PUBLIC: PermissionScope

def __init__(self):
self.PUBLIC = PermissionScope(
CR=[BuiltinGroup.PROJECT_ADMIN],
D=[BuiltinGroup.CREATOR, BuiltinGroup.PROJECT_MEMBER],
V=[BuiltinGroup.UNKNOWN_USER, BuiltinGroup.KNOWN_USER],
)
PUBLIC = PermissionScope(
CR=[BuiltinGroup.PROJECT_ADMIN],
D=[BuiltinGroup.CREATOR, BuiltinGroup.PROJECT_MEMBER],
V=[BuiltinGroup.UNKNOWN_USER, BuiltinGroup.KNOWN_USER],
)

0 comments on commit dd809ae

Please sign in to comment.