Skip to content

Commit

Permalink
Merge branch 'master' into cli-user
Browse files Browse the repository at this point in the history
  • Loading branch information
tino097 committed May 7, 2019
2 parents 82bfed0 + 49c81e6 commit 287831d
Show file tree
Hide file tree
Showing 143 changed files with 3,185 additions and 2,303 deletions.
37 changes: 36 additions & 1 deletion CHANGELOG.rst
Expand Up @@ -10,6 +10,30 @@ Changelog
v.2.9.0 TBA
==================

* When upgrading from previous CKAN versions, the Activity Stream needs a
migrate_package_activity.py running for displaying the history of dataset
changes. This can be performed while CKAN is running or stopped (whereas the
standard `paster db upgrade` migrations need CKAN to be stopped). Ideally it
is run before CKAN is upgraded, but it can be run afterwards. If running
previous versions or this version of CKAN, download and run
migrate_package_activity.py like this:

cd /usr/lib/ckan/default/src/ckan/
wget https://raw.githubusercontent.com/ckan/ckan/3484_revision_ui_removal2/ckan/migration/migrate_package_activity.py
wget https://raw.githubusercontent.com/ckan/ckan/3484_revision_ui_removal2/ckan/migration/revision_legacy_code.py
python migrate_package_activity.py -c /etc/ckan/production.ini

Future versions of CKAN are likely to need a slightly different procedure.
Full info about this migration is found here:
https://github.com/ckan/ckan/wiki/Migrate-package-activity

