Skip to content

Commit

Permalink
pave the way for custom group, 3rd round (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
jnussbaum authored Oct 23, 2024
1 parent 1508a4e commit 37713be
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 31 deletions.
4 changes: 2 additions & 2 deletions dsp_permissions_scripts/models/group_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def sort_groups(groups_original: Iterable[Group]) -> list[Group]:
return groups


def _get_sort_pos_of_custom_group(group: str) -> int:
def _get_sort_pos_of_custom_group(prefixed_iri: str) -> int:
alphabet = list("abcdefghijklmnopqrstuvwxyz")
relevant_letter = group.replace("knora-admin:", "")[0]
relevant_letter = prefixed_iri.split(":")[-1][0]
return alphabet.index(relevant_letter.lower()) + 99 # must be higher than the highest index of the builtin groups


Expand Down
44 changes: 25 additions & 19 deletions tests/test_group_utils.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
import pytest

from dsp_permissions_scripts.models import group
from dsp_permissions_scripts.models.group import CREATOR
from dsp_permissions_scripts.models.group import KNOWN_USER
from dsp_permissions_scripts.models.group import PROJECT_ADMIN
from dsp_permissions_scripts.models.group import PROJECT_MEMBER
from dsp_permissions_scripts.models.group import SYSTEM_ADMIN
from dsp_permissions_scripts.models.group import UNKNOWN_USER
from dsp_permissions_scripts.models.group import Group
from dsp_permissions_scripts.models.group_utils import sort_groups


def test_sort_groups() -> None:
groups_original = [
group.Group(prefixed_iri="knora-admin:C_CustomGroup"),
group.UNKNOWN_USER,
group.PROJECT_ADMIN,
group.PROJECT_MEMBER,
group.CREATOR,
group.Group(prefixed_iri="knora-admin:A_CustomGroup"),
group.Group(prefixed_iri="knora-admin:B_CustomGroup"),
group.KNOWN_USER,
group.SYSTEM_ADMIN,
Group(prefixed_iri="knora-admin:C_CustomGroup"),
UNKNOWN_USER,
PROJECT_ADMIN,
PROJECT_MEMBER,
CREATOR,
Group(prefixed_iri="knora-admin:A_CustomGroup"),
Group(prefixed_iri="knora-admin:B_CustomGroup"),
KNOWN_USER,
SYSTEM_ADMIN,
]
groups_expected = [
group.SYSTEM_ADMIN,
group.CREATOR,
group.PROJECT_ADMIN,
group.PROJECT_MEMBER,
group.KNOWN_USER,
group.UNKNOWN_USER,
group.Group(prefixed_iri="knora-admin:A_CustomGroup"),
group.Group(prefixed_iri="knora-admin:B_CustomGroup"),
group.Group(prefixed_iri="knora-admin:C_CustomGroup"),
SYSTEM_ADMIN,
CREATOR,
PROJECT_ADMIN,
PROJECT_MEMBER,
KNOWN_USER,
UNKNOWN_USER,
Group(prefixed_iri="knora-admin:A_CustomGroup"),
Group(prefixed_iri="knora-admin:B_CustomGroup"),
Group(prefixed_iri="knora-admin:C_CustomGroup"),
]
groups_returned = sort_groups(groups_original)
assert groups_returned == groups_expected
Expand Down
25 changes: 15 additions & 10 deletions tests/test_scope_serialization.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import pytest
from pytest_unordered import unordered

from dsp_permissions_scripts.models import group
from dsp_permissions_scripts.models.group import CREATOR
from dsp_permissions_scripts.models.group import KNOWN_USER
from dsp_permissions_scripts.models.group import PROJECT_ADMIN
from dsp_permissions_scripts.models.group import PROJECT_MEMBER
from dsp_permissions_scripts.models.group import SYSTEM_ADMIN
from dsp_permissions_scripts.models.group import UNKNOWN_USER
from dsp_permissions_scripts.models.scope import PermissionScope
from dsp_permissions_scripts.utils.helpers import KNORA_ADMIN_ONTO_NAMESPACE
from dsp_permissions_scripts.utils.scope_serialization import create_admin_route_object_from_scope
Expand Down Expand Up @@ -48,21 +53,21 @@ class TestScopeSerialization:
)
scopes = (
PermissionScope.create(
CR=[group.SYSTEM_ADMIN],
CR=[SYSTEM_ADMIN],
),
PermissionScope.create(
D=[group.PROJECT_ADMIN],
RV=[group.PROJECT_MEMBER],
D=[PROJECT_ADMIN],
RV=[PROJECT_MEMBER],
),
PermissionScope.create(
M=[group.PROJECT_ADMIN],
V=[group.CREATOR, group.KNOWN_USER],
RV=[group.UNKNOWN_USER],
M=[PROJECT_ADMIN],
V=[CREATOR, KNOWN_USER],
RV=[UNKNOWN_USER],
),
PermissionScope.create(
CR=[group.SYSTEM_ADMIN, group.PROJECT_ADMIN],
D=[group.CREATOR],
RV=[group.UNKNOWN_USER],
CR=[SYSTEM_ADMIN, PROJECT_ADMIN],
D=[CREATOR],
RV=[UNKNOWN_USER],
),
)

Expand Down

0 comments on commit 37713be

Please sign in to comment.