Skip to content

Commit 6fba8da

Browse files
authored
Correctly sync available projects, roles and clients on add and delete (#6981)
* Correctly sync available projects on add and delete * Also fix user-roles * Also fix user-clients * Add Sort
1 parent 66cfaac commit 6fba8da

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

Kitodo/src/main/java/org/kitodo/production/forms/user/UserEditViewClientsTab.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ public String deleteFromClient() {
107107
for (Client client : this.userObject.getClients()) {
108108
if (client.getId().equals(clientId)) {
109109
this.userObject.getClients().remove(client);
110+
if (Objects.nonNull(this.clients) && !this.clients.contains(client)) {
111+
this.clients.add(client);
112+
this.clients.sort(Comparator.comparing(Client::getName, String.CASE_INSENSITIVE_ORDER));
113+
}
110114
if (client.equals(this.userObject.getDefaultClient())) {
111115
this.userObject.setDefaultClient(null);
112116
}
@@ -137,6 +141,9 @@ public String addToClient() {
137141

138142
if (!this.userObject.getClients().contains(client)) {
139143
this.userObject.getClients().add(client);
144+
if (Objects.nonNull(this.clients)) {
145+
this.clients.remove(client);
146+
}
140147
}
141148
} catch (DAOException e) {
142149
Helper.setErrorMessage(ERROR_DATABASE_READING,

Kitodo/src/main/java/org/kitodo/production/forms/user/UserEditViewProjectsTab.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.logging.log4j.LogManager;
2525
import org.apache.logging.log4j.Logger;
2626
import org.kitodo.data.database.beans.Project;
27+
import org.kitodo.data.database.beans.Role;
2728
import org.kitodo.data.database.beans.User;
2829
import org.kitodo.data.database.exceptions.DAOException;
2930
import org.kitodo.production.enums.ObjectType;
@@ -105,6 +106,10 @@ public String deleteFromProject() {
105106
for (Project project : this.userObject.getProjects()) {
106107
if (project.getId().equals(projectId)) {
107108
this.userObject.getProjects().remove(project);
109+
if (Objects.nonNull(this.projects) && !this.projects.contains(project)) {
110+
this.projects.add(project);
111+
this.projects.sort(Comparator.comparing(Project::getTitle, String.CASE_INSENSITIVE_ORDER));
112+
}
108113
break;
109114
}
110115
}
@@ -132,6 +137,9 @@ public String addToProject() {
132137

133138
if (!this.userObject.getProjects().contains(project)) {
134139
this.userObject.getProjects().add(project);
140+
if (Objects.nonNull(this.projects)) {
141+
this.projects.remove(project);
142+
}
135143
}
136144
} catch (DAOException e) {
137145
Helper.setErrorMessage(ERROR_DATABASE_READING,

Kitodo/src/main/java/org/kitodo/production/forms/user/UserEditViewRolesTab.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import org.apache.logging.log4j.LogManager;
2525
import org.apache.logging.log4j.Logger;
26+
import org.kitodo.data.database.beans.Client;
2627
import org.kitodo.data.database.beans.Role;
2728
import org.kitodo.data.database.beans.User;
2829
import org.kitodo.data.database.exceptions.DAOException;
@@ -104,6 +105,10 @@ public String deleteFromRole() {
104105
for (Role role : this.userObject.getRoles()) {
105106
if (role.getId().equals(roleId)) {
106107
this.userObject.getRoles().remove(role);
108+
if (Objects.nonNull(this.availableRoles) && !this.availableRoles.contains(role)) {
109+
this.availableRoles.add(role);
110+
this.availableRoles.sort(Comparator.comparing(Role::getTitle, String.CASE_INSENSITIVE_ORDER));
111+
}
107112
break;
108113
}
109114
}
@@ -131,6 +136,9 @@ public String addToRole() {
131136

132137
if (!this.userObject.getRoles().contains(role)) {
133138
this.userObject.getRoles().add(role);
139+
if (Objects.nonNull(this.availableRoles)) {
140+
this.availableRoles.remove(role);
141+
}
134142
}
135143
} catch (DAOException e) {
136144
Helper.setErrorMessage(ERROR_DATABASE_READING,

0 commit comments

Comments
 (0)