Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions ckanext/datapusher_plus/datastore_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,23 @@ def default(self, obj: object) -> object:
return json.JSONEncoder.default(self, obj)


def _site_user_context():
"""A context that names the site user.

From CKAN 2.11 the activity plugin requires context["user"] on every
action that records an activity (datastore_create and datastore_delete
both patch the resource; resource_delete records one too), and raises
ValidationError({"user_id": ["User not found"]}) otherwise.
"""
site_user = tk.get_action("get_site_user")({"ignore_auth": True}, {})
return {"ignore_auth": True, "user": site_user["name"]}


def delete_datastore_resource(resource_id: str) -> None:
"""Delete a resource from datastore."""
try:
tk.get_action("datastore_delete")(
{"ignore_auth": True}, {"resource_id": resource_id, "force": True}
_site_user_context(), {"resource_id": resource_id, "force": True}
)
except tk.ObjectNotFound:
raise utils.JobError("Deleting existing datastore failed.")
Expand All @@ -39,7 +51,7 @@ def delete_resource(resource_id: str) -> None:
"""Delete a resource from CKAN."""
try:
tk.get_action("resource_delete")(
{"ignore_auth": True}, {"id": resource_id, "force": True}
_site_user_context(), {"id": resource_id, "force": True}
)
except tk.ObjectNotFound:
raise utils.JobError("Deleting existing resource failed.")
Expand Down Expand Up @@ -160,7 +172,7 @@ def send_resource_to_datastore(
}
try:
resource_dict = tk.get_action("datastore_create")(
{"ignore_auth": True}, request
_site_user_context(), request
)
return resource_dict
except Exception as e:
Expand Down
Loading