Repository: OCHA-DAP/hdx-ckan

Issue:
Last updated by user for OCHA Colombia is a user who is not a member of the organiation
The user who is stated as having made the last edit is not a member of the organisation.

![image](https://cloud.githubusercontent.com/assets/6885303/4638566/66542d78-53fc-11e4-8aa7-b414b567024a.png)



Discussion:
@takavarasha Do we know if this person was able to make an update?  There is nothing mentioning her in the activity stream.  

Note that this example of the issue is on Production.

User did not make an update.

@takavarasha @cjhendrix 
I took the database, I checked it, I also checked some code and made small refactoring but no impact. I think all is good on our side, but indeed I see it was very strange. Right now there were some updates and I can not reproduce the bug.
If you can see it again on testing or prod please let me know ASAP and I will try to get that db snapshot to investigate.

I'm still seeing the problem on Prod right now.

@cjhendrix I tested with current code on local with prod db from 20.10.2014 and it is ok. Also, on stag I don't see this problem. I am 99% this is done. I will double check again

Lets check this after redeploy on PROD and STAG


Resolving patch:
diff --git a/ckanext-hdx_theme/ckanext/hdx_theme/helpers/helpers.py b/ckanext-hdx_theme/ckanext/hdx_theme/helpers/helpers.py
--- a/ckanext-hdx_theme/ckanext/hdx_theme/helpers/helpers.py
+++ b/ckanext-hdx_theme/ckanext/hdx_theme/helpers/helpers.py
@@ -56,22 +56,26 @@ def get_facet_items_dict(facet, limit=1000, exclude_active=False):
         return (facets, no_items)
 
 
-# def get_last_modifier_user(rev_id, get_timestamp=False):
-def get_last_modifier_user(group_id, get_timestamp=False):
-    rev_id = get_last_revision_group(group_id)
-    act_list = model.Session.query(model.Activity).filter(
-        model.Activity.revision_id == rev_id).all()
-    if act_list and len(act_list) > 0:
-        act = act_list[0]
-        usr_id = act.user_id
+def get_last_modifier_user(g_id=None, p_id=None, get_timestamp=False):
+    if g_id is not None:
+        activity_objects = model.activity.group_activity_list(
+            g_id, limit=1, offset=0)
+    if p_id is not None:
+        activity_objects = model.activity.package_activity_list(
+            p_id, limit=1, offset=0)
+    if activity_objects is not None:
+        user = activity_objects[0].user_id
+        t_stamp = activity_objects[0].timestamp
         if get_timestamp:
-            return (model.User.get(usr_id), act.timestamp.isoformat())
-        return model.User.get(usr_id)
+            return (model.User.get(user), t_stamp.isoformat())
+        return model.User.get(user)
+
     # in case there is no update date it will be displayed the current date
-    usr_list = model.Session.query(model.User).filter(
-        model.User.name == 'hdx').all()
-    usr = usr_list[0]
-    return (usr.id, datetime.datetime.now().isoformat())
+    user = model.Session.query(model.User).filter(
+        model.User.name == 'hdx').first()
+    if get_timestamp:
+        return (model.User.get(user), datetime.datetime.now().isoformat())
+    return model.User.get(user)
 
 
 def get_filtered_params_list(params):


Test patch: