diff options
Diffstat (limited to 'cvp')
5 files changed, 44 insertions, 16 deletions
diff --git a/cvp/3rd_party/static/testapi-ui/components/results/modal/sharedModal.html b/cvp/3rd_party/static/testapi-ui/components/results/modal/sharedModal.html index de3b125d..2f50b0ce 100644 --- a/cvp/3rd_party/static/testapi-ui/components/results/modal/sharedModal.html +++ b/cvp/3rd_party/static/testapi-ui/components/results/modal/sharedModal.html @@ -1,6 +1,6 @@ <div> - <h4>Enter user name</h4> + <h4>Enter user name or email</h4> <input type="text" ng-model="ctrl.userName" /> <div style="text-align:center;margin-top:20px;"> diff --git a/cvp/3rd_party/static/testapi-ui/components/results/results.html b/cvp/3rd_party/static/testapi-ui/components/results/results.html index 18de5ea0..5d6979da 100644 --- a/cvp/3rd_party/static/testapi-ui/components/results/results.html +++ b/cvp/3rd_party/static/testapi-ui/components/results/results.html @@ -54,7 +54,7 @@ <a id="single-button" type="button" class="nectar-button medium accent-color regular-button" style="width:130px" uib-dropdown-toggle> Share List<span class="caret"></span> </a> - <ul class="dropdown-menu" uib-dropdown-menu role="menu" aria-labelledby="single-button" style="min-width:150%"> + <ul class="dropdown-menu" uib-dropdown-menu role="menu" aria-labelledby="single-button" style="min-width:200%"> <li class="menu-item menu-item-type-post_type menu-item-object-page" role="menuitem" ng-repeat="share in result.shared track by $index"><span>{{ share }}<i class="pull-right glyphicon glyphicon-remove" ng-click="ctrl.removeSharedUser(result, share)"></i></span></li> </ul> </div> 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) |