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 @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())); user.setPassword(passwordEncoder.encode(user.getPassword()));
assert user != null : "Trying to store a null user"; assert user != null : "Trying to store a null user";
final Set<Collaboration> set = col.getCollaborations(); final Set<Collaboration> collaborations = collaborator.getCollaborations();
for (Collaboration collaboration : set) { for (Collaboration collaboration : collaborations) {
// Move maps to the new ...
Collaboration newMapUser = new Collaboration(); Collaboration newMapUser = new Collaboration();
newMapUser.setRoleId(collaboration.getRole().ordinal()); newMapUser.setRoleId(collaboration.getRole().ordinal());
newMapUser.setMindMap(collaboration.getMindMap()); newMapUser.setMindMap(collaboration.getMindMap());
newMapUser.setCollaborator(user); newMapUser.setCollaborator(user);
user.addCollaboration(newMapUser); user.addCollaboration(newMapUser);
// Delete collaborations on this collaborator ...
getHibernateTemplate().delete(collaboration);
getHibernateTemplate().flush();
} }
getHibernateTemplate().delete(col); // Delete collaboration ...
getHibernateTemplate().delete(collaborator);
getHibernateTemplate().flush(); getHibernateTemplate().flush();
getHibernateTemplate().saveOrUpdate(user); getHibernateTemplate().saveOrUpdate(user);
return user; return user;
} }

View File

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

View File

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

View File

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