* A full history of dataset changes is now displayed in the Activity Stream to
admins, and optionally to the public. By default this is enabled for new
installs, but disabled for sites which upgrade (just in case the history is
sensitive). When upgrading, open data CKANs are encouraged to make this
history open to the public, by setting this in production.ini:
``ckan.auth.public_activity_stream_detail = true`` (#3972)

Minor changes:

* For navl schemas, the 'default' validator no longer applies the default when
Expand All @@ -26,7 +50,18 @@ Bugfixes:
* Action function "datastore_search" would calculate the total, even if you
set include_total=False (#4448)

Deprecations:
Removals and deprecations:

* Revision and History UI is removed: `/revision/*` & `/dataset/{id}/history`
in favour of `/dataset/changes/` visible in the Activity Stream. (#3972)
* Logic functions removed:
``dashboard_activity_list_html`` ``organization_activity_list_html``
``user_activity_list_html`` ``package_activity_list_html``
``group_activity_list_html`` ``organization_activity_list_html``
``recently_changed_packages_activity_list_html``
``dashboard_activity_list_html`` ``activity_detail_list`` (#4627/#3972)
* ``model.ActivityDetail`` is no longer used and will be removed in the next
CKAN release. (#3972)
* ``c.action`` and ``c.controller`` variables should be avoided.
``ckan.plugins.toolkit.get_endpoint`` can be used instead. This function
returns tuple of two items(depending on request handler):
Expand Down
1 change: 1 addition & 0 deletions ckan/authz.py
Expand Up @@ -407,6 +407,7 @@ def get_user_id_for_username(user_name, allow_none=False):
'create_user_via_api': False,
'create_user_via_web': True,
'roles_that_cascade_to_sub_groups': 'admin',
'public_activity_stream_detail': False,
}


Expand Down
2 changes: 2 additions & 0 deletions ckan/config/deployment.ini_tmpl
Expand Up @@ -72,6 +72,8 @@ ckan.auth.user_delete_organizations = true
ckan.auth.create_user_via_api = false
ckan.auth.create_user_via_web = true
ckan.auth.roles_that_cascade_to_sub_groups = admin
ckan.auth.public_user_details = true
ckan.auth.public_activity_stream_detail = true


## Search Settings
Expand Down
7 changes: 0 additions & 7 deletions ckan/config/routing.py
Expand Up @@ -134,13 +134,6 @@ def make_map():
# users
map.redirect('/users/{url:.*}', '/user/{url}')

with SubMapper(map, controller='revision') as m:
m.connect('/revision', action='index')
m.connect('/revision/edit/{id}', action='edit')
m.connect('/revision/diff/{id}', action='diff')
m.connect('/revision/list', action='list')
m.connect('/revision/{id}', action='read')

with SubMapper(map, controller='util') as m:
m.connect('/i18n/strings_{lang}.js', action='i18n_js_strings')
m.connect('/util/redirect', action='redirect')
Expand Down
185 changes: 0 additions & 185 deletions ckan/controllers/revision.py

This file was deleted.

64 changes: 18 additions & 46 deletions ckan/lib/activity_streams_session_extension.py
Expand Up @@ -18,30 +18,22 @@ def activity_stream_item(obj, activity_type, revision, user_id):
return None


def activity_stream_detail(obj, activity_id, activity_type):
method = getattr(obj, "activity_stream_detail", None)
if callable(method):
return method(activity_id, activity_type)
else:
# Object did not have a suitable activity_stream_detail() method
return None


class DatasetActivitySessionExtension(SessionExtension):
"""Session extension that emits activity stream activities for packages
and related objects.
An SQLAlchemy SessionExtension that watches for new, changed or deleted
Packages or objects with related packages (Resources, PackageExtras..)
being committed to the SQLAlchemy session and creates Activity and
ActivityDetail objects for these activities.
being committed to the SQLAlchemy session and creates Activity objects for
these activities.
For most types of activity the Activity and ActivityDetail objects are
created in the relevant ckan/logic/action/ functions, but for Packages and
objects with related packages they are created by this class instead.
For most types of activity the Activity objects are created in the relevant
ckan/logic/action/ functions, but for Packages and objects with related
packages they are created by this class instead.
"""
def before_commit(self, session):
from ckan.model import Member # imported here to avoid dependency hell
if not asbool(config.get('ckan.activity_streams_enabled', 'true')):
return

Expand All @@ -67,12 +59,6 @@ def before_commit(self, session):
# objects.
activities = {}

# The second-level objects that we will append to the activity_detail
# table. Each row in the activity table has zero or more related rows
# in the activity_detail table. The keys here are activity IDs, and the
# values are lists of model.activity:ActivityDetail objects.
activity_details = {}

# Log new packages first to prevent them from getting incorrectly
# logged as changed packages.
# Looking for new packages...
Expand All @@ -89,10 +75,6 @@ def before_commit(self, session):

activities[obj.id] = activity

activity_detail = activity_stream_detail(obj, activity.id, "new")
if activity_detail is not None:
activity_details[activity.id] = [activity_detail]

# Now process other objects.
for activity_type in ('new', 'changed', 'deleted'):
objects = object_cache[activity_type]
Expand All @@ -114,6 +96,11 @@ def before_commit(self, session):
# skipping it
continue

if isinstance(obj, Member):
# When you add a package to a group/org, it should only be
# in the group's activity stream, not the related packages
continue

for package in related_packages:
if package is None:
continue
Expand All @@ -123,31 +110,16 @@ def before_commit(self, session):
continue

if package.id in activities:
activity = activities[package.id]
else:
activity = activity_stream_item(
package, "changed", revision, user_id)
if activity is None:
continue

activity_detail = activity_stream_detail(
obj, activity.id, activity_type)
if activity_detail is not None:
if not package.id in activities:
activities[package.id] = activity
if activity_details.has_key(activity.id):
activity_details[activity.id].append(
activity_detail)
else:
activity_details[activity.id] = [activity_detail]
continue

activity = activity_stream_item(
package, "changed", revision, user_id)
if activity is None:
continue
activities[package.id] = activity

for key, activity in activities.items():
# Emitting activity
session.add(activity)

for key, activity_detail_list in activity_details.items():
for activity_detail_obj in activity_detail_list:
# Emitting activity detail
session.add(activity_detail_obj)

session.flush()
1 change: 0 additions & 1 deletion ckan/lib/app_globals.py
Expand Up @@ -47,7 +47,6 @@
'ckan.template_footer_end': {},
'ckan.dumps_url': {},
'ckan.dumps_format': {},
'ofs.impl': {'name': 'ofs_impl'},
'ckan.homepage_style': {'default': '1'},

# split string
Expand Down

0 comments on commit 287831d

Please sign in to comment.