Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
jnussbaum committed Jul 18, 2024
1 parent 30420df commit 35a7549
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 22 deletions.
3 changes: 1 addition & 2 deletions dsp_permissions_scripts/ap/ap_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
20 changes: 0 additions & 20 deletions dsp_permissions_scripts/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 35a7549

Please sign in to comment.