diff options
author | grakiss <grakiss.wanglei@huawei.com> | 2017-10-18 22:15:32 -0400 |
---|---|---|
committer | Leo wang <grakiss.wanglei@huawei.com> | 2017-10-20 03:29:26 +0000 |
commit | 54bc0f28fd9b5ec6675401d6c3322b30e72e7d9c (patch) | |
tree | c203b151a705b53eb85e15af6ac62169857a2603 /cvp/opnfv_testapi | |
parent | 4f2c6191c68567e3fd7ee7e8bcb737c3194fbb2e (diff) |
[web-cvp]share result by email
JIRA: DOVETAIL-529
It may be easier to get other people's email than his user id
Change-Id: Ia5f9aa72d3c79bd3f5e69dad98b3f188cdaafc3d
Signed-off-by: grakiss <grakiss.wanglei@huawei.com>
Diffstat (limited to 'cvp/opnfv_testapi')
-rw-r--r-- | cvp/opnfv_testapi/resources/application_handlers.py | 5 | ||||
-rw-r--r-- | cvp/opnfv_testapi/resources/handlers.py | 14 | ||||
-rw-r--r-- | cvp/opnfv_testapi/resources/test_handlers.py | 37 |
3 files changed, 42 insertions, 14 deletions
diff --git a/cvp/opnfv_testapi/resources/application_handlers.py b/cvp/opnfv_testapi/resources/application_handlers.py index 16dae4f3..6986b9ef 100644 --- a/cvp/opnfv_testapi/resources/application_handlers.py +++ b/cvp/opnfv_testapi/resources/application_handlers.py @@ -31,6 +31,8 @@ class GenericApplicationHandler(handlers.GenericApiHandler): class ApplicationsCLHandler(GenericApplicationHandler): @swagger.operation(nickname="queryApplications") + @web.asynchronous + @gen.coroutine def get(self): """ @description: Retrieve result(s) for a application project @@ -64,7 +66,8 @@ class ApplicationsCLHandler(GenericApplicationHandler): 'per_page': CONF.api_results_per_page } - self._list(query=self.set_query(), **limitations) + query = yield self.set_query() + yield self._list(query=query, **limitations) logging.debug('list end') @swagger.operation(nickname="createApplication") diff --git a/cvp/opnfv_testapi/resources/handlers.py b/cvp/opnfv_testapi/resources/handlers.py index 17a7e359..51092b94 100644 --- a/cvp/opnfv_testapi/resources/handlers.py +++ b/cvp/opnfv_testapi/resources/handlers.py @@ -59,6 +59,7 @@ class GenericApiHandler(web.RequestHandler): raises.BadRequest(message.must_int(key)) return value + @gen.coroutine def set_query(self): query = dict() date_range = dict() @@ -76,13 +77,17 @@ class GenericApiHandler(web.RequestHandler): date_range.update({'$lt': str(v)}) elif k == 'signed': openid = self.get_secure_cookie(auth_const.OPENID) + user = yield dbapi.db_find_one("users", {'openid': openid}) role = self.get_secure_cookie(auth_const.ROLE) logging.info('role:%s', role) if role: if role.find("reviewer") != -1: query['$or'] = [{"shared": - {"$elemMatch": {"$eq": openid}} - }, {"owner": openid}, + {"$elemMatch": {"$eq": openid}}}, + {"owner": openid}, + {"shared": {"$elemMatch": + {"$eq": + user.get("email")}}}, {"status": {"$ne": "private"}}] else: query['$or'] = [{"shared": @@ -99,7 +104,7 @@ class GenericApiHandler(web.RequestHandler): query['start_date'].update({'$lt': str(datetime.now())}) logging.debug("query:%s", query) - return query + raise gen.Return((query)) def prepare(self): if self.request.method != "GET" and self.request.method != "DELETE": @@ -178,9 +183,10 @@ class GenericApiHandler(web.RequestHandler): raise gen.Return((True, 'Data alreay exists. %s' % (query))) raise gen.Return((False, 'Data does not exist. %s' % (query))) - @web.asynchronous + # @web.asynchronous @gen.coroutine def _list(self, query=None, res_op=None, *args, **kwargs): + logging.debug("_list query:%s", query) sort = kwargs.get('sort') page = kwargs.get('page', 0) last = kwargs.get('last', 0) diff --git a/cvp/opnfv_testapi/resources/test_handlers.py b/cvp/opnfv_testapi/resources/test_handlers.py index 9ad1bbc2..2cbfbf10 100644 --- a/cvp/opnfv_testapi/resources/test_handlers.py +++ b/cvp/opnfv_testapi/resources/test_handlers.py @@ -33,6 +33,8 @@ class GenericTestHandler(handlers.GenericApiHandler): class TestsCLHandler(GenericTestHandler): @swagger.operation(nickname="queryTests") + @web.asynchronous + @gen.coroutine def get(self): """ @description: Retrieve result(s) for a test project @@ -68,7 +70,8 @@ class TestsCLHandler(GenericTestHandler): 'per_page': CONF.api_results_per_page } - self._list(query=self.set_query(), **limitations) + query = yield self.set_query() + yield self._list(query=query, **limitations) logging.debug('list end') @swagger.operation(nickname="createTest") @@ -141,16 +144,27 @@ class TestsGURHandler(GenericTestHandler): return @gen.coroutine + def _convert_to_id(self, email): + query = {"email": email} + table = "users" + if query and table: + data = yield dbapi.db_find_one(table, query) + if data: + raise gen.Return((True, 'Data alreay exists. %s' % (query), + data.get("openid"))) + raise gen.Return((False, 'Data does not exist. %s' % (query), None)) + + @gen.coroutine def update(self, test_id, item, value): logging.debug("update") if item == "shared": - if len(value) != len(set(value)): - msg = "Already shared with this user" - self.finish_request({'code': '403', 'msg': msg}) - return - + new_list = [] for user in value: - query = {"openid": user} + ret, msg, user_id = yield self._convert_to_id(user) + if ret: + user = user_id + new_list.append(user) + query = {"$or": [{"openid": user}, {"email": user}]} table = "users" ret, msg = yield self._check_if_exists(table=table, query=query) @@ -159,6 +173,11 @@ class TestsGURHandler(GenericTestHandler): self.finish_request({'code': '403', 'msg': msg}) return + if len(new_list) != len(set(new_list)): + msg = "Already shared with this user" + self.finish_request({'code': '403', 'msg': msg}) + return + logging.debug("before _update") self.json_args = {} self.json_args[item] = value @@ -169,9 +188,9 @@ class TestsGURHandler(GenericTestHandler): query = {'id': test_id} db_keys = ['id', ] - user = self.get_secure_cookie(auth_const.OPENID) + curr_user = self.get_secure_cookie(auth_const.OPENID) if item == "shared": - query['owner'] = user + query['owner'] = curr_user db_keys.append('owner') logging.debug("before _update 2") self._update(query=query, db_keys=db_keys) |