summaryrefslogtreecommitdiffstats
path: root/cvp/opnfv_testapi/resources
diff options
context:
space:
mode:
authorgrakiss <grakiss.wanglei@huawei.com>2017-11-09 11:01:00 +0000
committerLeo wang <grakiss.wanglei@huawei.com>2017-11-09 11:55:20 +0000
commitf88b298c17a3dac9e6b2882d3f10f274572fc29d (patch)
tree13eeba65fbbb0a6f97e08d3afca6107d7a1157fc /cvp/opnfv_testapi/resources
parent135db0c9860db436a2036f2bcb6f45b164f5b848 (diff)
[cvp-web] Bugfix: use '_id' as the primary key of the data rather than the 'Test ID'
JIRA: DOVETAIL-554 It allows different users to upload the same results now. So the 'Test ID' is not unique in this situation. Use '_id' as the primary key which can uniquely identify one data. Change-Id: I852ee116f36a6a86e9b4350183e39ee00f8b99de Signed-off-by: grakiss <grakiss.wanglei@huawei.com>
Diffstat (limited to 'cvp/opnfv_testapi/resources')
-rw-r--r--cvp/opnfv_testapi/resources/test_handlers.py28
1 files changed, 22 insertions, 6 deletions
diff --git a/cvp/opnfv_testapi/resources/test_handlers.py b/cvp/opnfv_testapi/resources/test_handlers.py
index 54fa11f8..3c33b7db 100644
--- a/cvp/opnfv_testapi/resources/test_handlers.py
+++ b/cvp/opnfv_testapi/resources/test_handlers.py
@@ -121,7 +121,7 @@ class TestsGURHandler(GenericTestHandler):
@swagger.operation(nickname="updateTestById")
@web.asynchronous
- def put(self, test_id):
+ def put(self, _id):
"""
@description: update a single test by id
@param body: fields to be updated
@@ -138,7 +138,7 @@ class TestsGURHandler(GenericTestHandler):
value = data.get(item)
logging.debug('%s:%s', item, value)
try:
- self.update(test_id, item, value)
+ self.update(_id, item, value)
except Exception as e:
logging.error('except:%s', e)
return
@@ -155,7 +155,7 @@ class TestsGURHandler(GenericTestHandler):
raise gen.Return((False, 'Data does not exist. %s' % (query), None))
@gen.coroutine
- def update(self, test_id, item, value):
+ def update(self, _id, item, value):
logging.debug("update")
if item == "shared":
new_list = []
@@ -186,12 +186,28 @@ class TestsGURHandler(GenericTestHandler):
self.finish_request({'code': '404', 'msg': msg})
return
- query = {'id': test_id}
- db_keys = ['id', ]
+ query = {'_id': objectid.ObjectId(_id)}
+ db_keys = ['_id', ]
curr_user = self.get_secure_cookie(auth_const.OPENID)
- if item == "shared" or item == "label":
+ if item in {"shared", "label"}:
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']}
+ }
+ }
+ ]
logging.debug("before _update 2")
self._update(query=query, db_keys=db_keys)