Skip to content

Commit

Permalink
rename to namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
jnussbaum committed Jul 18, 2024
1 parent 35a7549 commit bd7d060
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions dsp_permissions_scripts/ap/ap_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from dsp_permissions_scripts.models.group import Group
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_PREFIX
from dsp_permissions_scripts.utils.helpers import KNORA_ADMIN_ONTO_NAMESPACE
from dsp_permissions_scripts.utils.project import get_project_iri_and_onto_iris_by_shortcode

logger = get_logger(__name__)
Expand All @@ -16,7 +16,7 @@
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}"""
ap = Ap(
forGroup=Group(val=permission["forGroup"].replace(KNORA_ADMIN_ONTO_PREFIX, "knora-admin:")),
forGroup=Group(val=permission["forGroup"].replace(KNORA_ADMIN_ONTO_NAMESPACE, "knora-admin:")),
forProject=permission["forProject"],
hasPermissions=frozenset(ApValue(p["name"]) for p in permission["hasPermissions"]),
iri=permission["iri"],
Expand Down
4 changes: 2 additions & 2 deletions dsp_permissions_scripts/doap/doap_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from dsp_permissions_scripts.models.group import Group
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_PREFIX
from dsp_permissions_scripts.utils.helpers import KNORA_ADMIN_ONTO_NAMESPACE
from dsp_permissions_scripts.utils.project import get_project_iri_and_onto_iris_by_shortcode
from dsp_permissions_scripts.utils.scope_serialization import create_scope_from_admin_route_object

Expand Down Expand Up @@ -51,7 +51,7 @@ 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(KNORA_ADMIN_ONTO_PREFIX, "knora-admin:")
relative_group_iri = permission["forGroup"].replace(KNORA_ADMIN_ONTO_NAMESPACE, "knora-admin:")
else:
relative_group_iri = None
doap = Doap(
Expand Down
4 changes: 2 additions & 2 deletions dsp_permissions_scripts/doap/doap_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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_PREFIX
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__)
Expand All @@ -16,7 +16,7 @@ def _update_doap_scope_on_server(doap_iri: str, scope: PermissionScope, dsp_clie
iri = quote_plus(doap_iri, safe="")
payload = {
"hasPermissions": create_admin_route_object_from_scope(scope),
"context": {"knora-admin": KNORA_ADMIN_ONTO_PREFIX},
"context": {"knora-admin": KNORA_ADMIN_ONTO_NAMESPACE},
}
try:
response = dsp_client.put(f"/admin/permissions/{iri}/hasPermissions", data=payload)
Expand Down
6 changes: 3 additions & 3 deletions dsp_permissions_scripts/oap/oap_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from dsp_permissions_scripts.oap.oap_model import ValueOap
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_PREFIX
from dsp_permissions_scripts.utils.helpers import KNORA_ADMIN_ONTO_NAMESPACE
from dsp_permissions_scripts.utils.scope_serialization import create_string_from_scope

logger = get_logger(__name__)
Expand Down Expand Up @@ -87,7 +87,7 @@ def _update_batch(batch: tuple[ResourceOap | ValueOap, ...], dsp_client: DspClie
resource_iri=oap.resource_iri,
lmd=resource.get("knora-api:lastModificationDate"),
resource_type=resource["@type"],
context=resource["@context"] | {"knora-admin": KNORA_ADMIN_ONTO_PREFIX},
context=resource["@context"] | {"knora-admin": KNORA_ADMIN_ONTO_NAMESPACE},
scope=oap.scope,
dsp_client=dsp_client,
)
Expand All @@ -100,7 +100,7 @@ def _update_batch(batch: tuple[ResourceOap | ValueOap, ...], dsp_client: DspClie
resource_iri=oap.resource_iri,
value=oap,
resource_type=resource["@type"],
context=resource["@context"] | {"knora-admin": KNORA_ADMIN_ONTO_PREFIX},
context=resource["@context"] | {"knora-admin": KNORA_ADMIN_ONTO_NAMESPACE},
dsp_client=dsp_client,
)
except ApiError as err:
Expand Down
2 changes: 1 addition & 1 deletion dsp_permissions_scripts/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from dsp_permissions_scripts.models import group

PACKAGE_NAME = "dsp-permissions-scripts"
KNORA_ADMIN_ONTO_PREFIX = "http://www.knora.org/ontology/knora-admin#"
KNORA_ADMIN_ONTO_NAMESPACE = "http://www.knora.org/ontology/knora-admin#"


def dereference_prefix(
Expand Down
6 changes: 3 additions & 3 deletions dsp_permissions_scripts/utils/scope_serialization.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any

from dsp_permissions_scripts.models.scope import PermissionScope
from dsp_permissions_scripts.utils.helpers import KNORA_ADMIN_ONTO_PREFIX
from dsp_permissions_scripts.utils.helpers import KNORA_ADMIN_ONTO_NAMESPACE
from dsp_permissions_scripts.utils.helpers import sort_groups


Expand All @@ -22,7 +22,7 @@ def create_scope_from_string(permission_string: str) -> PermissionScope:
for scope in scopes:
perm_letter, groups_as_str = scope.split(" ")
groups = groups_as_str.split(",")
kwargs[perm_letter] = [g.replace(KNORA_ADMIN_ONTO_PREFIX, "knora-admin:") for g in groups]
kwargs[perm_letter] = [g.replace(KNORA_ADMIN_ONTO_NAMESPACE, "knora-admin:") for g in groups]
return PermissionScope.from_dict(kwargs)


Expand All @@ -31,7 +31,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"].replace(KNORA_ADMIN_ONTO_PREFIX, "knora-admin:")
group: str = obj["additionalInformation"].replace(KNORA_ADMIN_ONTO_NAMESPACE, "knora-admin:")
if attr_name in kwargs:
kwargs[attr_name].append(group)
else:
Expand Down

0 comments on commit bd7d060

Please sign in to comment.