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
13 changes: 12 additions & 1 deletion api/dao/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def get_children(self, _id, projection=None):
raise APINotFoundException('Children cannot be listed from the {0} level'.format(self.cont_name))
query = {self.cont_name[:-1]: bson.ObjectId(_id)}
if not projection:
projection = {'metadata': 0, 'files.metadata': 0, 'subject': 0}
projection = {'info': 0, 'files.info': 0, 'subject': 0, 'tags': 0}
return ContainerStorage.factory(child_name).get_all_el(query, None, projection)

def _from_mongo(self, cont):
Expand Down Expand Up @@ -184,9 +184,20 @@ def get_all_el(self, query, user, projection, fill_defaults=False):
query['permissions'] = {'$elemMatch': user}
log.debug(query)
log.debug(projection)

# if projection includes files.info, add new key `info_exists`
if projection and 'files.info' in projection:
replace_info_with_bool = True
projection.pop('files.info')
else:
replace_info_with_bool = False

results = list(self.dbc.find(query, projection))
for cont in results:
cont = self._from_mongo(cont)
if fill_defaults:
cont = self._fill_default_values(cont)
if replace_info_with_bool:
for f in cont.get('files', []):
f['info_exists'] = bool(f.pop('info', False))
return results
2 changes: 1 addition & 1 deletion api/handlers/containerhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class ContainerHandler(base.RequestHandler):
'parent_storage': containerstorage.SessionStorage(),
'storage_schema_file': 'acquisition.json',
'payload_schema_file': 'acquisition.json',
'list_projection': {'info': 0, 'collections': 0, 'files.info': 0, 'tag': 0}
'list_projection': {'info': 0, 'collections': 0, 'files.info': 0, 'tags': 0}
}
}

Expand Down
3 changes: 2 additions & 1 deletion raml/schemas/definitions/file.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
"hash":{"$ref":"#/definitions/hash"},
"created":{"$ref":"../definitions/created-modified.json#/definitions/created"},
"modified":{"$ref":"../definitions/created-modified.json#/definitions/modified"},
"size":{"$ref":"#/definitions/size"}
"size":{"$ref":"#/definitions/size"},
"info_exists": {"type": "boolean"}
},
"additionalProperties": false,
"required":["modified", "size"]
Expand Down