This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository coselmar. See http://git.codelutin.com/coselmar.git commit 8071f4691e7c46a0f5cc98cda8df7e2c10494f71 Author: Yannick Martel <martel@©odelutin.com> Date: Thu Feb 5 11:37:29 2015 +0100 add API to get experts list, available for expert users --- .../coselmar/services/v1/UsersWebService.java | 46 ++++++++++++++++++++++ coselmar-rest/src/main/resources/mapping | 1 + coselmar-ui/src/main/webapp/i18n/en.js | 1 + coselmar-ui/src/main/webapp/i18n/fr.js | 1 + .../src/main/webapp/js/coselmar-controllers.js | 4 +- .../src/main/webapp/js/coselmar-services.js | 4 +- .../main/webapp/views/documents/editDocument.html | 2 +- .../main/webapp/views/documents/newdocument.html | 2 +- 8 files changed, 55 insertions(+), 6 deletions(-) diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/UsersWebService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/UsersWebService.java index a3deee0..c0dbe5c 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/UsersWebService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/UsersWebService.java @@ -152,6 +152,52 @@ public class UsersWebService extends CoselmarWebServiceSupport { return result; } + public List<UserBean> getExperts(UserSearchBean search) throws InvalidCredentialException, UnauthorizedException { + + // Check authentication + String authorization = getContext().getHeader("Authorization"); + CoselmarUser currentUser = checkUserAuthentication(authorization); + + // Who is allowed here ? Admin and user himself + if (currentUser.getRole() != CoselmarUserRole.ADMIN + && currentUser.getRole() != CoselmarUserRole.SUPERVISOR + && currentUser.getRole() != CoselmarUserRole.EXPERT) { + if (log.isDebugEnabled()) { + String message = String.format("A non admin, non supervisor, non expert user is trying to access experts list"); + log.debug(message); + } + throw new UnauthorizedException("Not allowed to see experts"); + } + + List<CoselmarUser> userList; + if (search != null) { + // Search default parameter if not given + SearchRequestBean requestBean = new SearchRequestBean(); + requestBean.setLimit(search.getLimit()); + requestBean.setPage(search.getPage()); + requestBean.setFullTextSearch(search.getFullTextSearch()); + + CoselmarUser example = BeanEntityConverter.fromBean(search); + example.setRole(CoselmarUserRole.EXPERT);// we search experts here, force it ! + + userList = getCoselmarUserDao().findAllByExample(example, search.isActiveAndInactive(), requestBean); + + } else { + userList = getCoselmarUserDao().forRoleEquals(CoselmarUserRole.EXPERT).findAll(); + + } + + List<UserBean> result = new ArrayList<>(userList.size()); + + for (CoselmarUser user : userList) { + String userLightId = getPersistenceContext().getTopiaIdFactory().getRandomPart(user.getTopiaId()); + UserBean userBean = BeanEntityConverter.toBean(userLightId, user); + result.add(userBean); + } + + return result; + } + public void addUser(UserBean user) throws InvalidParameterException, InvalidCredentialException, UnauthorizedException { Preconditions.checkNotNull(user); diff --git a/coselmar-rest/src/main/resources/mapping b/coselmar-rest/src/main/resources/mapping index f0fd0df..3d166f2 100644 --- a/coselmar-rest/src/main/resources/mapping +++ b/coselmar-rest/src/main/resources/mapping @@ -43,6 +43,7 @@ DELETE /v1/documents/{documentId} DocumentsWebService.deleteDocume # Users Api GET /v1/users UsersWebService.getUsers +GET /v1/users/experts UsersWebService.getExperts GET /v1/users/{userId} UsersWebService.getUser POST /v1/users/login UsersWebService.login POST /v1/users/password UsersWebService.generateNewPassword diff --git a/coselmar-ui/src/main/webapp/i18n/en.js b/coselmar-ui/src/main/webapp/i18n/en.js index 457b4cd..6029427 100644 --- a/coselmar-ui/src/main/webapp/i18n/en.js +++ b/coselmar-ui/src/main/webapp/i18n/en.js @@ -107,6 +107,7 @@ var translateEN = { "document.message.requiredCopyright" : "Document copyright is required.", "document.message.requiredSummary" : "A summary is required.", "document.privacy.questionRestricted" : "Restricted to Project participants", +"document.privacy.restricted.info" : "Restricted to selected experts and to projects using document", "document.button.download" : "Download", "document.button.openLink" : "Open link", diff --git a/coselmar-ui/src/main/webapp/i18n/fr.js b/coselmar-ui/src/main/webapp/i18n/fr.js index 170d3da..ba6c83f 100644 --- a/coselmar-ui/src/main/webapp/i18n/fr.js +++ b/coselmar-ui/src/main/webapp/i18n/fr.js @@ -107,6 +107,7 @@ var translateFR = { "document.message.requiredCopyright" : "Le copyright du document est requis.", "document.message.requiredSummary" : "Un résumé est requis.", "document.privacy.questionRestricted" : "Restreint aux participants de projet.", +"document.privacy.restricted.info" : "Restreint aux experts indiqués et aux projets incluant le document", "document.button.download" : "Télécharger", "document.button.openLink" : "Ouvrir le lien", diff --git a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js index 8c23c11..2dad51f 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js @@ -158,7 +158,7 @@ coselmarControllers.controller("NewDocumentCtrl", ['$scope', '$location', 'docum searchKeywords.push(searchKeyword); } - documentService.findUsers({'role': 'EXPERT', 'active': true, 'fullTextSearch' : searchKeywords}, function(users) { + documentService.findExperts({'active': true, 'fullTextSearch' : searchKeywords}, function(users) { $scope.users = users; $scope.usersIndex = []; angular.forEach($scope.users, function(user) { @@ -349,7 +349,7 @@ coselmarControllers.controller("DocumentViewCtrl", searchKeywords.push(searchKeyword); } - documentService.findUsers({'role': 'EXPERT', 'active': true, 'fullTextSearch' : searchKeywords}, function(users) { + documentService.findExperts({'active': true, 'fullTextSearch' : searchKeywords}, function(users) { $scope.users = users; $scope.usersIndex = []; angular.forEach($scope.users, function(user) { diff --git a/coselmar-ui/src/main/webapp/js/coselmar-services.js b/coselmar-ui/src/main/webapp/js/coselmar-services.js index 6e2f2f7..815cfc0 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-services.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-services.js @@ -130,8 +130,8 @@ function Document(resource, config){ docResource.query(successFunction); }; - this.findUsers = function(example, successFunction) { - var userResource = resource(usersURL, {'search': example}); + this.findExperts = function(example, successFunction) { + var userResource = resource(usersURL + '/experts', {'search': example}); userResource.query(successFunction); }; diff --git a/coselmar-ui/src/main/webapp/views/documents/editDocument.html b/coselmar-ui/src/main/webapp/views/documents/editDocument.html index 7764bc8..caf807c 100644 --- a/coselmar-ui/src/main/webapp/views/documents/editDocument.html +++ b/coselmar-ui/src/main/webapp/views/documents/editDocument.html @@ -103,7 +103,7 @@ </select> <div ng-if="document.privacy == 'RESTRICTED'"> - {{ 'document.metadata.restricted.info' | translate }} + {{ 'document.privacy.restricted.info' | translate }} <ui-select multiple ng-model="document.authorizedUsers" theme="bootstrap" reset-search-input="true" diff --git a/coselmar-ui/src/main/webapp/views/documents/newdocument.html b/coselmar-ui/src/main/webapp/views/documents/newdocument.html index 96da0c7..132e1af 100644 --- a/coselmar-ui/src/main/webapp/views/documents/newdocument.html +++ b/coselmar-ui/src/main/webapp/views/documents/newdocument.html @@ -112,7 +112,7 @@ </select> <div ng-if="document.privacy == 'RESTRICTED'"> - {{ 'document.metadata.restricted.info' | translate }} + {{ 'document.privacy.restricted.info' | translate }} <ui-select multiple ng-model="document.authorizedUsers" theme="bootstrap" reset-search-input="true" -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.