Commit 8c4d3a18 authored by michael.simon's avatar michael.simon
Browse files

remove and add users from/to role now possible from role view

parent 297bc8cd
......@@ -50,5 +50,9 @@ public interface RoleDao extends BaseDao<RoleEntity, Long> {
List<RoleEntity> findByGroups(Set<GroupEntity> groups);
void addUserToRole(UserEntity user, String roleName);
List<UserEntity> findUsersForRole(RoleEntity role);
List<GroupEntity> findGroupsForRole(RoleEntity role);
}
......@@ -112,6 +112,20 @@ public class JpaRoleDao extends JpaBaseDao<RoleEntity, Long> implements RoleDao
.setParameter("userId", userId).getResultList();
}
@SuppressWarnings("unchecked")
@Override
public List<UserEntity> findUsersForRole(RoleEntity role) {
return em.createQuery("select u from UserEntity u left join u.roles ur where ur.role = :role")
.setParameter("role", role).getResultList();
}
@SuppressWarnings("unchecked")
@Override
public List<GroupEntity> findGroupsForRole(RoleEntity role) {
return em.createQuery("select g from GroupEntity g left join g.roles gr where gr.role = :role")
.setParameter("role", role).getResultList();
}
@SuppressWarnings("unchecked")
@Override
public Boolean checkUserInRole(Long userId, String roleName) {
......
......@@ -46,6 +46,9 @@ public class GroupEntity extends AbstractBaseEntity {
@OneToMany(targetEntity = UserGroupEntity.class, mappedBy="group")
private Set<UserGroupEntity> users;
@OneToMany(targetEntity = RoleGroupEntity.class, mappedBy="group")
private Set<RoleGroupEntity> roles;
@ManyToMany(targetEntity=RoleEntity.class, cascade = CascadeType.ALL)
@JoinTable(name = "group_role",
joinColumns = @JoinColumn(name="role_id"),
......
......@@ -37,4 +37,8 @@ public interface RoleService extends BaseService<RoleEntity, Long> {
List<RoleEntity> findByGroups(Set<GroupEntity> groups);
List<UserEntity> findUsersForRole(RoleEntity role);
List<GroupEntity> findGroupsForRole(RoleEntity role);
}
......@@ -71,6 +71,16 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleEntity, Long> implement
return dao.findWithUsers(id);
}
@Override
public List<UserEntity> findUsersForRole(RoleEntity role) {
return dao.findUsersForRole(role);
}
@Override
public List<GroupEntity> findGroupsForRole(RoleEntity role) {
return dao.findGroupsForRole(role);
}
@Override
public RoleEntity findByName(String name) {
return dao.findByName(name);
......
......@@ -11,17 +11,25 @@
package edu.kit.scc.webreg.bean.admin.role;
import java.io.Serializable;
import java.util.List;
import javax.enterprise.context.RequestScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ComponentSystemEvent;
import javax.inject.Inject;
import javax.inject.Named;
import org.primefaces.model.LazyDataModel;
import edu.kit.scc.webreg.entity.GroupEntity;
import edu.kit.scc.webreg.entity.RoleEntity;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.model.GenericLazyDataModelImpl;
import edu.kit.scc.webreg.service.GroupService;
import edu.kit.scc.webreg.service.RoleService;
import edu.kit.scc.webreg.service.UserService;
@Named("showRoleBean")
@RequestScoped
@ManagedBean
@ViewScoped
public class ShowRoleBean implements Serializable {
private static final long serialVersionUID = 1L;
......@@ -29,12 +37,50 @@ public class ShowRoleBean implements Serializable {
@Inject
private RoleService service;
private RoleEntity entity;
@Inject
private UserService userService;
@Inject
private GroupService groupService;
private RoleEntity entity;
private List<UserEntity> userList;
private List<GroupEntity> groupList;
private LazyDataModel<UserEntity> allUserList;
private LazyDataModel<GroupEntity> allGroupList;
private Long id;
public void preRenderView(ComponentSystemEvent ev) {
entity = service.findWithUsers(id);
if (entity == null) {
entity = service.findById(id);
userList = service.findUsersForRole(entity);
groupList = service.findGroupsForRole(entity);
allUserList = new GenericLazyDataModelImpl<UserEntity, UserService, Long>(userService);
allGroupList = new GenericLazyDataModelImpl<GroupEntity, GroupService, Long>(groupService);
}
}
public void removeUserFromRole(UserEntity user) {
service.removeUserFromRole(user, entity.getName());
userList = service.findUsersForRole(entity);
}
public void removeGroupFromRole(GroupEntity group) {
//service.removeGroupFromRole(group, entity.getName());
groupList = service.findGroupsForRole(entity);
}
public void addUserToRole(UserEntity user) {
service.addUserToRole(user, entity.getName());
userList = service.findUsersForRole(entity);
}
public void addGroupToRole(GroupEntity group) {
//service.removeGroupFromRole(group, entity.getName());
groupList = service.findGroupsForRole(entity);
}
public RoleEntity getEntity() {
......@@ -52,4 +98,20 @@ public class ShowRoleBean implements Serializable {
public void setId(Long id) {
this.id = id;
}
public List<UserEntity> getUserList() {
return userList;
}
public List<GroupEntity> getGroupList() {
return groupList;
}
public LazyDataModel<UserEntity> getAllUserList() {
return allUserList;
}
public LazyDataModel<GroupEntity> getAllGroupList() {
return allGroupList;
}
}
......@@ -44,37 +44,137 @@
</p:panel>
</div>
<h3><h:outputText value="#{messages.users}" /></h3>
<p:dataTable id="userTable" var="ur" style="min-width: 500px;"
value="#{showRoleBean.entity.users.toArray()}">
<p:column>
<f:facet name="header">
<h:outputText value="#{messages.id}" />
</f:facet>
<h:outputText value="#{ur.user.id}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{messages.eppn}" />
</f:facet>
<h:outputText value="#{ur.user.eppn}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{messages.sur_name}" />
</f:facet>
<h:outputText value="#{ur.user.surName}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{messages.given_name}" />
</f:facet>
<h:outputText value="#{ur.user.givenName}" />
</p:column>
</p:dataTable>
<div class="panel">
<p:panel id="memberPanel" header="#{messages.members}">
<p:dataTable id="memberData" style="min-width: 500px;"
value="#{showRoleBean.userList}" var="user">
<p:column>
<f:facet name="header">
<h:outputText value="#{messages.id}" />
</f:facet>
<h:outputText value="#{user.id}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{messages.eppn}" />
</f:facet>
<h:link outcome="/admin/user/show-user.xhtml" value="#{user.eppn}">
<f:param name="id" value="#{user.id}"/>
</h:link>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{messages.sur_name}" />
</f:facet>
<h:outputText value="#{user.surName}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{messages.given_name}" />
</f:facet>
<h:outputText value="#{user.givenName}" />
</p:column>
<p:column>
<p:commandLink action="#{showRoleBean.removeUserFromRole(user)}" value="#{messages.remove}"
update="@form"/>
</p:column>
</p:dataTable>
</p:panel>
<br/>
<br/>
<p:panel id="groupMemberPanel" header="#{messages.groups}">
<p:dataTable id="groupMemberData" style="min-width: 500px;"
value="#{showRoleBean.groupList}" var="group">
<p:column>
<f:facet name="header">
<h:outputText value="#{messages.id}" />
</f:facet>
<h:outputText value="#{group.id}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{messages.name}" />
</f:facet>
<h:outputText value="#{group.name}" />
</p:column>
<p:column>
<p:commandLink action="#{showRoleBean.removeGroupFromRole(group)}" value="#{messages.remove}"
update="@form"/>
</p:column>
</p:dataTable>
<br/>
<br/>
<p:dataTable id="allUsersTable" var="user" value="#{showRoleBean.allUserList}" paginator="true"
lazy="true" rows="15">
<p:column sortBy="#{user.id}">
<f:facet name="header">
<h:outputText value="#{messages.id}" />
</f:facet>
<h:outputText value="#{user.id}" />
</p:column>
<p:column sortBy="#{user.surName}" filterBy="#{user.surName}">
<f:facet name="header">
<h:outputText value="#{messages.sur_name}" />
</f:facet>
<h:outputText value="#{user.surName}" />
</p:column>
<p:column sortBy="#{user.givenName}" filterBy="#{user.givenName}">
<f:facet name="header">
<h:outputText value="#{messages.given_name}" />
</f:facet>
<h:outputText value="#{user.givenName}" />
</p:column>
<p:column sortBy="#{user.eppn}" filterBy="#{user.eppn}">
<f:facet name="header">
<h:outputText value="#{messages.eppn}" />
</f:facet>
<h:link outcome="/admin/user/show-user.xhtml" value="#{user.eppn}">
<f:param name="id" value="#{user.id}"/>
</h:link>
</p:column>
<p:column sortBy="#{user.userStatus}">
<f:facet name="header">
<h:outputText value="#{messages.status}" />
</f:facet>
<h:outputText value="#{user.userStatus}" />
</p:column>
<p:column>
<p:commandLink action="#{showRoleBean.addUserToRole(user)}" value="#{messages.add}"
update="@form"/>
</p:column>
</p:dataTable>
<br/>
<br/>
<p:dataTable id="allGroupTable" var="group" value="#{showRoleBean.allGroupList}" paginator="true"
lazy="true" rows="15">
<p:column sortBy="#{user.id}">
<f:facet name="header">
<h:outputText value="#{messages.id}" />
</f:facet>
<h:outputText value="#{group.id}" />
</p:column>
<p:column sortBy="#{group.name}" filterBy="#{group.name}">
<f:facet name="header">
<h:outputText value="#{messages.name}" />
</f:facet>
<h:outputText value="#{group.name}" />
</p:column>
<p:column>
<p:commandLink action="#{showRoleBean.addGroupToRole(group)}" value="#{messages.add}"
update="@form"/>
</p:column>
</p:dataTable>
</p:panel>
</div>
</h:form>
</ui:define>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment