diff options
author | Panagiotis Karalis <pkaralis@intracom-telecom.com> | 2019-04-18 18:48:22 +0300 |
---|---|---|
committer | Panagiotis Karalis <pkaralis@intracom-telecom.com> | 2019-04-24 17:04:43 +0300 |
commit | da620c17769c0357e4a9137eedbb7cf044cc38d4 (patch) | |
tree | e2008953fa3637cd9da96fece5c2165e703436df | |
parent | 6ade07b42e9ef39dafda4504bc61eb4661b10cde (diff) |
Bug fix for ONAP/OVP portals
During portal review, some errors have been noticed and fixed.
- 'no role', In the 'My Results' page are displayed also results
from other users.
- 'user,reviewer' role, In the 'My Results' page are appeared all
results and not only for the current user.
- 'administrator' role, The applications are not appeared in the
application page
- 'reviewer' role, Reviewers cannot submit votes and after few
seconds a 'time out' is received.
Change-Id: Ia9bc3c4fdcac1b37ac03adff64ff689ca2428c0f
Signed-off-by: Panagiotis Karalis <pkaralis@intracom-telecom.com>
9 files changed, 110 insertions, 119 deletions
diff --git a/3rd_party/static/onap-ui/components/application/application.html b/3rd_party/static/onap-ui/components/application/application.html index 2238ca4..5a0a199 100644 --- a/3rd_party/static/onap-ui/components/application/application.html +++ b/3rd_party/static/onap-ui/components/application/application.html @@ -56,7 +56,8 @@ </div> </script> <tbody style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"> - <tr ng-if="results.status != 'review'" ng-repeat="app in ctrl.applications"> + <tr ng-if="auth.currentUser.role.indexOf('administrator') != -1" + ng-repeat="app in ctrl.applications"> <td>{{ app.creation_date | limitTo: 10 }}</td> <td>{{ app.owner }}</td> <td>{{ app.onap_version }}</td> @@ -80,7 +81,7 @@ <i ng-if="app.lab_location != 'internal'" class="glyphicon glyphicon-info-sign opnfv-blue"></i> </td> <td> - <a ng-click="ctrl.toggleApproveApp(app._id, 'true')" class="badge badge-info" + <a ng-click="ctrl.toggleApproveApp(app._id, 'true', app.owner)" class="badge badge-info" ng-if="app.approved == 'false'" data-toggle="tooltip" title="Approve Application"> <i class="glyphicon glyphicon-ok" ></i> diff --git a/3rd_party/static/onap-ui/components/application/applicationController.js b/3rd_party/static/onap-ui/components/application/applicationController.js index 094ffdc..134b002 100644 --- a/3rd_party/static/onap-ui/components/application/applicationController.js +++ b/3rd_party/static/onap-ui/components/application/applicationController.js @@ -20,17 +20,28 @@ .controller('ApplicationController', ApplicationController); ApplicationController.$inject = [ - '$http', '$stateParams', '$window', '$sce', + '$http', '$state', '$stateParams', '$window', '$sce', '$uibModal', 'testapiApiUrl', 'raiseAlert', 'ngDialog', '$scope' ]; /** */ - function ApplicationController($http, $stateParams, $window, $sce, + function ApplicationController($http, $state, $stateParams, $window, $sce, $uibModal, testapiApiUrl, raiseAlert, ngDialog, $scope) { var ctrl = this; + /** Check to see if this page should display community results. */ + ctrl.isAdministrator = $scope.auth.currentUser.role.indexOf('administrator') != -1; + // Should only be on user-results-page if authenticated. + if (!$scope.auth.isAuthenticated) { + $state.go('home'); + } + // Should only be on applications if administrator + if (!ctrl.isAdministrator) { + $state.go('home'); + } + function init() { ctrl.applications = []; @@ -65,7 +76,7 @@ }); } - ctrl.toggleApproveApp = function(id, approved) { + ctrl.toggleApproveApp = function(id, approved, owner) { if (approved === 'true') { var text = 'Are you sure you want to approve this application?'; } else { @@ -80,6 +91,7 @@ var data = {}; data['item'] = 'approved'; data['approved'] = approved; + data['owner'] = owner; $http.put(updateUrl, JSON.stringify(data), { transformRequest: angular.identity, @@ -95,7 +107,7 @@ } function getApplication() { - $http.get(testapiApiUrl + "/onap/cvp/applications?page=" + ctrl.currentPage + "&signed&per_page=" + ctrl.itemsPerPage).then(function(response) { + $http.get(testapiApiUrl + "/onap/cvp/applications?page=" + ctrl.currentPage + "&signed&per_page=" + ctrl.itemsPerPage + "&applications").then(function(response) { ctrl.applications = response.data.applications; ctrl.totalItems = response.data.pagination.total_pages * ctrl.itemsPerPage; ctrl.currentPage = response.data.pagination.current_page; diff --git a/3rd_party/static/onap-ui/components/results/resultsController.js b/3rd_party/static/onap-ui/components/results/resultsController.js index 5983dd8..e8187f3 100644 --- a/3rd_party/static/onap-ui/components/results/resultsController.js +++ b/3rd_party/static/onap-ui/components/results/resultsController.js @@ -552,6 +552,7 @@ var start = $filter('date')(ctrl.startDate, 'yyyy-MM-dd'); var end = $filter('date')(ctrl.endDate, 'yyyy-MM-dd'); + ctrl.PageName = null; content_url += '?page=' + ctrl.currentPage; content_url += '&per_page=' + ctrl.itemsPerPage; if (start) { @@ -562,6 +563,7 @@ } if (ctrl.isUserResults) { content_url += '&signed'; + ctrl.PageName = 'MyResults'; } else { content_url += '&status={"$ne":"private"}&review'; } @@ -572,6 +574,25 @@ ctrl.totalItems = ctrl.data.pagination.total_pages * ctrl.itemsPerPage; ctrl.currentPage = ctrl.data.pagination.current_page; ctrl.numPages = ctrl.data.pagination.total_pages; + if (ctrl.PageName === 'MyResults') { + for (var i=0; i<data.tests.length; i++) { + if (data.tests[i].owner !== ctrl.currentUser) { + var sharing = false; + if (data.tests[i].shared !== null){ + for (var j=0; j<data.tests[i].shared.length; j++) { + if (data.tests[i].shared[j] === ctrl.currentUser){ + sharing = true; + } + } + } + if (sharing == false){ + data.tests.splice(i,1); + i = i - 1; + } + } + } + ctrl.data = data; + } }).error(function (error) { ctrl.data = null; ctrl.totalItems = 0; diff --git a/3rd_party/static/testapi-ui/app.js b/3rd_party/static/testapi-ui/app.js index 55603aa..635c0ac 100644 --- a/3rd_party/static/testapi-ui/app.js +++ b/3rd_party/static/testapi-ui/app.js @@ -181,11 +181,7 @@ var profile_url = testapiApiUrl + '/profile'; function canReview(user) { - if (typeof user.role == undefined) { - return false; - } else if (user.role.indexOf('administrator') != -1) { - return true; - } else if (user.role.indexOf('reviewer') != -1) { + if (user.role.indexOf('reviewer') != -1) { return true; } else { return false; diff --git a/3rd_party/static/testapi-ui/components/application/application.html b/3rd_party/static/testapi-ui/components/application/application.html index 5e78546..336b3b1 100644 --- a/3rd_party/static/testapi-ui/components/application/application.html +++ b/3rd_party/static/testapi-ui/components/application/application.html @@ -60,7 +60,8 @@ </div> </script> <tbody style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"> - <tr ng-repeat="app in ctrl.applications"> + <tr ng-if="auth.currentUser.role.indexOf('administrator') != -1" + ng-repeat="app in ctrl.applications"> <td>{{ app.creation_date | limitTo: 10 }}</td> <td>{{ app.organization_name }}</td> <td><a href="{{app.organization_web}}">{{ app.organization_web }}</a></td> @@ -88,7 +89,7 @@ <i ng-if="app.lab_location != 'internal'" class="glyphicon glyphicon-info-sign opnfv-blue"></i> </td> <td> - <a ng-click="ctrl.toggleApproveApp(app._id, 'true')" class="badge badge-info" + <a ng-click="ctrl.toggleApproveApp(app._id, 'true', app.owner)" class="badge badge-info" ng-if="app.approved == 'false'" data-toggle="tooltip" title="Approve Application"> <i class="glyphicon glyphicon-ok" ></i> diff --git a/3rd_party/static/testapi-ui/components/application/applicationController.js b/3rd_party/static/testapi-ui/components/application/applicationController.js index 6ae157e..366863c 100644 --- a/3rd_party/static/testapi-ui/components/application/applicationController.js +++ b/3rd_party/static/testapi-ui/components/application/applicationController.js @@ -20,44 +20,28 @@ .controller('ApplicationController', ApplicationController); ApplicationController.$inject = [ - '$http', '$stateParams', '$window', '$sce', + '$http', '$state', '$stateParams', '$window', '$sce', '$uibModal', 'testapiApiUrl', 'raiseAlert', 'ngDialog', '$scope' ]; - function ApplicationController ($http, $stateParams, $window, $sce, + function ApplicationController ($http, $state, $stateParams, $window, $sce, $uibModal, testapiApiUrl, raiseAlert, ngDialog, $scope) { var ctrl = this; -// ctrl.uploadLogo = uploadLogo; + + /** Check to see if this page should display community results. */ + ctrl.isAdministrator = $scope.auth.currentUser.role.indexOf('administrator') != -1; + // Should only be on user-results-page if authenticated. + if (!$scope.auth.isAuthenticated) { + $state.go('home'); + } + // Should only be on applications if administrator + if (!ctrl.isAdministrator) { + $state.go('home'); + } function init() { ctrl.applications = []; -// ctrl.organization_name = null; -// ctrl.organization_web = null; -// ctrl.product_name = null; -// ctrl.product_spec = null; -// ctrl.product_documentation = null; -// ctrl.product_categories = "soft&hard"; -// ctrl.prim_name = null; -// ctrl.prim_email = null; -// ctrl.prim_address = null; -// ctrl.prim_phone = null; -// ctrl.description = null; -// ctrl.sut_version = null; -// ctrl.sut_hw_version = null; -// ctrl.ovp_version = "2018.01"; -// ctrl.ovp_category = "Infrastructure"; -// ctrl.company_logo = null; -// ctrl.approve_date = null; -// ctrl.approved = "false"; -// ctrl.test_id = null; -// ctrl.lab_location = "internal"; -// ctrl.lab_name = null; -// ctrl.lab_email = null; -// ctrl.lab_address = null; -// ctrl.lab_phone = null; -// ctrl.applications = []; -// ctrl.showApplications = []; ctrl.totalItems = null; ctrl.currentPage = 1; @@ -65,59 +49,10 @@ ctrl.numPages = null; ctrl.lab_tpl = "lab.tpl.html"; ctrl.product_tpl = "product.tpl.html"; - //ctrl.lab_html=$sce.trustAsHtml('<div>{{app.lab_email}}</div><div>{{app.lab_address}}</div><div>{{app.lab_phone}}</div>'); getApplication(); } - -// ctrl.submitForm = function() { -// var data = { -// "organization_name": ctrl.organization_name, -// "organization_web": ctrl.organization_web, -// "product_name": ctrl.product_name, -// "product_spec": ctrl.product_spec, -// "product_documentation": ctrl.product_documentation, -// "product_categories": ctrl.product_categories, -// "prim_name": ctrl.prim_name, -// "prim_email": ctrl.prim_email, -// "prim_address": ctrl.prim_address, -// "prim_phone": ctrl.prim_phone, -// "description": ctrl.description, -// "sut_version": ctrl.sut_version, -// "sut_hw_version": ctrl.sut_hw_version, -// "ovp_version": ctrl.ovp_version, -// "ovp_category": ctrl.ovp_category, -// "company_logo": ctrl.company_logo, -// "approve_date": ctrl.approve_date, -// "approved": ctrl.approved, -// "test_id": ctrl.test_id, -// "lab_location": ctrl.lab_location, -// "lab_email": ctrl.lab_email, -// "lab_address": ctrl.lab_address, -// "lab_phone": ctrl.lab_phone -// }; -// $http.post(testapiApiUrl + "/cvp/applications", data).then(function(resp) { -// if (resp.data.code && resp.data.code != 0) { -// alert(resp.data.msg); -// return; -// } -// getApplication(); -// }, function(error) { -// }); -// } - -// ctrl.openConfirmModal = function() { -// var resp = confirm("Are you sure to submit?"); -// if (resp) { -// ctrl.submitForm(); -// } -// } -// -// ctrl.cancelSubmit = function() { -// ngDialog.close(); -// } - ctrl.updatePage = function() { getApplication(); } @@ -137,7 +72,7 @@ }); } - ctrl.toggleApproveApp = function(id, approved) { + ctrl.toggleApproveApp = function(id, approved, owner) { if (approved === 'true') { var text = 'Are you sure you want to approve this application?'; } else { @@ -152,6 +87,7 @@ var data = {}; data['item'] = 'approved'; data['approved'] = approved; + data['owner'] = owner; $http.put(updateUrl, JSON.stringify(data), { transformRequest: angular.identity, @@ -166,26 +102,8 @@ }); } -// function uploadLogo() { -// var file = $scope.logoFile; -// var fd = new FormData(); -// fd.append('file', file); -// -// $http.post(testapiApiUrl + "/cvp/applications/uploadlogo", fd, { -// transformRequest: angular.identity, -// headers: {'Content-Type': undefined} -// }).then(function(resp) { -// if (resp.data.code && resp.data.code != 0) { -// alert(resp.data.msg); -// return; -// } -// }, function(error) { -// }); -// -// }; - function getApplication() { - $http.get(testapiApiUrl + "/cvp/applications?page=" + ctrl.currentPage + "&signed&per_page=" + ctrl.itemsPerPage).then(function(response) { + $http.get(testapiApiUrl + "/cvp/applications?page=" + ctrl.currentPage + "&signed&per_page=" + ctrl.itemsPerPage + "&applications").then(function(response) { ctrl.applications = response.data.applications; ctrl.totalItems = response.data.pagination.total_pages * ctrl.itemsPerPage; ctrl.currentPage = response.data.pagination.current_page; diff --git a/3rd_party/static/testapi-ui/components/results/resultsController.js b/3rd_party/static/testapi-ui/components/results/resultsController.js index f752412..482d3a9 100644 --- a/3rd_party/static/testapi-ui/components/results/resultsController.js +++ b/3rd_party/static/testapi-ui/components/results/resultsController.js @@ -148,7 +148,7 @@ } // Should only be on user-results-page if authenticated. - if (ctrl.isUserResults && !$scope.auth.isAuthenticated) { + if (!ctrl.isUserResults && !ctrl.isReviewer) { $state.go('home'); } @@ -579,6 +579,7 @@ var content_url = testapiApiUrl + '/tests'; var start = $filter('date')(ctrl.startDate, 'yyyy-MM-dd'); var end = $filter('date')(ctrl.endDate, 'yyyy-MM-dd'); + ctrl.PageName = null; content_url += '?page=' + ctrl.currentPage; content_url += '&per_page=' + ctrl.itemsPerPage; if (start) { @@ -590,6 +591,7 @@ } if (ctrl.isUserResults) { content_url += '&signed'; + ctrl.PageName = 'MyResults'; } else { content_url += '&status={"$ne":"private"}&review'; } @@ -600,6 +602,25 @@ ctrl.totalItems = ctrl.data.pagination.total_pages * ctrl.itemsPerPage; ctrl.currentPage = ctrl.data.pagination.current_page; ctrl.numPages = ctrl.data.pagination.total_pages; + if (ctrl.PageName === 'MyResults') { + for (var i=0; i<data.tests.length; i++) { + if (data.tests[i].owner !== ctrl.currentUser) { + var sharing = false; + if (data.tests[i].shared !== null){ + for (var j=0; j<data.tests[i].shared.length; j++) { + if (data.tests[i].shared[j] === ctrl.currentUser){ + sharing = true; + } + } + } + if (sharing == false){ + data.tests.splice(i,1); + i = i - 1; + } + } + } + ctrl.data = data; + } }).error(function (error) { ctrl.data = null; ctrl.totalItems = 0; diff --git a/opnfv_testapi/resources/application_handlers.py b/opnfv_testapi/resources/application_handlers.py index 7d823b8..653e6b5 100644 --- a/opnfv_testapi/resources/application_handlers.py +++ b/opnfv_testapi/resources/application_handlers.py @@ -236,19 +236,19 @@ class ApplicationsGURHandler(GenericApplicationHandler): data = json.loads(self.request.body) item = data.get('item') value = data.get(item) + owner = data.get('owner') logging.debug('%s:%s', item, value) try: - self.update(application_id, item, value) + self.update(application_id, item, value, owner) except Exception as e: logging.error('except:%s', e) return @gen.coroutine - def update(self, application_id, item, value): + def update(self, application_id, item, value, owner): self.json_args = {} self.json_args[item] = value - query = {'_id': objectid.ObjectId(application_id), 'owner': - self.get_secure_cookie(auth_const.OPENID)} + query = {'_id': objectid.ObjectId(application_id), 'owner': owner} db_keys = ['_id', 'owner'] if item == 'approved': if value == 'true': diff --git a/opnfv_testapi/resources/handlers.py b/opnfv_testapi/resources/handlers.py index 559e689..df0cae5 100644 --- a/opnfv_testapi/resources/handlers.py +++ b/opnfv_testapi/resources/handlers.py @@ -79,6 +79,30 @@ class GenericApiHandler(web.RequestHandler): date_range.update({'$gte': str(v)}) elif k == 'to': date_range.update({'$lt': str(v)}) + elif k == 'applications': + role = self.get_secure_cookie(auth_const.ROLE) + logging.info('role:%s', role) + if role: + if role.find("administrator") != -1: + query['$or'] = [ + { + "status": { + "$ne": "private" + } + } + ] + elif k == 'review': + role = self.get_secure_cookie(auth_const.ROLE) + logging.info('role:%s', role) + if role: + if role.find("reviewer") != -1: + query['$or'] = [ + { + "status": { + "$ne": "private" + } + } + ] elif k == 'signed': openid = self.get_secure_cookie(auth_const.OPENID) user = yield dbapi.db_find_one("users", {'openid': openid}) @@ -98,9 +122,6 @@ class GenericApiHandler(web.RequestHandler): } } ] - - if role.find("reviewer") != -1: - query['$or'].append({"status": {"$ne": "private"}}) elif k == 'status': if v.startswith('{'): query[k] = json.loads(v) |