Skip to content

Commit

Permalink
start of first primitive implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jnussbaum committed Jul 17, 2024
1 parent d995c8a commit fb2aded
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion dsp_permissions_scripts/ap/ap_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

def create_ap_from_admin_route_object(permission: dict[str, Any]) -> Ap:
"""Deserializes a AP from JSON as returned by /admin/permissions/ap/{project_iri}"""
relative_group_iri = permission["forGroup"].replace("http://www.knora.org/ontology/knora-admin#", "knora-admin:")
ap = Ap(
forGroup=Group(val=permission["forGroup"]),
forGroup=Group(val=relative_group_iri),
forProject=permission["forProject"],
hasPermissions=frozenset(ApValue(p["name"]) for p in permission["hasPermissions"]),
iri=permission["iri"],
Expand Down
8 changes: 7 additions & 1 deletion dsp_permissions_scripts/doap/doap_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,16 @@ def _get_all_doaps_of_project(project_iri: str, dsp_client: DspClient) -> list[D
def create_doap_from_admin_route_response(permission: dict[str, Any]) -> Doap:
"""Deserializes a DOAP from JSON as returned by /admin/permissions/doap/{project_iri}"""
scope = create_scope_from_admin_route_object(permission["hasPermissions"])
if permission.get("forGroup"):
relative_group_iri = permission["forGroup"].replace(
"http://www.knora.org/ontology/knora-admin#", "knora-admin:"
)
else:
relative_group_iri = None
doap = Doap(
target=DoapTarget(
project=permission["forProject"],
group=Group(val=permission["forGroup"]) if permission.get("forGroup") else None,
group=Group(val=relative_group_iri) if relative_group_iri else None,
resource_class=permission.get("forResourceClass"),
property=permission.get("forProperty"),
),
Expand Down
5 changes: 4 additions & 1 deletion dsp_permissions_scripts/doap/doap_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@

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)}
payload = {
"hasPermissions": create_admin_route_object_from_scope(scope),
"context": {"knora-admin": "http://www.knora.org/ontology/knora-admin"},
}
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/utils/scope_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def create_scope_from_admin_route_object(admin_route_object: list[dict[str, Any]
kwargs: dict[str, list[str]] = {}
for obj in admin_route_object:
attr_name: str = obj["name"]
group: str = obj["additionalInformation"]
group: str = obj["additionalInformation"].replace("http://www.knora.org/ontology/knora-admin#", "knora-admin:")
if attr_name in kwargs:
kwargs[attr_name].append(group)
else:
Expand Down

0 comments on commit fb2aded

Please sign in to comment.