Commit 8339d233 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Adding an embargo length to uploads in API. #252

parent b92a605f
......@@ -67,6 +67,7 @@ calc_metadata_model = api.inherit('CalcMetaData', metadata_model, {
})
upload_metadata_model = api.inherit('UploadMetaData', metadata_model, {
'embargo_length': fields.Integer(description='Length of the requested embargo in months.'),
'calculations': fields.List(fields.Nested(model=calc_metadata_model, skip_none=True), description='Specific per calculation data that will override the upload data.')
})
......
......@@ -25,7 +25,7 @@ calculations, and files
"""
from typing import cast, List, Any, ContextManager, Tuple, Generator, Dict, cast
from mongoengine import StringField, DateTimeField, DictField, BooleanField
from mongoengine import StringField, DateTimeField, DictField, BooleanField, IntField
import logging
from structlog import wrap_logger
from contextlib import contextmanager
......@@ -441,6 +441,7 @@ class Upload(Proc):
upload_id = StringField(primary_key=True)
upload_path = StringField(default=None)
temporary = BooleanField(default=False)
embargo_length = IntField(default=36)
name = StringField(default=None)
upload_time = DateTimeField()
......@@ -1034,6 +1035,8 @@ class Upload(Proc):
for the upload and for each calculation. This method will try to move same values
from the calculation to the upload to "compress" the data.
"""
self.embargo_length = min(metadata.get('embargo_length', 36), 36)
compressed = {
key: value for key, value in metadata.items() if key != 'calculations'}
calculations: List[Dict[str, Any]] = []
......
......@@ -259,6 +259,7 @@ class TestUploads:
upload_proc = Upload.objects(upload_id=upload_id).first()
assert upload_proc is not None
assert upload_proc.published is True
assert upload_proc.embargo_length == min(36, metadata.get('embargo_length', 36))
upload_with_metadata = upload_proc.to_upload_with_metadata()
assert_upload_files(upload_with_metadata, files.PublicUploadFiles, published=True)
......
......@@ -507,6 +507,7 @@ def example_user_metadata(other_test_user, test_user) -> dict:
return {
'comment': 'test comment',
'with_embargo': True,
'embargo_length': 12,
'references': ['http://external.ref/one', 'http://external.ref/two'],
'_uploader': other_test_user.user_id,
'coauthors': [test_user.user_id],
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment