Skip to content

Commit

Permalink
Add switch to show roles of all clients available to current user
Browse files Browse the repository at this point in the history
  • Loading branch information
solth committed Nov 12, 2024
1 parent ef0d905 commit 10bcab4
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 66 deletions.
13 changes: 11 additions & 2 deletions Kitodo/src/main/java/org/kitodo/production/forms/RoleForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.kitodo.data.database.exceptions.DAOException;
import org.kitodo.production.enums.ObjectType;
import org.kitodo.production.helper.Helper;
import org.kitodo.production.model.LazyDTOModel;
import org.kitodo.production.model.LazyRoleModel;
import org.kitodo.production.services.ServiceManager;
import org.primefaces.model.DualListModel;

Expand All @@ -47,7 +47,7 @@ public class RoleForm extends BaseForm {
*/
public RoleForm() {
super();
super.setLazyDTOModel(new LazyDTOModel(ServiceManager.getRoleService()));
super.setLazyDTOModel(new LazyRoleModel(ServiceManager.getRoleService()));
}

/**
Expand Down Expand Up @@ -235,6 +235,15 @@ public void setClientAssignableAuthorities(DualListModel<Authority> clientAuthor
setAssignableAuthorities(clientAuthoritiesModel);
}

public boolean isShowRolesOfAllAvailableClients() {
return ((LazyRoleModel)this.lazyDTOModel).isShowRolesOfAllAvailableClients();
}

public void setShowRolesOfAllAvailableClients(boolean showRolesOfAllAvailableClients) {
// FIXME: after passing "true" for the first time, subsequent "false" parameters do not update the list again!
((LazyRoleModel)this.lazyDTOModel).setShowRolesOfAllAvailableClients(showRolesOfAllAvailableClients);
}

private void setAssignableAuthorities(DualListModel<Authority> authoritiesModel) {
for (Authority authority : authoritiesModel.getSource()) {
this.role.getAuthorities().remove(authority);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* (c) Kitodo. Key to digital objects e. V. <[email protected]>
*
* This file is part of the Kitodo project.
*
* It is licensed under GNU General Public License version 3 or later.
*
* For the full copyright and license information, please read the
* GPL3-License.txt file that was distributed with this source code.
*/

package org.kitodo.production.model;

import static java.lang.Math.toIntExact;

import org.kitodo.data.database.exceptions.DAOException;
import org.kitodo.production.services.data.RoleService;
import org.primefaces.model.FilterMeta;
import org.primefaces.model.SortOrder;

import java.util.Collections;
import java.util.List;
import java.util.Map;

public class LazyRoleModel extends LazyDTOModel {

private boolean showRolesOfAllAvailableClients = false;

public LazyRoleModel(RoleService roleService) {
super(roleService);
}

public boolean isShowRolesOfAllAvailableClients() {
return showRolesOfAllAvailableClients;
}

public void setShowRolesOfAllAvailableClients(boolean showRolesOfAllAvailableClients) {
this.showRolesOfAllAvailableClients = showRolesOfAllAvailableClients;
}

@Override
@SuppressWarnings("unchecked")
public List<Object> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,
FilterMeta> filters) {
try {
Map<String, Boolean> filterMap = Collections.singletonMap("allClients", showRolesOfAllAvailableClients);
setRowCount(toIntExact(((RoleService) searchService).countResults(filterMap)));
entities = ((RoleService) searchService).loadData(first, pageSize, sortField, sortOrder, filterMap);
return entities;
} catch (DAOException e) {
setRowCount(0);
logger.error(e.getMessage(), e);
}
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public Long countDatabaseRows() throws DAOException {

@Override
public Long countResults(Map filters) throws DAOException {
if (((Boolean)filters.get("allClients"))
&& ServiceManager.getSecurityAccessService().hasAuthorityGlobalToViewRoleList()) {
return countDatabaseRows();
}
if (ServiceManager.getSecurityAccessService().hasAuthorityToViewRoleList()) {
return countDatabaseRows("SELECT COUNT(*) FROM Role AS r INNER JOIN r.client AS c WITH c.id = :clientId",
Collections.singletonMap(CLIENT_ID, ServiceManager.getUserService().getSessionClientId()));
Expand All @@ -83,7 +87,13 @@ public List<Role> getAllForSelectedClient() {
}

@Override
@SuppressWarnings("unchecked")
public List<Role> loadData(int first, int pageSize, String sortField, SortOrder sortOrder, Map filters) {
if (((Boolean)filters.get("allClients"))
&& ServiceManager.getSecurityAccessService().hasAuthorityGlobalToViewRoleList()) {
return dao.getByQuery("FROM Role" + getSort(sortField, sortOrder), Collections.emptyMap(), first,
pageSize);
}
if (ServiceManager.getSecurityAccessService().hasAuthorityToViewRoleList()) {
return dao.getByQuery("SELECT r FROM Role AS r INNER JOIN r.client AS c WITH c.id = :clientId"
+ getSort(sortField, sortOrder),
Expand Down
1 change: 1 addition & 0 deletions Kitodo/src/main/resources/messages/messages_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,7 @@ showInactiveProjects=Deaktivierte Projekte zeigen
showOnlyStructureElements=Zeige nur Strukturelemente
showProjectProcesses=Vorg\u00E4nge dieses Projektes anzeigen
showProjectTasks=Aktuelle Aufgaben dieses Projektes anzeigen
showRolesOfAllAvailableClients=Rollen aller ver\u00FCgbarer Mandanten anzeigen
signIn=Anmelden
# shouldContentBeRemoved is used in onclick
shouldContentBeRemoved=Soll der Inhalt wirklich gel\u00F6scht werden?
Expand Down
1 change: 1 addition & 0 deletions Kitodo/src/main/resources/messages/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,7 @@ showInactiveProjects=show deactivated projects
showOnlyStructureElements=Show only structure elements
showProjectProcesses=Show processes of this project
showProjectTasks=Show current tasks of this project
showRolesOfAllAvailableClients=Show roles of all available clients
signIn=Sign in
# shouldContentBeRemoved is used in onclick
shouldContentBeRemoved=Do you really want to delete the content?
Expand Down
1 change: 1 addition & 0 deletions Kitodo/src/main/resources/messages/messages_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,7 @@ showInactiveProjects=Mostrar proyectos desactivados
showOnlyStructureElements=Mostrar sólo los elementos de la estructura
showProjectProcesses=Mostrar los procesos de este proyecto
showProjectTasks=Mostrar las tareas actuales de este proyecto
showRolesOfAllAvailableClients=Mostrar roles de todos los clientes disponibles
signIn=Entrar en el sistema
# shouldContentBeRemoved is used in onclick
shouldContentBeRemoved=¿Realmente quieres borrar el contenido?
Expand Down
131 changes: 67 additions & 64 deletions Kitodo/src/main/webapp/WEB-INF/templates/includes/users/roleList.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -17,70 +17,73 @@
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui">
<!--@elvariable id="item" type="org.kitodo.production.dto.RoleDTO"-->
<p:dataTable var="item"
id="rolesTable"
styleClass="default-layout"
value="#{RoleForm.lazyDTOModel}"
first="#{RoleForm.firstRow}"
lazy="true"
paginator="true"
resizableColumns="true"
liveResize="true"
sortBy="#{item.title}"
rows="#{LoginForm.loggedUser.tableSize}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {JumpToPageInput} {NextPageLink} {LastPageLink}"
currentPageReportTemplate="#{msgs.currentPageReportTemplate}"
paginatorPosition="bottom">
<p:ajax event="page"
listener="#{RoleForm.onPageChange}"/>
<p:column headerText="#{msgs.role}"
sortBy="#{item.title}"
rendered="#{UserForm.showColumn('role.role')}">
<h:outputText value="#{item.title}"
title="#{item.title}"/>
</p:column>
<p:column headerText="#{msgs.client}"
sortBy="#{item.client.name}"
rendered="#{UserForm.showColumn('role.client')}">
<h:outputText value="#{item.client.name}"
title="#{item.client.name}"/>
</p:column>
<p:column headerText="#{msgs.actions}"
width="70"
resizable="false"
styleClass="actionsColumn">
<h:form id="actionForm">
<h:link id="viewRole"
outcome="roleEdit"
styleClass="action"
title="#{msgs.view}"
rendered="#{SecurityAccessController.hasAuthorityToViewRole() and not SecurityAccessController.hasAuthorityToEditRole()}">
<f:param name="id" value="#{item.id}" />
<i class="fa fa-eye fa-lg"/>
</h:link>
<h:form id="rolesTableForm">
<p:dataTable var="item"
id="rolesTable"
widgetVar="rolesTable"
styleClass="default-layout"
value="#{RoleForm.lazyDTOModel}"
first="#{RoleForm.firstRow}"
lazy="true"
paginator="true"
resizableColumns="true"
liveResize="true"
sortBy="#{item.title}"
rows="#{LoginForm.loggedUser.tableSize}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {JumpToPageInput} {NextPageLink} {LastPageLink}"
currentPageReportTemplate="#{msgs.currentPageReportTemplate}"
paginatorPosition="bottom">
<p:ajax event="page"
listener="#{RoleForm.onPageChange}"/>
<p:column headerText="#{msgs.role}"
sortBy="#{item.title}"
rendered="#{UserForm.showColumn('role.role')}">
<h:outputText value="#{item.title}"
title="#{item.title}"/>
</p:column>
<p:column headerText="#{msgs.client}"
sortBy="#{item.client.name}"
rendered="#{UserForm.showColumn('role.client')}">
<h:outputText value="#{item.client.name}"
title="#{item.client.name}"/>
</p:column>
<p:column headerText="#{msgs.actions}"
width="70"
resizable="false"
styleClass="actionsColumn">
<h:form id="actionForm">
<h:link id="viewRole"
outcome="roleEdit"
styleClass="action"
title="#{msgs.view}"
rendered="#{SecurityAccessController.hasAuthorityToViewRole() and not SecurityAccessController.hasAuthorityToEditRole()}">
<f:param name="id" value="#{item.id}" />
<i class="fa fa-eye fa-lg"/>
</h:link>

<h:link id="editRole"
outcome="roleEdit"
styleClass="action"
title="#{msgs.edit}"
rendered="#{SecurityAccessController.hasAuthorityToEditRole()}">
<f:param name="id" value="#{item.id}" />
<i class="fa fa-pencil-square-o fa-lg"/>
</h:link>
<h:link id="editRole"
outcome="roleEdit"
styleClass="action"
title="#{msgs.edit}"
rendered="#{SecurityAccessController.hasAuthorityToEditRole()}">
<f:param name="id" value="#{item.id}" />
<i class="fa fa-pencil-square-o fa-lg"/>
</h:link>

<p:commandLink id="deleteRole"
action="#{RoleForm.delete}"
styleClass="action"
title="#{msgs.delete}"
rendered="#{SecurityAccessController.hasAuthorityToDeleteRole()}"
update="usersTabView:rolesTable">
<h:outputText><i class="fa fa-trash-o"/></h:outputText>
<f:setPropertyActionListener value="#{item.id}" target="#{RoleForm.roleById}"/>
<p:confirm header="#{msgs.confirmDelete}"
message="#{RoleForm.formatString('confirmDeleteRole', item.title)}"
icon="ui-icon-alert"/>
</p:commandLink>
</h:form>
</p:column>
</p:dataTable>
<p:commandLink id="deleteRole"
action="#{RoleForm.delete}"
styleClass="action"
title="#{msgs.delete}"
rendered="#{SecurityAccessController.hasAuthorityToDeleteRole()}"
update="usersTabView:rolesTableForm:rolesTable">
<h:outputText><i class="fa fa-trash-o"/></h:outputText>
<f:setPropertyActionListener value="#{item.id}" target="#{RoleForm.roleById}"/>
<p:confirm header="#{msgs.confirmDelete}"
message="#{RoleForm.formatString('confirmDeleteRole', item.title)}"
icon="ui-icon-alert"/>
</p:commandLink>
</h:form>
</p:column>
</p:dataTable>
</h:form>
</ui:composition>
12 changes: 12 additions & 0 deletions Kitodo/src/main/webapp/pages/users.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@
<p:outputPanel rendered="#{UserForm.activeTabIndex eq 0}">
<ui:include src="/WEB-INF/templates/includes/users/filterMenu.xhtml"/>
</p:outputPanel>
<p:outputPanel rendered="#{UserForm.activeTabIndex eq 1 and UserForm.user.clients.size() gt 1}">
<!--<p:outputPanel>-->
<h:form id="allClientsRolesForm">
<p:selectBooleanCheckbox id="showAllClientsRoles"
value="#{RoleForm.showRolesOfAllAvailableClients}"
itemLabel="#{msgs.showRolesOfAllAvailableClients}"
styleClass="switch">
<p:ajax onstart="PF('rolesTable').getPaginator().setPage(0);"
update="filterMenuWrapper usersTabView:rolesTableForm:rolesTable"/>
</p:selectBooleanCheckbox>
</h:form>
</p:outputPanel>
</h:panelGroup>
<h:form id="configureColumnsForm"
rendered="#{SecurityAccessController.hasAuthorityToConfigureColumns()}">
Expand Down

0 comments on commit 10bcab4

Please sign in to comment.