From 35a75495187b9aba307471042f95440a6266a03f Mon Sep 17 00:00:00 2001 From: Johannes Nussbaum Date: Thu, 18 Jul 2024 15:39:47 +0200 Subject: [PATCH] simplify --- dsp_permissions_scripts/ap/ap_get.py | 3 +-- dsp_permissions_scripts/utils/helpers.py | 20 -------------------- 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/dsp_permissions_scripts/ap/ap_get.py b/dsp_permissions_scripts/ap/ap_get.py index 7a88cef4..d8c604bb 100644 --- a/dsp_permissions_scripts/ap/ap_get.py +++ b/dsp_permissions_scripts/ap/ap_get.py @@ -15,9 +15,8 @@ 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(KNORA_ADMIN_ONTO_PREFIX, "knora-admin:") ap = Ap( - forGroup=Group(val=relative_group_iri), + forGroup=Group(val=permission["forGroup"].replace(KNORA_ADMIN_ONTO_PREFIX, "knora-admin:")), forProject=permission["forProject"], hasPermissions=frozenset(ApValue(p["name"]) for p in permission["hasPermissions"]), iri=permission["iri"], diff --git a/dsp_permissions_scripts/utils/helpers.py b/dsp_permissions_scripts/utils/helpers.py index 1a3e6378..aaa7901d 100644 --- a/dsp_permissions_scripts/utils/helpers.py +++ b/dsp_permissions_scripts/utils/helpers.py @@ -25,26 +25,6 @@ def dereference_prefix( return context[namespace_prefix] + localname -def shorten_iri_by_prefixing( - iri: str, - context: dict[str, str], -) -> str: - """ - Transforms a full IRI into its shortened form, using the namespace prefix from the provided context. - - Args: - iri: an full IRI, e.g. "http://www.knora.org/ontology/knora-admin#Creator" - context: The context to use take the namespace prefix from - - Returns: - The prefixed short form of the IRI, e.g. "knora-admin:Creator" - """ - for namespace_prefix, full_iri in context.items(): - if iri.startswith(full_iri): - return f"{namespace_prefix}:{iri[len(full_iri):]}" - raise ValueError(f"Could not find a prefix for IRI {iri}") - - def _get_sort_pos_of_custom_group(group: str) -> int: alphabet = list("abcdefghijklmnopqrstuvwxyz") relevant_letter = group.replace("knora-admin:", "")[0]