Commit ba400709 authored by Matija Obreza's avatar Matija Obreza

Fix: deepLoad(user) must be called in getUserByEmail

- User missing ROLE_EVERYONE
parent 3ba95e70
...@@ -120,7 +120,7 @@ public class UserServiceImpl extends BasicUserServiceImpl<UserRole, User> implem ...@@ -120,7 +120,7 @@ public class UserServiceImpl extends BasicUserServiceImpl<UserRole, User> implem
user.setAccountType(accountType); user.setAccountType(accountType);
user.getRoles().add(UserRole.USER); user.getRoles().add(UserRole.USER);
super.setPassword(user, password); super.setPassword(user, password);
return userRepository.save(user); return deepLoad(userRepository.save(user));
} }
@Transactional @Transactional
...@@ -279,23 +279,13 @@ public class UserServiceImpl extends BasicUserServiceImpl<UserRole, User> implem ...@@ -279,23 +279,13 @@ public class UserServiceImpl extends BasicUserServiceImpl<UserRole, User> implem
@Override @Override
public User getUserByEmail(String email) { public User getUserByEmail(String email) {
final User user = userRepository.findByEmail(email); final User user = userRepository.findByEmail(email);
return deepLoad(user);
if (user != null) {
user.getRoles().size();
}
return user;
} }
@Override @Override
public User getUserByUuid(String uuid) { public User getUserByUuid(String uuid) {
final User user = userRepository.findByUuid(uuid); final User user = userRepository.findByUuid(uuid);
return deepLoad(user);
if (user != null) {
user.getRoles().size();
}
return user;
} }
@Override @Override
......
...@@ -67,6 +67,7 @@ public class UserServiceTest extends AbstractServicesTest { ...@@ -67,6 +67,7 @@ public class UserServiceTest extends AbstractServicesTest {
user = userService.createUser(email, fullName, initialPassword, AccountType.LOCAL); user = userService.createUser(email, fullName, initialPassword, AccountType.LOCAL);
assertEquals(user.getAccountType(), AccountType.LOCAL); assertEquals(user.getAccountType(), AccountType.LOCAL);
assertThat(user.getRoles(), containsInAnyOrder(UserRole.USER, UserRole.EVERYONE));
assertThat(passwordEncoder.matches(initialPassword, user.getPassword()), is(true)); assertThat(passwordEncoder.matches(initialPassword, user.getPassword()), is(true));
} }
...@@ -230,7 +231,7 @@ public class UserServiceTest extends AbstractServicesTest { ...@@ -230,7 +231,7 @@ public class UserServiceTest extends AbstractServicesTest {
@Test @Test
public void updateRolesTest() throws PasswordPolicyException { public void updateRolesTest() throws PasswordPolicyException {
assertThat(userService.getUserByEmail(email).getRoles(), hasSize(1)); assertThat(userService.getUserByEmail(email).getRoles(), hasSize(2));
Set<UserRole> selectedRoles = Sets.newHashSet(UserRole.ADMINISTRATOR); Set<UserRole> selectedRoles = Sets.newHashSet(UserRole.ADMINISTRATOR);
userService.setRoles(user, selectedRoles); userService.setRoles(user, selectedRoles);
assertThat(userService.getUserByEmail(email).getRoles(), hasSize(3)); assertThat(userService.getUserByEmail(email).getRoles(), hasSize(3));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment