Skip to content

Commit

Permalink
edit
Browse files Browse the repository at this point in the history
  • Loading branch information
jnussbaum committed Oct 23, 2024
1 parent 577f376 commit 4931300
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion dsp_permissions_scripts/ap/ap_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from dsp_permissions_scripts.ap.ap_model import ApValue
from dsp_permissions_scripts.models.errors import ApiError
from dsp_permissions_scripts.models.group import Group
from dsp_permissions_scripts.models.group_utils import get_full_iri_from_prefixed_iri
from dsp_permissions_scripts.utils.dsp_client import DspClient
from dsp_permissions_scripts.utils.get_logger import get_logger
from dsp_permissions_scripts.utils.project import get_project_iri_and_onto_iris_by_shortcode
Expand Down Expand Up @@ -49,7 +50,7 @@ def create_new_ap_on_server(
) -> Ap | None:
proj_iri, _ = get_project_iri_and_onto_iris_by_shortcode(shortcode, dsp_client)
payload = {
"forGroup": forGroup.full_iri(),
"forGroup": get_full_iri_from_prefixed_iri(forGroup.prefixed_iri),
"forProject": proj_iri,
"hasPermissions": [
{"additionalInformation": None, "name": ap_val.value, "permissionCode": None} for ap_val in hasPermissions
Expand Down
6 changes: 5 additions & 1 deletion dsp_permissions_scripts/doap/doap_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from dsp_permissions_scripts.doap.doap_model import NewEntityDoapTarget
from dsp_permissions_scripts.doap.doap_model import NewGroupDoapTarget
from dsp_permissions_scripts.models.errors import ApiError
from dsp_permissions_scripts.models.group_utils import get_full_iri_from_prefixed_iri
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
Expand Down Expand Up @@ -47,8 +48,11 @@ def create_new_doap_on_server(
dsp_client: DspClient,
) -> Doap | None:
proj_iri, _ = get_project_iri_and_onto_iris_by_shortcode(shortcode, dsp_client)
forGroup = None
if isinstance(target, NewGroupDoapTarget):
forGroup = get_full_iri_from_prefixed_iri(target.group.prefixed_iri)
payload = {
"forGroup": target.group.full_iri() if isinstance(target, NewGroupDoapTarget) else None,
"forGroup": forGroup,
"forProject": proj_iri,
"forProperty": target.property if isinstance(target, NewEntityDoapTarget) else None,
"forResourceClass": target.resource_class if isinstance(target, NewEntityDoapTarget) else None,
Expand Down
3 changes: 2 additions & 1 deletion dsp_permissions_scripts/utils/scope_serialization.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Any

from dsp_permissions_scripts.models.group_utils import get_full_iri_from_prefixed_iri
from dsp_permissions_scripts.models.group_utils import sort_groups
from dsp_permissions_scripts.models.scope import PermissionScope

Expand Down Expand Up @@ -48,7 +49,7 @@ def create_admin_route_object_from_scope(perm_scope: PermissionScope) -> list[di
for group in groups:
scope_elements.append(
{
"additionalInformation": group.full_iri(),
"additionalInformation": get_full_iri_from_prefixed_iri(group.prefixed_iri),
"name": perm_letter,
"permissionCode": None,
}
Expand Down
4 changes: 1 addition & 3 deletions tests/test_scope_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@

class TestScopeSerialization:
perm_strings = (
"CR knora-admin:SystemAdmin|V knora-admin:CustomGroup",
"CR knora-admin:SystemAdmin",
"D knora-admin:ProjectAdmin|RV knora-admin:ProjectMember",
"M knora-admin:ProjectAdmin|V knora-admin:Creator,knora-admin:KnownUser|RV knora-admin:UnknownUser",
"CR knora-admin:SystemAdmin,knora-admin:ProjectAdmin|D knora-admin:Creator|RV knora-admin:UnknownUser",
)
admin_route_objects = (
[
{"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": f"{KNORA_ADMIN_ONTO_NAMESPACE}ProjectAdmin", "permissionCode": None},
Expand Down Expand Up @@ -50,7 +49,6 @@ class TestScopeSerialization:
scopes = (
PermissionScope.create(
CR=[group.SYSTEM_ADMIN],
V=[group.Group(prefixed_iri="knora-admin:CustomGroup")],
),
PermissionScope.create(
D=[group.PROJECT_ADMIN],
Expand Down

0 comments on commit 4931300

Please sign in to comment.