Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pave the way for custom group, 3rd round #150

Merged
merged 1 commit into from
Oct 23, 2024
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
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