[ckan-changes] [ckan/ckan] 5c04c0: Store current user in SQLAlchemy session so activi...

Adrià Mercader noreply at github.com
Fri Oct 18 11:08:35 UTC 2019


  Branch: refs/heads/remove-vdm-4
  Home:   https://github.com/ckan/ckan
  Commit: 5c04c0fd55761dfc2f4fad20f52bcea1004ac2a6
      https://github.com/ckan/ckan/commit/5c04c0fd55761dfc2f4fad20f52bcea1004ac2a6
  Author: amercader <amercadero at gmail.com>
  Date:   2019-10-18 (Fri, 18 Oct 2019)

  Changed paths:
    M ckan/lib/activity_streams_session_extension.py
    M ckan/logic/__init__.py

  Log Message:
  -----------
  Store current user in SQLAlchemy session so activity hook can get it

Up until now, the activity stream session extension used the revision
property of the session to get the user performing the action. With the
revisions gone we need to find an alternative. The
`session.revision.user` property was set after a revision was explicitly
created in an action, and its `author`  property set (by way of [1]):

    rev = model.repo.new_revision()
    rev.author = user

So it makes sense to attached the user performing an action when the
actions happen. But rather than have to call it explicitly on each
action that has activities as above, this change adds a unique function
in ckan.logic.get_action that uses the value in the `context` object.
These can be provided by users but most of the time they are
prepolutated with the following defaults: model, model.Session and
c.user.

The main drawback of this is that if extensions import and call core
action functions directly activites will get registered as a Non logged
in user. This is discouraged but it was quite common before chained
actions were introduced (and is still used now). To support this
situation we should add the call to set the user in the session in all
actions that have activities, like it was done before with the
revisions.

[1] https://github.com/ckan/ckan/blob/42596a014a713f9787d4ee9167f4c51afaaefaa6/ckan/model/__init__.py#L436




More information about the ckan-changes mailing list