Skip to content

Commit

Permalink
fix(xmlupload): permission for uri value serialise (DEV-3630) (#958)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nora-Olivia-Ammann authored May 14, 2024
1 parent 0289294 commit 79a11bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SerialiseValue(Protocol):
"""A value to be serialised."""

value: str
permissions: str
permissions: str | None
comment: str | None

def serialise(self) -> dict[str, Any]:
Expand All @@ -31,20 +31,21 @@ class SerialiseURI(SerialiseValue):
"""A URI to be serialised."""

value: str
permissions: str
permissions: str | None
comment: str | None

def serialise(self) -> dict[str, Any]:
"""Serialise the URI value."""

serialised = {
"@type": "knora-api:UriValue",
"knora-api:hasPermissions": self.permissions,
"knora-api:uriValueAsUri": {
"@type": "xsd:anyURI",
"@value": self.value,
},
}
if self.comment:
serialised["knora-api:valueHasComment"] = self.comment
if self.permissions:
serialised["knora-api:hasPermissions"] = self.permissions
return serialised
12 changes: 7 additions & 5 deletions src/dsp_tools/commands/xmlupload/resource_create_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,15 +365,17 @@ def _make_time_value(value: XMLValue) -> dict[str, Any]:
def _serialise_uri_prop(prop: XMLProperty, permissions_lookup: dict[str, Permissions]) -> dict[str, Any]:
uri_values: list[SerialiseValue] = []
for v in prop.values:
value_permission = cast(str, v.permissions)
if not (per := permissions_lookup.get(value_permission)):
raise PermissionNotExistsError(f"Could not find permissions for value: {v.permissions}")
per_str = str(per)
if v.permissions:
if not (per := permissions_lookup.get(v.permissions)):
raise PermissionNotExistsError(f"Could not find permissions for value: {v.permissions}")
permission = str(per)
else:
permission = None
uri = cast(str, v.value)
uri_values.append(
SerialiseURI(
value=uri,
permissions=per_str,
permissions=permission,
comment=v.comment,
)
)
Expand Down

0 comments on commit 79a11bb

Please sign in to comment.