diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c1dcdf87e2ccfcce6123cb51553b069514c66e1c..9ecfce68b41bd6eb0252e3b0a251b3c4f567ab37 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -104,7 +104,7 @@ deploy: - helm dependency update ops/helm/nomad - helm upgrade --namespace nomad --install $RELEASE_NAME ops/helm/nomad -f ops/helm/nomad/ci-dev-values.yaml --set proxy.external.path=/dev/nomad/$RELEASE_NAME,image.tag=$CI_COMMIT_REF_NAME,roll=true --wait - docker pull $TEST_IMAGE - - docker run -t -e NOMAD_KEYCLOAK_REALM_NAME=fairdi_nomad_prod $TEST_IMAGE python -m nomad.cli client -n $CI_DEV_CLUSTER_PROXY/dev/nomad/$RELEASE_NAME/api -u admin -w $CI_NOMAD_ADMIN_PASSWORD integrationtests --skip-doi + - docker run -t -e NOMAD_KEYCLOAK_REALM_NAME=fairdi_nomad_prod $TEST_IMAGE python -m nomad.cli client -n $CI_DEV_CLUSTER_PROXY/dev/nomad/$RELEASE_NAME/api -u admin -w $CI_NOMAD_ADMIN_PASSWORD integrationtests except: - /^dev-.*$/ diff --git a/nomad/app/api/dataset.py b/nomad/app/api/dataset.py index a478d0c72fea226e57ec9ec69da11a7507d99abc..3f9bd159f29357049880b72b414695fc02ad8920 100644 --- a/nomad/app/api/dataset.py +++ b/nomad/app/api/dataset.py @@ -175,7 +175,10 @@ class DatasetResource(Resource): abort(404, 'Dataset with name %s does not exist for current user' % name) if result.doi is not None and len(result.doi) > 0: - abort(400, 'Dataset with name %s has a DOI and cannot be deleted' % name) + if g.user.is_admin: + DOI.objects(doi__in=result.doi).delete() + else: + abort(400, 'Dataset with name %s has a DOI and cannot be deleted' % name) # edit all affected entries edit( diff --git a/nomad/app/api/upload.py b/nomad/app/api/upload.py index 8d883c7fbb4d7f723f6f6bed84b9c5fe59af634b..a67bc382ca17ff3e2807e0cb46921dc7b039227b 100644 --- a/nomad/app/api/upload.py +++ b/nomad/app/api/upload.py @@ -419,7 +419,7 @@ class UploadResource(Resource): if upload.user_id != str(g.user.user_id) and not g.user.is_admin: abort(401, message='Upload with id %s does not belong to you.' % upload_id) - if upload.published: + if upload.published and not g.user.is_admin: abort(400, message='The upload is already published') if upload.tasks_running: diff --git a/nomad/cli/client/client.py b/nomad/cli/client/client.py index 9b9834513edbb504f405b9c7ece955093444ffdc..e3398020fe4f768cd16e1971668e30af1836d6c4 100644 --- a/nomad/cli/client/client.py +++ b/nomad/cli/client/client.py @@ -90,7 +90,8 @@ def handle_common_errors(func): @click.option('-w', '--password', default=nomad_config.client.password, help='the password used to login.') @click.option('--no-ssl-verify', help='disables SSL verificaton when talking to nomad.', is_flag=True) @click.option('--no-token', is_flag=True, help='replaces token with basic auth, e.g. to work with v0.6.x or older API versions') -def client(url: str, user: str, password: str, no_ssl_verify: bool, no_token: bool): +@click.pass_context +def client(ctx, url: str, user: str, password: str, no_ssl_verify: bool, no_token: bool): logger = utils.get_logger(__name__) logger.info('Used nomad is %s' % url) @@ -98,6 +99,8 @@ def client(url: str, user: str, password: str, no_ssl_verify: bool, no_token: bo nomad_config.client.url = url + ctx.obj.user = user + global _create_client def _create_client(*args, **kwargs): # pylint: disable=W0612 diff --git a/nomad/cli/client/integrationtests.py b/nomad/cli/client/integrationtests.py index c2c0075aaf7dbaf3e10fb8ba9a0c148593bf3133..30f5a3865810ecee84261ac3de625da125c3eacf 100644 --- a/nomad/cli/client/integrationtests.py +++ b/nomad/cli/client/integrationtests.py @@ -183,11 +183,11 @@ def integrationtests(ctx, skip_parsers, skip_publish, skip_doi, skip_mirror): assert doi has_doi = True - if not has_doi: + if not has_doi or ctx.obj.user == 'admin': print('deleting dataset') result = client.datasets.delete_dataset(name=dataset).response().result - if not skip_mirror: + if not skip_mirror and ctx.obj.user == 'admin': print('getting upload mirror') # get_upload_mirror gives 404 payload = dict(query=dict(upload_id=upload.upload_id)) @@ -196,7 +196,7 @@ def integrationtests(ctx, skip_parsers, skip_publish, skip_doi, skip_mirror): assert len(client.mirror.get_upload_mirror(upload_id=upload.upload_id).response().result.calcs) > 0 finally: - if not published: + if not published or ctx.obj.user == 'admin': print('delete the upload again') client.uploads.delete_upload(upload_id=upload.upload_id).response() while upload.process_running: diff --git a/nomad/processing/data.py b/nomad/processing/data.py index dd48fe96adf8101e5039d60c61e172cb67cb8724..50f185aa14207c064456042244f5b727cbb0a89f 100644 --- a/nomad/processing/data.py +++ b/nomad/processing/data.py @@ -625,14 +625,14 @@ class Upload(Proc): ''' logger = self.get_logger() - with utils.lnr(logger, 'staged upload delete failed'): + with utils.lnr(logger, 'upload delete failed'): with utils.timer( logger, 'upload deleted from index', step='index', upload_size=self.upload_files.size): search.delete_upload(self.upload_id) with utils.timer( - logger, 'staged upload deleted', step='files', + logger, 'upload deleted', step='files', upload_size=self.upload_files.size): self.upload_files.delete()