Skip to content

Commit

Permalink
Merge branch 'main' into wip/always-retrieve-resource-oaps
Browse files Browse the repository at this point in the history
  • Loading branch information
jnussbaum authored Jul 26, 2024
2 parents d9d5e60 + 8015d59 commit 3d435bd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
6 changes: 1 addition & 5 deletions dsp_permissions_scripts/doap/doap_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@
from dsp_permissions_scripts.models.scope import PermissionScope
from dsp_permissions_scripts.utils.dsp_client import DspClient
from dsp_permissions_scripts.utils.get_logger import get_logger
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

logger = get_logger(__name__)


def _update_doap_scope_on_server(doap_iri: str, scope: PermissionScope, dsp_client: DspClient) -> Doap:
iri = quote_plus(doap_iri, safe="")
payload = {
"hasPermissions": create_admin_route_object_from_scope(scope),
"context": {"knora-admin": KNORA_ADMIN_ONTO_NAMESPACE},
}
payload = {"hasPermissions": create_admin_route_object_from_scope(scope)}
try:
response = dsp_client.put(f"/admin/permissions/{iri}/hasPermissions", data=payload)
except ApiError as err:
Expand Down
2 changes: 1 addition & 1 deletion dsp_permissions_scripts/oap/oap_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,4 @@ def apply_updated_oaps_on_server(
)
msg = f"ERROR: {len(failed_iris)} resources or values could not be updated. They were written to {filename}."
logger.error(msg)
logger.info(f"Updated OAPs of {len(oaps)} resources on {host}")
logger.info(f"Updated {res_oap_count} resource OAPs and {value_oap_count} value OAPs on {host}... *******")
7 changes: 5 additions & 2 deletions dsp_permissions_scripts/utils/scope_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ def create_scope_from_admin_route_object(admin_route_object: list[dict[str, Any]


def create_admin_route_object_from_scope(perm_scope: PermissionScope) -> list[dict[str, str | None]]:
"""Serializes a permission scope to an object that can be used for requests to /admin/permissions routes."""
"""
Serializes a permission scope to an object that can be used for requests to /admin/permissions routes.
Note: This route doesn't accept relative IRIs.
"""
scope_elements: list[dict[str, str | None]] = []
for perm_letter in perm_scope.model_fields:
groups = perm_scope.get(perm_letter)
for group in groups:
scope_elements.append(
{
"additionalInformation": group.val,
"additionalInformation": group.val.replace("knora-admin:", KNORA_ADMIN_ONTO_NAMESPACE),
"name": perm_letter,
"permissionCode": None,
}
Expand Down
33 changes: 21 additions & 12 deletions tests/test_scope_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from dsp_permissions_scripts.models import group
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
from dsp_permissions_scripts.utils.scope_serialization import create_scope_from_admin_route_object
from dsp_permissions_scripts.utils.scope_serialization import create_scope_from_string
Expand All @@ -18,24 +19,32 @@ class TestScopeSerialization:
)
admin_route_objects = (
[
{"name": "CR", "additionalInformation": "knora-admin:SystemAdmin", "permissionCode": None},
{"name": "V", "additionalInformation": "knora-admin:CustomGroup", "permissionCode": None},
{"name": "CR", "additionalInformation": f"{KNORA_ADMIN_ONTO_NAMESPACE}SystemAdmin", "permissionCode": None},
{"name": "V", "additionalInformation": f"{KNORA_ADMIN_ONTO_NAMESPACE}CustomGroup", "permissionCode": None},
],
[
{"name": "D", "additionalInformation": "knora-admin:ProjectAdmin", "permissionCode": None},
{"name": "RV", "additionalInformation": "knora-admin:ProjectMember", "permissionCode": None},
{"name": "D", "additionalInformation": f"{KNORA_ADMIN_ONTO_NAMESPACE}ProjectAdmin", "permissionCode": None},
{
"name": "RV",
"additionalInformation": f"{KNORA_ADMIN_ONTO_NAMESPACE}ProjectMember",
"permissionCode": None,
},
],
[
{"name": "M", "additionalInformation": "knora-admin:ProjectAdmin", "permissionCode": None},
{"name": "V", "additionalInformation": "knora-admin:Creator", "permissionCode": None},
{"name": "V", "additionalInformation": "knora-admin:KnownUser", "permissionCode": None},
{"name": "RV", "additionalInformation": "knora-admin:UnknownUser", "permissionCode": None},
{"name": "M", "additionalInformation": f"{KNORA_ADMIN_ONTO_NAMESPACE}ProjectAdmin", "permissionCode": None},
{"name": "V", "additionalInformation": f"{KNORA_ADMIN_ONTO_NAMESPACE}Creator", "permissionCode": None},
{"name": "V", "additionalInformation": f"{KNORA_ADMIN_ONTO_NAMESPACE}KnownUser", "permissionCode": None},
{"name": "RV", "additionalInformation": f"{KNORA_ADMIN_ONTO_NAMESPACE}UnknownUser", "permissionCode": None},
],
[
{"name": "CR", "additionalInformation": "knora-admin:SystemAdmin", "permissionCode": None},
{"name": "CR", "additionalInformation": "knora-admin:ProjectAdmin", "permissionCode": None},
{"name": "D", "additionalInformation": "knora-admin:Creator", "permissionCode": None},
{"name": "RV", "additionalInformation": "knora-admin:UnknownUser", "permissionCode": None},
{"name": "CR", "additionalInformation": f"{KNORA_ADMIN_ONTO_NAMESPACE}SystemAdmin", "permissionCode": None},
{
"name": "CR",
"additionalInformation": f"{KNORA_ADMIN_ONTO_NAMESPACE}ProjectAdmin",
"permissionCode": None,
},
{"name": "D", "additionalInformation": f"{KNORA_ADMIN_ONTO_NAMESPACE}Creator", "permissionCode": None},
{"name": "RV", "additionalInformation": f"{KNORA_ADMIN_ONTO_NAMESPACE}UnknownUser", "permissionCode": None},
],
)
scopes = (
Expand Down

0 comments on commit 3d435bd

Please sign in to comment.