Skip to content

Commit

Permalink
Add confirm dialog to remove projects from user before removing client
Browse files Browse the repository at this point in the history
  • Loading branch information
solth committed Nov 7, 2024
1 parent d074f61 commit 78b7336
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import javax.inject.Named;

import org.kitodo.data.database.beans.Client;
import org.kitodo.data.database.beans.Project;
import org.kitodo.data.database.beans.User;
import org.kitodo.production.services.ServiceManager;
import org.primefaces.PrimeFaces;

Expand Down Expand Up @@ -146,20 +144,12 @@ public String setSessionClient(Client sessionClient) {
}

/**
* Gets all clients to which the user directly assigned and also those from user
* assigned projects.
* Gets all clients to which the user directly assigned.
*
* @return The list of clients.
*/
public List<Client> getAvailableClientsOfCurrentUser() {
User currentUser = ServiceManager.getUserService().getCurrentUser();
List<Client> clients = currentUser.getClients();
for (Project project : currentUser.getProjects()) {
if (!clients.contains(project.getClient())) {
clients.add(project.getClient());
}
}
return clients;
return ServiceManager.getUserService().getCurrentUser().getClients();
}

/**
Expand Down
82 changes: 69 additions & 13 deletions Kitodo/src/main/java/org/kitodo/production/forms/UserForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public class UserForm extends BaseForm {

private String oldPassword;
private SortedMap<String, String> shortcuts;
private Integer removeClientId = null;

@Named("LoginForm")
private final LoginForm loginForm;
Expand Down Expand Up @@ -351,28 +352,66 @@ public String addToRole() {
return this.stayOnCurrentPage;
}

/**
* Check whether User 'userObject' is currently assigned to any projects associated with the client
* identified by given ID 'clientId'. If true, the user is prompted to confirm his removal from those projects
* before removing the client from the user. If false, the client is remove from the user directly.
*
* @param clientId ID of client that is remove from the user
*/
public void checkClientProjects(Integer clientId) {
List<Project> assignedClientProjects = this.userObject.getProjects().stream()
.filter(p -> p.getClient().getId().equals(clientId)).collect(Collectors.toList());
removeClientId = clientId;
if (assignedClientProjects.isEmpty()) {
deleteFromClient();
} else {
PrimeFaces.current().ajax().update("removeClientDialog");
PrimeFaces.current().executeScript("PF('removeClientDialog').show();");
}
}

/**
* Remove all projects from User 'userObject' that are associated with the client identified by ID
* 'removeClientId'.
*/
public void removeUserFromClientProjects() {
if (Objects.nonNull(this.removeClientId)) {
this.userObject.getProjects().removeAll(this.userObject.getProjects().stream()
.filter(p -> p.getClient().getId().equals(this.removeClientId)).collect(Collectors.toList()));
}
}

/**
* Return list of project titles that are associated with the client with ID 'removeClientId' and
* assigned to User 'userObject'.
* @return list of process titles
*/
public List<String> getClientProjects() {
if (Objects.nonNull(this.removeClientId)) {
return this.userObject.getProjects().stream()
.filter(project -> project.getClient().getId().equals(this.removeClientId))
.map(Project::getTitle).collect(Collectors.toList());
} else {
return Collections.emptyList();
}
}

