From 6c777a78f1d955c01f2941b196611d3da0c7e8d8 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Mon, 7 Jul 2014 13:48:58 +0200 Subject: [PATCH] =?UTF-8?q?P=C5=99i=20definici=20nov=C3=A9ho=20st=C5=99edi?= =?UTF-8?q?ska=20se=20automaticky=20nastav=C3=AD=20=C4=8Dlenstv=C3=AD=20ve?= =?UTF-8?q?=20funkc=C3=ADch=20pro=20st=C5=99edisko.=20refs=20#97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bukova/isspst/services/users/UserService.java | 4 ++++ .../isspst/services/users/UserServiceImpl.java | 15 +++++++++++++++ .../isspst/ui/workgroups/WorkgroupForm.java | 15 +++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/src/main/java/info/bukova/isspst/services/users/UserService.java b/src/main/java/info/bukova/isspst/services/users/UserService.java index d97e3620..182a4b46 100644 --- a/src/main/java/info/bukova/isspst/services/users/UserService.java +++ b/src/main/java/info/bukova/isspst/services/users/UserService.java @@ -1,5 +1,8 @@ package info.bukova.isspst.services.users; +import java.util.List; + +import info.bukova.isspst.data.Role; import info.bukova.isspst.data.User; import info.bukova.isspst.services.Service; @@ -10,6 +13,7 @@ public interface UserService extends UserDetailsService, Service { public void setPassword(User user, String password); public boolean hasRole(User user, String authority); public void saveWithPwd(User user, String password); + public List getUsersWithRole(Role r); public User getCurrent(); public String encodePassword(User user, String plain); public void grantAdmin(); diff --git a/src/main/java/info/bukova/isspst/services/users/UserServiceImpl.java b/src/main/java/info/bukova/isspst/services/users/UserServiceImpl.java index a9780c73..4c891cab 100644 --- a/src/main/java/info/bukova/isspst/services/users/UserServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/users/UserServiceImpl.java @@ -1,5 +1,9 @@ package info.bukova.isspst.services.users; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + import org.hibernate.Query; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.encoding.PasswordEncoder; @@ -99,5 +103,16 @@ public class UserServiceImpl extends AbstractService implements UserServic SecurityContextHolder.getContext().setAuthentication(null); } + @SuppressWarnings("unchecked") + @Override + @Transactional + public List getUsersWithRole(Role r) { + Set roles = new HashSet(); + roles.add(r); + Query q = dao.getQuery("select u from User u join u.authorities a where a in (:roles)"); + q.setParameterList("roles", roles); + return q.list(); + } + } diff --git a/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupForm.java b/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupForm.java index 508e4a7e..7dac28db 100644 --- a/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupForm.java +++ b/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupForm.java @@ -1,8 +1,10 @@ package info.bukova.isspst.ui.workgroups; +import info.bukova.isspst.Constants; import info.bukova.isspst.data.JobMapping; import info.bukova.isspst.data.Member; import info.bukova.isspst.data.Role; +import info.bukova.isspst.data.User; import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.services.users.RoleService; import info.bukova.isspst.services.users.UserService; @@ -66,6 +68,19 @@ public class WorkgroupForm extends FormViewModel { @NotifyChange({"workgroupRoles", "centre", "users"}) public void setCentre(boolean centre) { getDataBean().setCentre(centre); + getDataBean().getMembers().clear(); + + if (centre) { + List centreRoles = roleService.getCentreRoles(); + for (Role r : centreRoles) { + if (!r.getAuthority().equals(Constants.ROLE_USER)) { + List users = userService.getUsersWithRole(r); + for (User u : users) { + workgroupService.addMember(getDataBean(), u, r); + } + } + } + } } public boolean getCentre() {