Repository: ckan/ckan

Issue:
dashboard_activity_list_html 500s
It looks like commit e27b46b4 added an `id` arg to `dashboard_activity_list_html()` but didn't document it, now calling the function as described in the API docs 500s. Also looks like this id param is unnecessary as it should just use the id of the authorized user. Then the code that calls this function and passes an id in can be changed to not pass an id.

Also, are there any tests for this function? Apparently not or they would be failing. Need to add tests. It's just a simple wrapper function so should only need a couple of simple tests.



Discussion:
@seanh do you have time to do this?  I think john is snowed under at the mo, if not I could fix it

@tobes Yeah I'll take this

I looked into this pretty deeply today and I think the best course of action is to document that `id` is required. This is used to render the public activity streams for users and using the current user is not the right course of action there.


Resolving patch:
diff --git a/ckan/controllers/user.py b/ckan/controllers/user.py
--- a/ckan/controllers/user.py
+++ b/ckan/controllers/user.py
@@ -575,8 +575,8 @@ def dashboard(self, id=None, offset=0):
             context, {'id': c.userobj.id, 'q': q})
         c.dashboard_activity_stream_context = self._get_dashboard_context(
             filter_type, filter_id, q)
-        c.dashboard_activity_stream = h.dashboard_activity_stream(
-            id, filter_type, filter_id, offset)
+        c.dashboard_activity_stream = h.dashboard_activity_stream(filter_type,
+                filter_id, offset)
 
         # Mark the user's new activities as old whenever they view their
         # dashboard page.
diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py
--- a/ckan/lib/helpers.py
+++ b/ckan/lib/helpers.py
@@ -1289,7 +1289,7 @@ def user_in_org_or_group(group_id):
 
 def dashboard_activity_stream(user_id, filter_type=None, filter_id=None,
         offset=0):
-    '''Return the dashboard activity stream of the given user.
+    '''Return the dashboard activity stream of the current user.
 
     :param user_id: the id of the user
     :type user_id: string
@@ -1317,7 +1317,7 @@ def dashboard_activity_stream(user_id, filter_type=None, filter_id=None,
         return action_function(context, {'id': filter_id, 'offset': offset})
     else:
         return logic.get_action('dashboard_activity_list_html')(
-            context, {'id': user_id, 'offset': offset})
+            context, {'offset': offset})
 
 
 def recently_changed_packages_activity_stream():
diff --git a/ckan/logic/action/get.py b/ckan/logic/action/get.py
--- a/ckan/logic/action/get.py
+++ b/ckan/logic/action/get.py
@@ -830,7 +830,7 @@ def _group_or_org_show(context, data_dict, is_org=False):
         _check_access('organization_show',context, data_dict)
     else:
         _check_access('group_show',context, data_dict)
-    
+
 
     group_dict = model_dictize.group_dictize(group, context)
 
@@ -2645,11 +2645,11 @@ def dashboard_activity_list_html(context, data_dict):
 
     '''
     activity_stream = dashboard_activity_list(context, data_dict)
+    model = context['model']
     offset = int(data_dict.get('offset', 0))
     extra_vars = {
-        'controller': 'dashboard',
-        'action': 'activity',
-        'id': data_dict['id'],
+        'controller': 'user',
+        'action': 'dashboard',
         'offset': offset,
         }
     return activity_streams.activity_list_to_html(context, activity_stream,


Test patch:
diff --git a/ckan/tests/functional/api/test_dashboard.py b/ckan/tests/functional/api/test_dashboard.py
--- a/ckan/tests/functional/api/test_dashboard.py
+++ b/ckan/tests/functional/api/test_dashboard.py
@@ -331,3 +331,20 @@ def test_09_activities_that_should_not_show(self):
         after = self.dashboard_activity_list(self.new_user)
 
         assert before == after
+
+    def test_10_dashboard_activity_list_html_does_not_crash(self):
+
+        params = json.dumps({'name': 'irrelevant_dataset1'})
+        response = self.app.post('/api/action/package_create', params=params,
+            extra_environ={'Authorization': str(self.annafan['apikey'])})
+        assert response.json['success'] is True
+
+        params = json.dumps({'name': 'another_irrelevant_dataset'})
+        response = self.app.post('/api/action/package_create', params=params,
+            extra_environ={'Authorization': str(self.annafan['apikey'])})
+        assert response.json['success'] is True
+
+        res = self.app.get('/api/3/action/dashboard_activity_list_html',
+                extra_environ={'Authorization':
+                    str(self.annafan['apikey'])})
+        assert res.json['success'] is True