Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions api/dao/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,18 @@ def get_container(self, _id, projection=None, get_children=False):
cont[CHILD_MAP[self.cont_name]] = children
return cont

def get_children(self, _id, projection=None):
def get_children(self, _id, projection=None, uid=None):
try:
child_name = CHILD_MAP[self.cont_name]
except KeyError:
raise APINotFoundException('Children cannot be listed from the {0} level'.format(self.cont_name))
query = {self.cont_name[:-1]: bson.ObjectId(_id)}
if not self.use_object_id:
query = {containerutil.singularize(self.cont_name): _id}
else:
query = {containerutil.singularize(self.cont_name): bson.ObjectId(_id)}

if uid:
query['permissions'] = {'$elemMatch': {'_id': uid}}
if not projection:
projection = {'info': 0, 'files.info': 0, 'subject': 0, 'tags': 0}
return ContainerStorage.factory(child_name).get_all_el(query, None, projection)
Expand Down
11 changes: 11 additions & 0 deletions api/handlers/grouphandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ def delete(self, _id):
self.abort(404, 'Group {} not removed'.format(_id))
return result

def handle_projects(self, result):
"""
If parameter join=projects, return project id, label, permissions, and description
"""
result['projects'] = self.storage.get_children(result.get('_id'), projection={'permissions': 1, 'label': 1, 'description': 1, 'group': 1}, uid=self.uid)
self._filter_permissions(result['projects'], self.uid)
return result

def get_all(self, uid=None):
projection = {'label': 1, 'created': 1, 'modified': 1, 'permissions': 1, 'tags': 1}
permchecker = groupauth.list_permission_checker(self, uid)
Expand All @@ -44,6 +52,9 @@ def get_all(self, uid=None):
self._filter_permissions(results, self.uid)
if self.is_true('join_avatars'):
results = ContainerHandler.join_user_info(results)
if 'projects' in self.request.params.getall('join'):
for result in results:
result = self.handle_projects(result)
return results

@validators.verify_payload_exists
Expand Down
6 changes: 6 additions & 0 deletions test/integration_tests/python/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,9 @@ def test_groups(as_user, as_admin, data_builder):
r = as_admin.get('/groups/' + group)
assert r.ok
assert r.json()['label'] == group_label

# Test join=projects
project = data_builder.create_project()
r = as_admin.get('/groups', params={'join': 'projects'})
assert r.ok
assert r.json()[1].get('projects')[0].get('_id') == project