From 10bcab488a0ffadb51ff92702641c3b4a2fb8cad Mon Sep 17 00:00:00 2001 From: Arved Solth Date: Tue, 12 Nov 2024 10:31:16 +0100 Subject: [PATCH] Add switch to show roles of all clients available to current user --- .../org/kitodo/production/forms/RoleForm.java | 13 +- .../production/model/LazyRoleModel.java | 56 ++++++++ .../production/services/data/RoleService.java | 10 ++ .../resources/messages/messages_de.properties | 1 + .../resources/messages/messages_en.properties | 1 + .../resources/messages/messages_es.properties | 1 + .../templates/includes/users/roleList.xhtml | 131 +++++++++--------- Kitodo/src/main/webapp/pages/users.xhtml | 12 ++ 8 files changed, 159 insertions(+), 66 deletions(-) create mode 100644 Kitodo/src/main/java/org/kitodo/production/model/LazyRoleModel.java diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/RoleForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/RoleForm.java index bc4eaaa5e38..4d8ca4eb914 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/RoleForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/RoleForm.java @@ -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; @@ -47,7 +47,7 @@ public class RoleForm extends BaseForm { */ public RoleForm() { super(); - super.setLazyDTOModel(new LazyDTOModel(ServiceManager.getRoleService())); + super.setLazyDTOModel(new LazyRoleModel(ServiceManager.getRoleService())); } /** @@ -235,6 +235,15 @@ public void setClientAssignableAuthorities(DualListModel 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 authoritiesModel) { for (Authority authority : authoritiesModel.getSource()) { this.role.getAuthorities().remove(authority); diff --git a/Kitodo/src/main/java/org/kitodo/production/model/LazyRoleModel.java b/Kitodo/src/main/java/org/kitodo/production/model/LazyRoleModel.java new file mode 100644 index 00000000000..16d6946836a --- /dev/null +++ b/Kitodo/src/main/java/org/kitodo/production/model/LazyRoleModel.java @@ -0,0 +1,56 @@ +/* + * (c) Kitodo. Key to digital objects e. V. + * + * 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 load(int first, int pageSize, String sortField, SortOrder sortOrder, Map filters) { + try { + Map 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(); + } +} diff --git a/Kitodo/src/main/java/org/kitodo/production/services/data/RoleService.java b/Kitodo/src/main/java/org/kitodo/production/services/data/RoleService.java index 8a4ea8cc679..cb796e90841 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/data/RoleService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/data/RoleService.java @@ -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())); @@ -83,7 +87,13 @@ public List getAllForSelectedClient() { } @Override + @SuppressWarnings("unchecked") public List 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), diff --git a/Kitodo/src/main/resources/messages/messages_de.properties b/Kitodo/src/main/resources/messages/messages_de.properties index e63c9f3794e..aff6e301ea6 100644 --- a/Kitodo/src/main/resources/messages/messages_de.properties +++ b/Kitodo/src/main/resources/messages/messages_de.properties @@ -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? diff --git a/Kitodo/src/main/resources/messages/messages_en.properties b/Kitodo/src/main/resources/messages/messages_en.properties index 9f50b60b7b2..887736c86c3 100644 --- a/Kitodo/src/main/resources/messages/messages_en.properties +++ b/Kitodo/src/main/resources/messages/messages_en.properties @@ -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? diff --git a/Kitodo/src/main/resources/messages/messages_es.properties b/Kitodo/src/main/resources/messages/messages_es.properties index 3ae2d9de152..48258dce109 100644 --- a/Kitodo/src/main/resources/messages/messages_es.properties +++ b/Kitodo/src/main/resources/messages/messages_es.properties @@ -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? diff --git a/Kitodo/src/main/webapp/WEB-INF/templates/includes/users/roleList.xhtml b/Kitodo/src/main/webapp/WEB-INF/templates/includes/users/roleList.xhtml index 495972aeff5..4b4cb68f2c0 100644 --- a/Kitodo/src/main/webapp/WEB-INF/templates/includes/users/roleList.xhtml +++ b/Kitodo/src/main/webapp/WEB-INF/templates/includes/users/roleList.xhtml @@ -17,70 +17,73 @@ xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:p="http://primefaces.org/ui"> - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - + + + + - - - - - - - - + + + + + + + + + diff --git a/Kitodo/src/main/webapp/pages/users.xhtml b/Kitodo/src/main/webapp/pages/users.xhtml index ed4c41dca44..50f3220b1eb 100644 --- a/Kitodo/src/main/webapp/pages/users.xhtml +++ b/Kitodo/src/main/webapp/pages/users.xhtml @@ -38,6 +38,18 @@ + + + + + + + +