/**
* Remove user from client.
*
* @return empty String
*/
public String deleteFromClient() {
String idParameter = Helper.getRequestParameter(ID_PARAMETER);
if (Objects.nonNull(idParameter)) {
try {
int clientId = Integer.parseInt(idParameter);
for (Client client : this.userObject.getClients()) {
if (client.getId().equals(clientId)) {
this.userObject.getClients().remove(client);
break;
}
if (Objects.nonNull(this.removeClientId)) {
for (Client client : this.userObject.getClients()) {
if (client.getId().equals(this.removeClientId)) {
this.userObject.getClients().remove(client);
break;
}
} catch (NumberFormatException e) {
Helper.setErrorMessage(e.getLocalizedMessage(), logger, e);
}
} else {
Helper.setErrorMessage(ERROR_PARAMETER_MISSING, new Object[] {ID_PARAMETER});
}
this.removeClientId = null;
return this.stayOnCurrentPage;
}

Expand Down Expand Up @@ -778,4 +817,21 @@ public String getGalleryViewModeTranslation(String galleryViewModeValue) {
public FilterMenu getFilterMenu() {
return filterMenu;
}

/**
* Get 'removeClientId'. ID of the client that is to be removed from User 'userObject'.
*
* @return removeClientId
*/
public Integer getRemoveClientId() {
return removeClientId;
}

/**
* Set 'removeClientId'.
* @param clientId ID of the client that is to be removed from User 'userObject'.
*/
public void setRemoveClientId(Integer clientId) {
this.removeClientId = clientId;
}
}
5 changes: 4 additions & 1 deletion Kitodo/src/main/resources/messages/messages_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ configurationChanged=Einstellungen ge\u00E4ndert
configurationFile=Konfigurationsdatei
configurationOPAC=OPAC Konfiguration
configurationSaving=Konfiguration wird gespeichert...
confirm=Diese Aktion kann einige Zeit dauern. Sind Sie sicher, dass Sie fortfahren m\u00F6chten?
confirm=Best\u00E4tigen
confirmArchive=Archivieren best\u00E4tigen
confirmArchiveWorkflow=Workflow archivieren?
confirmClose=Schlie\u00DFen best\u00E4tigen
Expand All @@ -221,6 +221,7 @@ confirmDeleteUserWithTasks=Wenn Sie diesen Benutzer "{0}" l\u00F6schen, werden a
confirmDeleteRole=Rolle "{0}" l\u00F6schen?
confirmDeleteWorkflow=Workflow "{0}" l\u00F6schen?
confirmUpdateWorkflow=\u00C4nderungen am Workflow l\u00F6schen existierende Layout-Einstellungen im Metadateneditor. Trotzdem fortfahren?
confirmLongRunningTask=Diese Aktion kann einige Zeit dauern. Sind Sie sicher, dass Sie fortfahren m\u00F6chten?
confirmNewPassword=Neues Passwort best\u00E4tigen
confirmRelease=Abgeben best\u00E4tigen
confirmUnassignTasks=Alle Aufgaben in Bearbeitung, die zu diesem Benutzer zugeordnet sind, werden auf 'Offen' gesetzt.
Expand Down Expand Up @@ -983,6 +984,8 @@ relativeAmount=Relative Anzahl
reload=Aktualisieren
remark=Bemerkung
removeAllTasks=Alle Aufgaben l\u00F6schen
removeClientProjectsFromUser=Mandantenprojekte von Benutzer entfernen
removeClientProjectsFromUserConfirmMessage=Diesem Benutzer sind die folgenden Projekte des ausgew\u00E4hlten Mandanten zugewiesen. Diese Projekte werden vom Benutzer entfernt. M\u00F6chten Sie fortfahren?
removeClosedTasks=Abgeschlossene Aufgaben l\u00F6schen
removeElement=Element entfernen
removeFilter=Filter entfernen
Expand Down
5 changes: 4 additions & 1 deletion Kitodo/src/main/resources/messages/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ configurationChanged=Configuration changed
configurationFile=Configuration file
configurationOPAC=OPAC configuration
configurationSaving=Saving configuration...
confirm=This operation may take some time. Are you sure you want to continue?
confirm=Confirm
confirmArchive=Confirm archive
confirmArchiveWorkflow=Archive workflow?
confirmClose=Confirm close
Expand All @@ -221,6 +221,7 @@ confirmDeleteUserWithTasks=If you delete this user "{0}", all tasks assigned to
confirmDeleteRole=Delete role "{0}"?
confirmDeleteWorkflow=Delete workflow "{0}"?
confirmUpdateWorkflow=Changes to the workflow will delete existing metadata editor layout settings. Continue?
confirmLongRunningTask=This operation may take some time. Are you sure you want to continue?
confirmNewPassword=Confirm new password
confirmRelease=Confirm release
confirmUnassignTasks=All tasks in progress that are assigned to this user will be set again to 'Open'.
Expand Down Expand Up @@ -983,6 +984,8 @@ relativeAmount=Relative amount
reload=reload
remark=Remark
removeAllTasks=Remove all tasks
removeClientProjectsFromUser=Remove client projects from user
removeClientProjectsFromUserConfirmMessage=The following projects of the selected client are assigned to this user. These projects will be removed from the user. Do you want to continue?
removeClosedTasks=Remove finished tasks
removeElement=Remove element
removeFilter=Remove filter from list
Expand Down
29 changes: 29 additions & 0 deletions Kitodo/src/main/webapp/WEB-INF/resources/css/kitodo.css
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,35 @@ main i.fa {
width: calc(100% - 48px);
}

#titleProcess {
flex-grow: 1;
flex-shrink: 1;
}

#titleProcess > .ui-panel-content {
display: flex;
}

#titleProcess h3 {
display: inline-block;
flex-grow: 0;
}

