This is an automated email from the git hooks/post-receive script. New commit to branch feature/adminUser in repository pollen. See http://git.chorem.org/pollen.git commit 685819f509a94927c27163d7031b6cdddfb8f02e Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Wed Jul 23 10:32:28 2014 +0200 add method for ban user --- .../chorem/pollen/rest/api/v1/PollenUserApi.java | 9 ++++++-- pollen-rest-api/src/main/resources/mapping | 1 + .../pollen/services/service/PollenUserService.java | 24 +++++++++++++++++++--- .../src/main/webapp/js/controllers/userCtrl.js | 13 +++++++++--- pollen-ui-angular/src/main/webapp/js/services.js | 4 ++++ .../src/main/webapp/partials/user-admin-list.html | 1 + 6 files changed, 44 insertions(+), 8 deletions(-) diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserApi.java index dfbf98b..b02027a 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserApi.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserApi.java @@ -79,12 +79,17 @@ public class PollenUserApi extends WebMotionController { return pollenUserService.adminUser(user); } - public void deleteUser(PollenUserService pollenUserService, PollenEntityId<PollenUser> userId) throws InvalidFormException { + public void deleteUser(PollenUserService pollenUserService, PollenEntityId<PollenUser> userId, boolean anonymize) throws InvalidFormException { - pollenUserService.deleteUser(userId.getEntityId()); + pollenUserService.deleteUser(userId.getEntityId(), anonymize); } + public void banUser(PollenUserService pollenUserService, PollenEntityId<PollenUser> userId, boolean anonymize) { + + pollenUserService.banUser(userId.getEntityId(), anonymize); + } + public void validateUserEmail(PollenUserService pollenUserService, PollenEntityId<PollenUser> userId, String token) throws PollenInvalidEmailActivationTokenException { diff --git a/pollen-rest-api/src/main/resources/mapping b/pollen-rest-api/src/main/resources/mapping index f3d8522..ddc03f7 100644 --- a/pollen-rest-api/src/main/resources/mapping +++ b/pollen-rest-api/src/main/resources/mapping @@ -132,6 +132,7 @@ PUT,POST /v1/users/{userId} PollenUserApi.editUser PUT,POST /v1/users/{userId}/password PollenUserApi.changePassword POST /v1/users/{userId}/admin PollenUserApi.adminUser DELETE /v1/users/{userId} PollenUserApi.deleteUser +DELETE /v1/users/{userId}/ban PollenUserApi.banUser PUT /v1/users/{userId}?token={} PollenUserApi.validateUserEmail # VoteCountingApi diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java index a15f3d1..d577551 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java @@ -131,15 +131,17 @@ public class PollenUserService extends PollenServiceSupport implements PollenSer return toBean(PollenUserBean.class, userSaved, pollenUserFunction); } - public void deleteUser(String userId) { + public void deleteUser(String userId, boolean anonymize) { checkNotNull(userId); checkIsAdmin(); PollenUser user = getUser0(userId); - anonymizeUser(user); - + if (anonymize) { + anonymizeUser(user); + } + getPollenUserDao().delete(user); commit(); @@ -147,6 +149,22 @@ public class PollenUserService extends PollenServiceSupport implements PollenSer } + public void banUser(String userId, boolean anonymize) { + + checkNotNull(userId); + + PollenUser user = getUser0(userId); + + if (anonymize) { + anonymizeUser(user); + } + + user.setPassword(""); + commit(); + + getNotificationService().onUserEdited(user); + } + public void changePassword(String userId, String oldPassword, String newPassword) throws PollenInvalidPasswordException { diff --git a/pollen-ui-angular/src/main/webapp/js/controllers/userCtrl.js b/pollen-ui-angular/src/main/webapp/js/controllers/userCtrl.js index f060a02..b2c3add 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/userCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/userCtrl.js @@ -116,8 +116,8 @@ angular.module('userControllers', []) } }]) -.controller('UserListCtrl', ['$scope', '$routeParams', 'User', 'Page', - function ($scope, $routeParams, User, Page) { +.controller('UserListCtrl', ['$scope', '$rootScope', '$routeParams', 'User', 'Page', + function ($scope, $rootScope, $routeParams, User, Page) { Page.setTitle('title.user.list'); @@ -152,13 +152,20 @@ angular.module('userControllers', []) }; $scope.deleteUser = function (user) { - User.remove({userId:user.id}, function (data) { + User.remove({userId:user.id, anonymize:true}, function (data) { + $rootScope.$broadcast('newSuccess', 'user.delete.success'); var userIndex = $scope.data.users.indexOf(user); if (userIndex >= 0) { $scope.data.users.splice(userIndex, 1); } }); }; + + $scope.banUser = function (user) { + User.ban({userId : user.id, anonymize:true}, function (data) { + $rootScope.$broadcast('newSuccess', 'user.ban.success'); + }); + }; }]) .controller('UserLoginCtrl', ['$scope', 'UserLogin', 'UserLogout', 'User', 'SessionStorage', '$route', '$location', '$translate', function ($scope, UserLogin, UserLogout, User, SessionStorage, $route, $location, $translate) { diff --git a/pollen-ui-angular/src/main/webapp/js/services.js b/pollen-ui-angular/src/main/webapp/js/services.js index 82ef663..4c2557e 100644 --- a/pollen-ui-angular/src/main/webapp/js/services.js +++ b/pollen-ui-angular/src/main/webapp/js/services.js @@ -230,6 +230,10 @@ angular.module('pollenServices', ['ngResource']) return 'oldPassword='+encodeURIComponent(data.password)+ '&newPassword='+encodeURIComponent(data.newPassword); } + }, + 'ban' : { + method:'DELETE', + url: conf.restURL+'/users/:userId/ban' } } ); diff --git a/pollen-ui-angular/src/main/webapp/partials/user-admin-list.html b/pollen-ui-angular/src/main/webapp/partials/user-admin-list.html index 6b3cd54..a7c09f3 100644 --- a/pollen-ui-angular/src/main/webapp/partials/user-admin-list.html +++ b/pollen-ui-angular/src/main/webapp/partials/user-admin-list.html @@ -34,6 +34,7 @@ </td> <td class="action"> <button class="btn btn-primary" ng-click="saveUser(user)"> <span class="glyphicon glyphicon-save"></span> </button> + <button class="btn btn-warning" ng-click="banUser(user)"> <span class="glyphicon glyphicon-ban-circle"></span> </button> <button class="btn btn-danger" ng-click="deleteUser(user)"> <span class="glyphicon glyphicon-trash"></span> </button> </td> </tr> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.