Commit fca57924 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Allow the admin user to provide uploader metadata via nomad.json.

parent bf687c24
Pipeline #92638 canceled with stages
...@@ -586,6 +586,10 @@ class Calc(Proc): ...@@ -586,6 +586,10 @@ class Calc(Proc):
if definition is None and self.upload.from_oasis: if definition is None and self.upload.from_oasis:
definition = _oasis_metadata.get(key, None) definition = _oasis_metadata.get(key, None)
if key == 'uploader':
if datamodel.User.get(self.upload.user_id).is_admin:
definition = datamodel.EntryMetadata.uploader
if definition is None: if definition is None:
logger.warn('Users cannot set metadata', quantity=key) logger.warn('Users cannot set metadata', quantity=key)
continue continue
......
...@@ -297,6 +297,7 @@ def keycloak(monkeypatch): ...@@ -297,6 +297,7 @@ def keycloak(monkeypatch):
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
def proc_infra(worker, elastic, mongo, raw_files): def proc_infra(worker, elastic, mongo, raw_files):
''' Combines all fixtures necessary for processing (elastic, worker, files, mongo) ''' ''' Combines all fixtures necessary for processing (elastic, worker, files, mongo) '''
processing.Upload.metadata_file_cached.cache_clear()
return dict(elastic=elastic) return dict(elastic=elastic)
......
...@@ -606,3 +606,25 @@ def test_read_metadata_from_file(proc_infra, test_user, other_test_user): ...@@ -606,3 +606,25 @@ def test_read_metadata_from_file(proc_infra, test_user, other_test_user):
assert entry_coauthors[j].email == coauthors[i][j].email assert entry_coauthors[j].email == coauthors[i][j].email
assert entry_coauthors[j].first_name == coauthors[i][j].first_name assert entry_coauthors[j].first_name == coauthors[i][j].first_name
assert entry_coauthors[j].last_name == coauthors[i][j].last_name assert entry_coauthors[j].last_name == coauthors[i][j].last_name
@pytest.mark.parametrize('user,uploader', [
('admin_user', 'other_test_user'),
('test_user', 'test_user')
])
def test_read_adminmetadata_from_file(proc_infra, test_user, other_test_user, admin_user, user, uploader):
def user_from_name(user_name):
if user_name == 'test_user':
return test_user
if user_name == 'other_test_user':
return other_test_user
if user_name == 'admin_user':
return admin_user
user = user_from_name(user)
uploader = user_from_name(uploader)
upload = run_processing(
('test_upload', 'tests/data/proc/examples_with_adminmetadata.zip'), user)
calc = Calc.objects(upload_id=upload.upload_id).first()
assert calc.metadata['uploader'] == uploader.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