diff options
Diffstat (limited to 'cvp')
3 files changed, 89 insertions, 68 deletions
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 aab2985f..5cdc6240 100644 --- a/cvp/3rd_party/static/testapi-ui/components/results/results.html +++ b/cvp/3rd_party/static/testapi-ui/components/results/results.html @@ -38,7 +38,7 @@ <td><a uib-tooltip="{{ result.id }}" tooltip-placement="top" tooltip-append-to-body="true" ng-click="ctrl.gotoResultDetail(result.id, result._id)">{{ result.id | limitTo:8 }}</a></td> <td>{{ result.owner }}</td> <td>{{ result.filename || "None"}}</td> - <td><div class="popover-wrapper"><a editable-theme="bs3" onbeforesave="ctrl.toggleCheck(result, 'label', $data)" editable-text="result.label"> {{ result.label || "None" }}</a></div></td> + <td><div class="popover-wrapper"><a editable-theme="bs3" onbeforesave="ctrl.changeLabel(result, $data)" editable-text="result.label"> {{ result.label || "None" }}</a></div></td> <td>{{ result.status }}</td> <td><a ng-click="ctrl.downloadLogs(result.id)">logs</a></td> <td><a ng-click="ctrl.gotoSUT(result.id)">info</a></td> @@ -54,7 +54,7 @@ <li role="menuitem" ng-if="auth.currentUser.role.indexOf('reviewer') != -1" class="menu-item menu-item-type-post_type menu-item-object-page"><a ng-class="{'hide': result.status == 'approved'}" ng-click="ctrl.toggleCheck(result, 'status', 'approve')">approve</a></li> <li role="menuitem" ng-if="auth.currentUser.role.indexOf('reviewer') != -1" class="menu-item menu-item-type-post_type menu-item-object-page"><a ng-class="{'hide': result.status == 'not approved'}" ng-click="ctrl.toggleCheck(result, 'status', 'not approve')">not approve</a></li> --> - <li role="menuitem" class="menu-item menu-item-type-post_type menu-item-object-page"><a ng-click="ctrl.openSharedModal(result)">share with</a></li> + <li role="menuitem" ng-if="auth.currentUser.openid == result.owner" class="menu-item menu-item-type-post_type menu-item-object-page"><a ng-click="ctrl.openSharedModal(result)">share with</a></li> <li role="menuitem" ng-if="auth.currentUser.openid == result.owner" class="menu-item menu-item-type-post_type menu-item-object-page"><a ng-click="ctrl.deleteTest(result._id)">delete</a></li> </ul> </div> @@ -65,7 +65,7 @@ Share List<span class="caret"></span> </a> <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> + <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 ng-if="auth.currentUser.openid == result.owner" class="pull-right glyphicon glyphicon-remove" ng-click="ctrl.removeSharedUser(result, share)"></i></span></li> </ul> </div> </td> diff --git a/cvp/3rd_party/static/testapi-ui/components/results/resultsController.js b/cvp/3rd_party/static/testapi-ui/components/results/resultsController.js index 86f7c5d6..4476618c 100644 --- a/cvp/3rd_party/static/testapi-ui/components/results/resultsController.js +++ b/cvp/3rd_party/static/testapi-ui/components/results/resultsController.js @@ -62,6 +62,7 @@ ctrl.gotoSUT = gotoSUT; ctrl.gotoResultDetail = gotoResultDetail; ctrl.toggleCheck = toggleCheck; + ctrl.changeLabel = changeLabel; ctrl.toReview = toReview; ctrl.toPrivate = toPrivate; ctrl.removeSharedUser = removeSharedUser; @@ -103,7 +104,7 @@ /** The date format for the date picker. */ ctrl.format = 'yyyy-MM-dd'; - ctrl.userName = null; + ctrl.userName = null; /** Check to see if this page should display user-specific results. */ // ctrl.isUserResults = $state.current.name === 'userResults'; @@ -168,44 +169,48 @@ } function toggleCheck(result, item, newValue) { - var id = result.id; - var updateUrl = testapiApiUrl + "/tests/"+id; - - var data = {}; - data['item'] = item; - data[item] = newValue; - - $http.put(updateUrl, JSON.stringify(data), { - transformRequest: angular.identity, - headers: {'Content-Type': 'application/json'}}) - .then( function(ret) { - if(ret.data.code && ret.data.code != 0) { - alert(ret.data.msg); - } - else { - result[item] = newValue; - console.log('update success'); - } - }, function(response){ + var id = result._id; + var updateUrl = testapiApiUrl + "/tests/"+ id; + + var data = {}; + data['item'] = item; + data[item] = newValue; + + $http.put(updateUrl, JSON.stringify(data), { + transformRequest: angular.identity, + headers: {'Content-Type': 'application/json'}}).then(function(ret){ + if(ret.data.code && ret.data.code != 0) { + alert(ret.data.msg); + } + else { + result[item] = newValue; + console.log('update success'); + } + }, function(error){ + alert("Error when update data"); }); } - function toReview(result, value){ - var resp = confirm('Once you submit a test result for review, it will become readable to all CVP reviewers. Do you want to proceed?'); - if(resp){ - toggleCheck(result, 'status', value); - } - } - - function toPrivate(result, value){ - var resp = confirm('Do you want to proceed?'); - if(resp){ - toggleCheck(result, 'status', value); - } - } - - function openSharedModal(result){ - ctrl.tempResult = result; + function changeLabel(result, data){ + toggleCheck(result, 'label', data); + } + + function toReview(result, value){ + var resp = confirm('Once you submit a test result for review, it will become readable to all CVP reviewers. Do you want to proceed?'); + if(resp){ + toggleCheck(result, 'status', value); + } + } + + function toPrivate(result, value){ + var resp = confirm('Do you want to proceed?'); + if(resp){ + toggleCheck(result, 'status', value); + } + } + + function openSharedModal(result){ + ctrl.tempResult = result; ngDialog.open({ preCloseCallback: function(value) { }, @@ -216,31 +221,31 @@ showClose: true, closeByDocument: true }); - } + } + + function addSharedUser(result, userId){ + var tempList = copy(result.shared); + tempList.push(userId); + toggleCheck(result, 'shared', tempList); + ngDialog.close(); + } - function addSharedUser(result, userId){ + function removeSharedUser(result, userId){ var tempList = copy(result.shared); - tempList.push(userId); - toggleCheck(result, 'shared', tempList); - ngDialog.close(); - } - - function removeSharedUser(result, userId){ - var tempList = copy(result.shared); - var idx = tempList.indexOf(userId); - if(idx != -1){ - tempList.splice(idx, 1); - toggleCheck(result, 'shared', tempList); - } - } - - function copy(arrList){ - var tempList = []; - angular.forEach(arrList, function(ele){ - tempList.push(ele); - }); - return tempList; - } + var idx = tempList.indexOf(userId); + if(idx != -1){ + tempList.splice(idx, 1); + toggleCheck(result, 'shared', tempList); + } + } + + function copy(arrList){ + var tempList = []; + angular.forEach(arrList, function(ele){ + tempList.push(ele); + }); + return tempList; + } function uploadFileToUrl(file, uploadUrl){ var fd = new FormData(); 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) |