Fix sharing of man on new collabs.

This commit is contained in:
Paulo Gustavo Veiga 2022-02-16 18:29:28 -08:00
parent 63cfe44d50
commit 1f99ce3889

View File

@ -105,19 +105,20 @@ public class UserManagerImpl
public User createUser(@NotNull User user, @NotNull Collaborator collaborator) { 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";
getHibernateTemplate().saveOrUpdate(user);
// Migrate from previous temporal collab to new user ...
final Set<Collaboration> collaborations = collaborator.getCollaborations(); final Set<Collaboration> collaborations = collaborator.getCollaborations();
for (Collaboration collaboration : collaborations) { for (Collaboration oldCollab : collaborations) {
// Move maps to the new ... Collaboration newCollab = new Collaboration();
Collaboration newMapUser = new Collaboration(); newCollab.setRoleId(oldCollab.getRole().ordinal());
newMapUser.setRoleId(collaboration.getRole().ordinal()); newCollab.setMindMap(oldCollab.getMindMap());
newMapUser.setMindMap(collaboration.getMindMap()); newCollab.setCollaborator(user);
newMapUser.setCollaborator(user); user.addCollaboration(newCollab);
user.addCollaboration(newMapUser); getHibernateTemplate().save(newCollab);
// Delete collaborations on this collaborator ... // Delete collaborations on this collaborator ...
getHibernateTemplate().delete(collaboration); getHibernateTemplate().delete(oldCollab);
getHibernateTemplate().flush();
} }
// Delete collaboration ... // Delete collaboration ...
@ -143,8 +144,7 @@ public class UserManagerImpl
// Does the password need to be encrypted ? // Does the password need to be encrypted ?
final String password = user.getPassword(); final String password = user.getPassword();
if(password!=null && (!password.startsWith(LegacyPasswordEncoder.ENC_PREFIX) && !password.startsWith( "{"+ DefaultPasswordEncoderFactories.ENCODING_ID))) if (password != null && (!password.startsWith(LegacyPasswordEncoder.ENC_PREFIX) && !password.startsWith("{" + DefaultPasswordEncoderFactories.ENCODING_ID))) {
{
user.setPassword(passwordEncoder.encode(user.getPassword())); user.setPassword(passwordEncoder.encode(user.getPassword()));
} }
@ -159,7 +159,7 @@ public class UserManagerImpl
query.setParameter("activationCode", code); query.setParameter("activationCode", code);
final List users = query.list(); final List users = query.list();
if(users != null && !users.isEmpty()) { if (users != null && !users.isEmpty()) {
assert users.size() == 1 : "More than one user with the same username!"; assert users.size() == 1 : "More than one user with the same username!";
user = (User) users.get(0); user = (User) users.get(0);