From 85c2c85ab5ae91141bacb23d0d881dcbfa5e9bd6 Mon Sep 17 00:00:00 2001 From: grakiss Date: Mon, 20 Nov 2017 06:19:29 +0000 Subject: [cvp-web] Can't submit the same results to review from different users JIRA: DOVETAIL-560 Can't submit the same results to review from different users. Change-Id: I4a3dcc2dc8a817653ac9da6f93722659e04c89a1 Signed-off-by: grakiss --- cvp/opnfv_testapi/resources/test_handlers.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/cvp/opnfv_testapi/resources/test_handlers.py b/cvp/opnfv_testapi/resources/test_handlers.py index 3c33b7db..2baa2943 100644 --- a/cvp/opnfv_testapi/resources/test_handlers.py +++ b/cvp/opnfv_testapi/resources/test_handlers.py @@ -189,25 +189,21 @@ class TestsGURHandler(GenericTestHandler): query = {'_id': objectid.ObjectId(_id)} db_keys = ['_id', ] curr_user = self.get_secure_cookie(auth_const.OPENID) - if item in {"shared", "label"}: + if item in {"shared", "label", "status"}: query['owner'] = curr_user db_keys.append('owner') - if item == 'status': - user = yield dbapi.db_find_one("users", {'openid': curr_user}) - query["$or"] = [ - {"owner": curr_user}, - { - "shared": { - "$elemMatch": {"$eq": curr_user} - } - }, - { - "shared": { - "$elemMatch": {"$eq": user['email']} - } - } - ] + if item == "status" and value == "review": + test = yield dbapi.db_find_one("tests", query) + if test: + test_query = {'id': test['id'], 'status': 'review'} + record = yield dbapi.db_find_one("tests", test_query) + if record: + msg = ('{} has already submitted one record with the same' + 'Test ID: {}'.format(record['owner'], test['id'])) + self.finish_request({'code': 403, 'msg': msg}) + return + logging.debug("before _update 2") self._update(query=query, db_keys=db_keys) -- cgit 1.2.3-korg