Remove orphan collabs on registration

This commit is contained in:
Paulo Gustavo Veiga 2022-02-16 18:05:26 -08:00
parent 07ad57e3b4
commit 63cfe44d50
4 changed files with 15 additions and 10 deletions

View File

@ -102,22 +102,29 @@ public class UserManagerImpl
}
@Override
public User createUser(@NotNull User user, @NotNull Collaborator col) {
public User createUser(@NotNull User user, @NotNull Collaborator collaborator) {
user.setPassword(passwordEncoder.encode(user.getPassword()));
assert user != null : "Trying to store a null user";
final Set<Collaboration> set = col.getCollaborations();
for (Collaboration collaboration : set) {
final Set<Collaboration> collaborations = collaborator.getCollaborations();
for (Collaboration collaboration : collaborations) {
// Move maps to the new ...
Collaboration newMapUser = new Collaboration();
newMapUser.setRoleId(collaboration.getRole().ordinal());
newMapUser.setMindMap(collaboration.getMindMap());
newMapUser.setCollaborator(user);
user.addCollaboration(newMapUser);
// Delete collaborations on this collaborator ...
getHibernateTemplate().delete(collaboration);
getHibernateTemplate().flush();
}
getHibernateTemplate().delete(col);
// Delete collaboration ...
getHibernateTemplate().delete(collaborator);
getHibernateTemplate().flush();
getHibernateTemplate().saveOrUpdate(user);
return user;
}

View File

@ -19,6 +19,9 @@
package com.wisemapping.model;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
@ -46,7 +49,6 @@ public class Collaboration implements Serializable {
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "properties_id", nullable = false, unique = true)
private CollaborationProperties collaborationProperties = new CollaborationProperties();
;
public Collaboration() {
}

View File

@ -55,8 +55,6 @@ public class AccountController extends BaseController {
@Autowired
private NotificationService notificationService;
final Logger logger = Logger.getLogger(AccountController.class);
@RequestMapping(method = RequestMethod.PUT, value = "account/password", consumes = {"text/plain"})
@ResponseStatus(value = HttpStatus.NO_CONTENT)

View File

@ -119,13 +119,11 @@ public class UserServiceImpl
if (emailConfirmEnabled) {
user.setActivationDate(null);
} else {
user.setActivationDate(Calendar.getInstance());
}
Collaborator col = userManager.getCollaboratorBy(user.getEmail());
final Collaborator col = userManager.getCollaboratorBy(user.getEmail());
if (col != null) {
userManager.createUser(user, col);
} else {