#titleProcess h5 {
display: inline-block;
}

.client-projects {
border: 1px solid var(--blue);
border-radius: 3px;
max-height: 100px;
overflow-y: auto;
}

.client-projects thead {
display: none;
}

/*----------------------------------------------------------------------
Statistics
----------------------------------------------------------------------*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<h:form>
<h:panelGroup styleClass="ui-confirm-dialog-message"
style="display: block; margin-left: -6px; margin-top: -16px;">
<h:outputText value="#{msgs.confirm}"/>
<h:outputText value="#{msgs.confirmLongRunningTask}"/>
</h:panelGroup>
<p:commandButton
id="yesButton"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
-->

<ui:composition
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
Expand All @@ -27,15 +26,14 @@
</p:column>
<p:column styleClass="actionsColumn" headerText="#{msgs.actions}">
<p:commandLink id="deleteFromClient"
action="#{UserForm.deleteFromClient}"
action="#{UserForm.checkClientProjects(client.id)}"
styleClass="action"
title="#{msgs.clientDeleteFrom}"
rendered="#{isEditMode || isCreateMode}"
immediate="true"
oncomplete="toggleSave()"
update="@form">
<i class="fa fa-trash-o fa-lg"/>
<f:param name="ID" value="#{client.id}"/>
</p:commandLink>
</p:column>
</p:dataTable>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<!--
*
* (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.
*
-->

<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui">
<p:dialog class="remove-client-dialog"
id="removeClientDialog"
widgetVar="removeClientDialog"
showHeader="false"
modal="true"
width="500px"
appendTo="@(body)"
resizable="false"
closable="false">
<h3>#{msgs.removeClientProjectsFromUser}</h3>
<h:form id="removeFromProjectsForm">
<div class="select-note ui-messages-info">#{msgs.removeClientProjectsFromUserConfirmMessage}</div>
<div class="select-selector">
<p>
<p:dataTable styleClass="client-projects"
value="#{UserForm.clientProjects}"
var="project">
<p:column id="projectTitle">
<h:outputText value="#{project}"
title="#{project}"/>
</p:column>
</p:dataTable>
</p>
<p:panelGrid>
<p:row>
<p:commandButton id="confirm"
actionListener="#{UserForm.removeUserFromClientProjects()}"
action="#{UserForm.deleteFromClient()}"
onstart="PF('removeClientDialog').hide(); $('#loadingScreen').show();"
oncomplete="$('#loadingScreen').hide();"
update="@all"
styleClass="primary right"
value="#{msgs.confirm}"
icon="fa fa-check"
iconPos="right"/>
<p:commandButton onclick="PF('removeClientDialog').hide();"
id="cancelButton"
type="button"
value="#{msgs.cancel}"
styleClass="secondary right"
icon="fa fa-close"
iconPos="right">
<f:setPropertyActionListener target="#{UserForm.removeClientId}" value="#{null}"/>
</p:commandButton>
</p:row>
</p:panelGrid>
</div>
</h:form>
</p:dialog>
</ui:composition>
1 change: 1 addition & 0 deletions Kitodo/src/main/webapp/pages/userEdit.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
<ui:include src="/WEB-INF/templates/includes/userEdit/changePasswordPopup.xhtml"/>
<ui:include src="/WEB-INF/templates/includes/userEdit/resetPasswordPopup.xhtml"/>
<ui:include src="/WEB-INF/templates/includes/userEdit/changeShortcutsPopup.xhtml"/>
<ui:include src="/WEB-INF/templates/includes/userEdit/removeClientFromUserDialog.xhtml"/>
</ui:define>

<ui:define name="page-scripts">
Expand Down

0 comments on commit 78b7336

Please sign in to comment.