From 4c1d560a6d5a18009deaba93ce734b8462db101c Mon Sep 17 00:00:00 2001 From: Megan Henning Date: Fri, 25 Aug 2017 12:29:39 -0500 Subject: [PATCH] Add avatars to notes when requested --- api/handlers/containerhandler.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/api/handlers/containerhandler.py b/api/handlers/containerhandler.py index 26e55e0f5..018d0571f 100644 --- a/api/handlers/containerhandler.py +++ b/api/handlers/containerhandler.py @@ -188,22 +188,26 @@ def handle_origin(self, result): @staticmethod def join_user_info(results): """ - Given a list of containers, adds avatar and name context to each member of the permissions list + Given a list of containers, adds avatar and name context to each member of the permissions and notes lists """ # Get list of all users, hash by uid + # TODO: This is not an efficient solution if there are hundreds of inactive users users_list = containerstorage.ContainerStorage('users', use_object_id=False).get_all_el({}, None, None) users = {user['_id']: user for user in users_list} for r in results: - permissions = r.get('permissions') or r.get('permissions', []) + permissions = r.get('permissions', []) + notes = r.get('notes', []) - for p in permissions: - user = users[p['_id']] + for p in permissions+notes: + uid = p['user'] if 'user' in p else p['_id'] + user = users[uid] p['avatar'] = user.get('avatar') p['firstname'] = user.get('firstname', '') p['lastname'] = user.get('lastname', '') + return results def _filter_permissions(self, result, uid):