diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/UserCommand.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/UserCommand.java index 9b7571e53..b7b1792bd 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/UserCommand.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/UserCommand.java @@ -100,7 +100,7 @@ public class UserCommand implements Serializable { } public boolean isPasswordChanged() { - return this.modifiedParameters.contains("password"); + return this.modifiedParameters.contains("password") && this.modifiedParameters.contains("repeatPassword"); } public boolean isOfficeChanged() { diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/AppUserData.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/AppUserData.java index ecbab89cf..c7f01513e 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/AppUserData.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/AppUserData.java @@ -6,9 +6,9 @@ import java.util.List; public class AppUserData { private Long id; + private String username; private Long officeId; private String officeName; - private String username; private String firstname; private String lastname; private String email; diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/user/service/AppUserWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/user/service/AppUserWritePlatformServiceJpaRepositoryImpl.java index fc755dec6..80125d276 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/user/service/AppUserWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/user/service/AppUserWritePlatformServiceJpaRepositoryImpl.java @@ -88,7 +88,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit return appUser.getId(); } catch (DataIntegrityViolationException dve) { - handleOfficeDataIntegrityIssues(command, dve); + handleAppUserDataIntegrityIssues(command, dve); return Long.valueOf(-1); } catch (PlatformEmailSendException e) { List dataValidationErrors = new ArrayList(); @@ -127,7 +127,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit userToUpdate.update(allRoles, office, command); this.appUserRepository.saveAndFlush(userToUpdate); - if (command.getPassword() != null || command.getRepeatPassword() != null) { + if (command.isPasswordChanged()) { PlatformUser dummyPlatformUser = new BasicPasswordEncodablePlatformUser( userToUpdate.getId(), userToUpdate.getUsername(), command.getPassword()); @@ -140,7 +140,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit return userToUpdate.getId(); } catch (DataIntegrityViolationException dve) { - handleOfficeDataIntegrityIssues(command, dve); + handleAppUserDataIntegrityIssues(command, dve); return Long.valueOf(-1); } } @@ -164,6 +164,8 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit return allRoles; } + // FIXME - KW - move this to a soft delete of user marking a is_deleted field as true so doesnt appear in results + // more than making a user disabled, locked? @Transactional @Override public void deleteUser(final Long userId) { @@ -178,11 +180,12 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit /* * Guaranteed to throw an exception no matter what the data integrity issue is. */ - private void handleOfficeDataIntegrityIssues(final UserCommand command, DataIntegrityViolationException dve) { + private void handleAppUserDataIntegrityIssues(final UserCommand command, final DataIntegrityViolationException dve) { Throwable realCause = dve.getMostSpecificCause(); if (realCause.getMessage().contains("username_org")) { - throw new PlatformDataIntegrityException("error.msg.user.duplicate.username", "User with username {0} already exists", "username", command.getUsername()); + StringBuilder defaultMessageBuilder = new StringBuilder("User with username ").append(command.getUsername()).append(" already exists."); + throw new PlatformDataIntegrityException("error.msg.user.duplicate.username", defaultMessageBuilder.toString(), "username", command.getUsername()); } logger.error(dve.getMessage(), dve);