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() {