Commit 11b6c416 authored by michael.simon's avatar michael.simon
Browse files

Make approve user list pageble sortable and lazyloading. Add correct

authorazation to approvals
parent bce5610c
......@@ -10,24 +10,32 @@
******************************************************************************/
package edu.kit.scc.webreg.bean;
import java.util.List;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
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 edu.kit.scc.webreg.entity.RegistryEntity;
import edu.kit.scc.webreg.entity.RegistryStatus;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.exc.NotAuthorizedException;
import edu.kit.scc.webreg.model.GenericLazyDataModel;
import edu.kit.scc.webreg.model.GenericLazyDataModelImpl;
import edu.kit.scc.webreg.sec.AuthorizationBean;
import edu.kit.scc.webreg.service.RegistryService;
import edu.kit.scc.webreg.service.ServiceService;
@Named("approvalListBean")
@RequestScoped
public class ApprovalListBean {
@ManagedBean
@ViewScoped
public class ApprovalListBean implements Serializable {
private List<RegistryEntity> list;
private static final long serialVersionUID = 1L;
private GenericLazyDataModel<RegistryEntity, RegistryService, Long> list;
@Inject
private RegistryService service;
......@@ -35,27 +43,33 @@ public class ApprovalListBean {
@Inject
private ServiceService serviceService;
@Inject
private AuthorizationBean authBean;
private ServiceEntity serviceEntity;
private Long serviceId;
public void preRenderView(ComponentSystemEvent ev) {
serviceEntity = serviceService.findById(serviceId);
list = service.findByServiceAndStatus(serviceEntity, RegistryStatus.PENDING);
if (serviceEntity == null) {
if (authBean.isUserServiceApprover(serviceId)) {
serviceEntity = serviceService.findById(serviceId);
}
else
throw new NotAuthorizedException("Nicht autorisiert");
}
}
public List<RegistryEntity> getRoleEntityList() {
return list;
}
public List<RegistryEntity> getList() {
public GenericLazyDataModel<RegistryEntity, RegistryService, Long> getList() {
if (list == null) {
Map<String, Object> filterMap = new HashMap<String, Object>();
filterMap.put("service", serviceEntity);
filterMap.put("registryStatus", RegistryStatus.PENDING);
list = new GenericLazyDataModelImpl<RegistryEntity, RegistryService, Long>(service, filterMap);
}
return list;
}
public void setList(List<RegistryEntity> list) {
this.list = list;
}
public ServiceEntity getServiceEntity() {
return serviceEntity;
}
......
......@@ -25,6 +25,7 @@ import edu.kit.scc.webreg.entity.RegistryEntity;
import edu.kit.scc.webreg.exc.MisconfiguredServiceException;
import edu.kit.scc.webreg.exc.NotAuthorizedException;
import edu.kit.scc.webreg.exc.RegisterException;
import edu.kit.scc.webreg.sec.AuthorizationBean;
import edu.kit.scc.webreg.service.RegistryService;
import edu.kit.scc.webreg.util.SessionManager;
import edu.kit.scc.webreg.util.ViewIds;
......@@ -42,16 +43,24 @@ public class ApproveUserBean implements Serializable {
@Inject
private SessionManager sessionManager;
@Inject
private AuthorizationBean authBean;
private RegistryEntity entity;
private Long id;
public void preRenderView(ComponentSystemEvent ev) {
entity = service.findById(id);
if (entity == null) {
throw new NotAuthorizedException("Nicht autorisiert");
entity = service.findById(id);
if (entity == null) {
throw new NotAuthorizedException("Nicht autorisiert");
}
if (! authBean.isUserServiceApprover(entity.getService().getId()))
throw new NotAuthorizedException("Nicht autorisiert");
}
}
......
......@@ -183,6 +183,17 @@ public class AuthorizationBean implements Serializable {
return false;
}
public boolean isUserServiceApprover(Long id) {
if (id == null)
return false;
for (ServiceEntity service : getServiceApproverList()) {
if (id.equals(service.getId()))
return true;
}
return false;
}
public boolean isUserServiceHotline(Long id) {
if (id == null)
return false;
......
......@@ -22,52 +22,57 @@
<ui:param name="title" value="#{messages.title}"/>
<ui:define name="content">
<h:form id="form">
<div id="panelInline">
<p:panel header="#{messages.new_approvals}">
<p:dataTable id="registeredTable" var="registry"
value="#{approvalListBean.list}" style="width:auto;">
<p:column style="width: 48px;">
<f:facet name="header">
<h:outputText value="#{messages.id}" />
</f:facet>
<h:outputText value="#{registry.id}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{messages.eppn}" />
</f:facet>
<h:outputText value="#{registry.user.eppn}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{messages.sur_name}" />
</f:facet>
<h:outputText value="#{registry.user.surName}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{messages.given_name}" />
</f:facet>
<h:outputText value="#{registry.user.givenName}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{messages.registered_time}" />
</f:facet>
<h:outputText value="#{of:formatDate(registry.agreedTime, 'dd.MM.yyyy HH:mm')}" />
</p:column>
<p:column style="width: 48px;">
<f:facet name="header">
<h:outputText value="#{messages.action}" />
</f:facet>
<h:link outcome="approve-user.xhtml" value="#{messages.edit}" >
<f:param name="id" value="#{registry.id}"/>
</h:link>
</p:column>
</p:dataTable>
<p:dataTable id="registeredTable" var="registry"
value="#{approvalListBean.list}" style="width:auto;"
paginator="true" lazy="true" rows="15">
<p:column sortBy="#{registry.id}" style="width: 48px;">
<f:facet name="header">
<h:outputText value="#{messages.id}" />
</f:facet>
<h:outputText value="#{registry.id}" />
</p:column>
<p:column sortBy="#{registry.user.eppn}" filterBy="#{registry.user.eppn}">
<f:facet name="header">
<h:outputText value="#{messages.eppn}" />
</f:facet>
<h:outputText value="#{registry.user.eppn}" />
</p:column>
<p:column sortBy="#{registry.user.surName}" filterBy="#{registry.user.surName}">
<f:facet name="header">
<h:outputText value="#{messages.sur_name}" />
</f:facet>
<h:outputText value="#{registry.user.surName}" />
</p:column>
<p:column sortBy="#{registry.user.givenName}" filterBy="#{registry.user.givenName}">
<f:facet name="header">
<h:outputText value="#{messages.given_name}" />
</f:facet>
<h:outputText value="#{registry.user.givenName}" />
</p:column>
<p:column sortBy="#{registry.agreedTime}">
<f:facet name="header">
<h:outputText value="#{messages.registered_time}" />
</f:facet>
<h:outputText value="#{of:formatDate(registry.agreedTime, 'dd.MM.yyyy HH:mm')}" />
</p:column>
<p:column style="width: 48px;">
<f:facet name="header">
<h:outputText value="#{messages.action}" />
</f:facet>
<h:link outcome="approve-user.xhtml" value="#{messages.edit}" >
<f:param name="id" value="#{registry.id}"/>
</h:link>
</p:column>
</p:dataTable>
</p:panel>
</div>
</p:panel>
</div>
</h:form>
</ui:define>
</ui:composition>
</f:view>
......
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