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

Added unstaging operation.

parent b4ff6171
......@@ -63,6 +63,7 @@ def login_really_required(func):
abort(401, message='Anonymous access is forbidden, authorization required')
return func(*args, **kwargs)
wrapper.__name__ = func.__name__
return wrapper
......@@ -300,6 +301,53 @@ class UploadRes(Resource):
return result, 200
def post(self, upload_id):
Move an upload out of the staging area. This changes the visibility of the upload.
Clients can specify, if the calcs should be restricted.
.. :quickref: upload; Move an upload out of the staging area.
**Example request**:
.. sourcecode:: http
POST /nomadxt/api/uploads HTTP/1.1
Accept: application/json
Content-Type: application/json
operation: 'unstage'
:param string upload_id: the upload id
:resheader Content-Type: application/json
:status 200: upload unstaged successfully
:status 404: upload could not be found
:status 400: if the operation is not supported
:returns: the upload record
upload = Upload.get(upload_id)
except KeyError:
abort(404, message='Upload with id %s does not exist.' % upload_id)
if upload.user_id !=
abort(404, message='Upload with id %s does not exist.' % upload_id)
json_data = request.get_json()
if json_data is None:
json_data = {}
operation = json_data.get('operation')
if operation == 'unstage':
return upload.json_dict, 200
abort(400, message='Unsuported operation %s.' % operation)
def delete(self, upload_id):
......@@ -234,7 +234,7 @@ class Upload(Proc):
def user_uploads(cls, user: User) -> List['Upload']:
""" Returns all uploads for the given user. Currently returns all uploads. """
return cls.objects()
return cls.objects(, in_staging=True)
def get_logger(self, **kwargs):
logger = super().get_logger()
......@@ -263,7 +263,7 @@ class Upload(Proc):
# delete repo entries'match', upload_id=self.upload_id).delete()
# delete calc processings
......@@ -304,6 +304,11 @@ class Upload(Proc):
return False
def unstage(self):
self.in_staging = False
RepoCalc.update_upload(upload_id=self.upload_id, staging=False)
def json_dict(self) -> dict:
""" A json serializable dictionary representation. """
......@@ -148,6 +148,17 @@ class RepoCalc(ElasticDocument):
return calc
def delete_upload(upload_id):
""" Deletes all repo entries of the given upload. """'match', upload_id=upload_id).delete()
def update_upload(cls, upload_id, **kwargs):
""" Update all entries of given upload with keyword args. """
for calc in'match', upload_id=upload_id):
def es_search(body):
""" Perform an elasticsearch and not elasticsearch_dsl search on the Calc index. """
......@@ -216,7 +216,16 @@ def test_processing(client, file, worker, mocksearch, test_user_auth):
upload = assert_upload(
assert len(upload['calcs']['results']) == 1
rv =
'/uploads/%s' % upload['upload_id'],
assert rv.status_code == 200
rv = client.get('/uploads', headers=test_user_auth)
assert rv.status_code == 200
assert_uploads(, count=0)
def test_repo_calc(client, example_elastic_calc):
......@@ -110,3 +110,13 @@ def test_delete_elastic_calc(example_elastic_calc: RepoCalc, caplog):
assert False
def test_staging_elastic_calc(example_elastic_calc: RepoCalc):
assert RepoCalc.get(id='test_upload_hash/test_calc_hash').staging
def test_unstage_elastic_calc(example_elastic_calc: RepoCalc):
RepoCalc.update_upload(upload_id='test_upload_id', staging=False)
assert not RepoCalc.get(id='test_upload_hash/test_calc_hash').staging
Supports Markdown
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