Skip to content

Commit

Permalink
Fix handling of 'deleted package' activity streams
Browse files Browse the repository at this point in the history
They now show up as 'deleted package' activities instead of as 'changed
package'. The implementation is a bit of a hack.
  • Loading branch information
Sean Hammond committed Jan 19, 2012
1 parent 48798be commit 6a47014
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 8 deletions.
5 changes: 5 additions & 0 deletions ckan/logic/action/get.py
Expand Up @@ -915,6 +915,10 @@ def render_new_package_activity(context, activity):
return render('activity_streams/new_package.html',
extra_vars = {'activity': activity})

def render_deleted_package_activity(context, activity):
return render('activity_streams/deleted_package.html',
extra_vars = {'activity': activity})

def render_new_resource_activity(context, activity, detail):
return render('activity_streams/new_resource.html',
extra_vars = {'activity': activity, 'detail': detail})
Expand Down Expand Up @@ -977,6 +981,7 @@ def render_changed_group_activity(context, activity):
activity_renderers = {
'new package' : render_new_package_activity,
'changed package' : render_changed_package_activity,
'deleted package' : render_deleted_package_activity,
'new user' : render_new_user_activity,
'changed user' : render_changed_user_activity,
'new group' : render_new_group_activity,
Expand Down
26 changes: 25 additions & 1 deletion ckan/model/package.py
Expand Up @@ -544,8 +544,24 @@ def activity_stream_item(self, activity_type, revision, user_id):
import ckan.model
import ckan.lib.dictization
import ckan.logic
assert activity_type in ("new", "changed", "deleted"), (
assert activity_type in ("new", "changed"), (
str(activity_type))

# Handle 'deleted' objects.
# When the user marks a package as deleted this comes through here as
# a 'changed' package activity. We detect this and change it to a
# 'deleted' activity.
if activity_type == 'changed' and self.state == u'deleted':
if ckan.model.Session.query(ckan.model.Activity).filter_by(
object_id=self.id, activity_type='deleted').all():
# A 'deleted' activity for this object has already been emitted
# FIXME: What if the object was deleted and then activated
# again?
return None
else:
# Emit a 'deleted' activity for this object.
activity_type = 'deleted'

try:
d = {'package': ckan.lib.dictization.table_dictize(self,
context={'model': ckan.model})}
Expand All @@ -561,6 +577,14 @@ def activity_stream_item(self, activity_type, revision, user_id):
def activity_stream_detail(self, activity_id, activity_type):
import ckan.model
import ckan.lib.dictization

# Handle 'deleted' objects.
# When the user marks a package as deleted this comes through here as
# a 'changed' package activity. We detect this and change it to a
# 'deleted' activity.
if activity_type == 'changed' and self.state == u'deleted':
activity_type = 'deleted'

package_dict = ckan.lib.dictization.table_dictize(self,
context={'model':ckan.model})
return ActivityDetail(activity_id, self.id, u"Package", activity_type,
Expand Down
21 changes: 21 additions & 0 deletions ckan/templates/activity_streams/deleted_package.html
@@ -0,0 +1,21 @@
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:i18n="http://genshi.edgewall.org/i18n"
xmlns:py="http://genshi.edgewall.org/"
xmlns:xi="http://www.w3.org/2001/XInclude"
py:strip=""
>
<xi:include href="../_util.html" />
<div>
<div style="font-weight:bold;">
${h.linked_user(activity.user_id)}
<span style="background:yellow;">deleted</span>
the dataset
${activity.data.package.name} - ${activity.data.package.title}
${h.render_datetime(activity.timestamp, '%B %d %Y')}
</div>
<div style="color:#999;">
${h.markdown_extract(activity.data.package.notes)}
</div>
</div>
</html>
10 changes: 3 additions & 7 deletions ckan/tests/models/test_activity.py
Expand Up @@ -573,7 +573,7 @@ def _delete_package(self, package):
len(user_new_activities))
activity = user_new_activities[0]

# The same new activity should appear in the package's activity stream.
# The same new activity should appear in the package's stream.
pkg_new_activities = (find_new_activities(
before['package activity stream'],
after['package activity stream']))
Expand All @@ -584,9 +584,7 @@ def _delete_package(self, package):
str(activity['object_id']))
assert activity['user_id'] == self.normal_user.id, (
str(activity['user_id']))
# "Deleted" packages actually show up as changed (the package's
# status changes to "deleted" but the package is not expunged).
assert activity['activity_type'] == 'changed package', (
assert activity['activity_type'] == 'deleted package', (
str(activity['activity_type']))
if not activity.has_key('id'):
assert False, "activity object has no id value"
Expand All @@ -606,9 +604,7 @@ def _delete_package(self, package):
assert detail['object_id'] == package.id, str(detail['object_id'])
assert detail['object_type'] == "Package", (
str(detail['object_type']))
# "Deleted" packages actually show up as changed (the package's
# status changes to "deleted" but the package is not expunged).
assert detail['activity_type'] == "changed", (
assert detail['activity_type'] == "deleted", (
str(detail['activity_type']))

def test_delete_package(self):
Expand Down

0 comments on commit 6a47014

Please sign in to comment.