ckan
ckan copied to clipboard
ckanext-activity requires username even if ignore_auth is set
CKAN version
2.11
Describe the bug
If tests use the helpers.call_action convenience function to call actions that affect the activity stream without providing authentication, the tests will encounter errors, because ckanext-activity expects a user to exist in the context.
Steps to reproduce
Enable 'activity' in the CKAN config.
Run a unit test such as:
from ckan.tests import helpers
def test_call_action(self):
helpers.call_action('dataset_create', notes="Test")
Expected behavior
If ignore_auth is True, the activity stream should gracefully handle the lack of user information.
Additional details
If possible, please provide the full stack trace of the error raised, or add screenshots to help explain your problem.
src/ckan/ckan/logic/action/create.py:314:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/ckan/ckan/logic/__init__.py:596: in wrapped
signals.action_succeeded.send(
/usr/local/lib/python3.10/site-packages/blinker/base.py:279: in send
result = receiver(sender, **kwargs)
src/ckan/ckanext/activity/subscriptions.py:167: in package_changed
_create_package_activity(
src/ckan/ckanext/activity/subscriptions.py:82: in _create_package_activity
user_obj = _get_user_or_raise(context["user"])
Discussion from the dev call:
- we should update
activity_createAPI to accept no user for actions performed with ignore_auth=True - before activity was a plugin, actions would directly insert activity rows into the database with a special "no user"
user_idvalue in this case. Might be better to use an empty string in the new implementation.
Other suggestions:
- consider recording how an action was performed/authenticated (e.g. CLI, web, or which exact API token was used) in activities for auditing purposes