tidy up around user api.
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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;
|
||||
|
||||
+8
-5
@@ -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<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user