Při definici nového střediska se automaticky nastaví členství ve

funkcích pro středisko. 
refs #97
multitenant
Josef Rokos 11 years ago
parent 21ebddc4ef
commit 6c777a78f1

@ -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<User> {
public void setPassword(User user, String password);
public boolean hasRole(User user, String authority);
public void saveWithPwd(User user, String password);
public List<User> getUsersWithRole(Role r);
public User getCurrent();
public String encodePassword(User user, String plain);
public void grantAdmin();

@ -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<User> implements UserServic
SecurityContextHolder.getContext().setAuthentication(null);
}
@SuppressWarnings("unchecked")
@Override
@Transactional
public List<User> getUsersWithRole(Role r) {
Set<Role> roles = new HashSet<Role>();
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();
}
}

@ -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<Workgroup> {
@NotifyChange({"workgroupRoles", "centre", "users"})
public void setCentre(boolean centre) {
getDataBean().setCentre(centre);
getDataBean().getMembers().clear();
if (centre) {
List<Role> centreRoles = roleService.getCentreRoles();
for (Role r : centreRoles) {
if (!r.getAuthority().equals(Constants.ROLE_USER)) {
List<User> users = userService.getUsersWithRole(r);
for (User u : users) {
workgroupService.addMember(getDataBean(), u, r);
}
}
}
}
}
public boolean getCentre() {

Loading…
Cancel
Save