tidy up around user api.
This commit is contained in:
@@ -100,7 +100,7 @@ public class UserCommand implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPasswordChanged() {
|
public boolean isPasswordChanged() {
|
||||||
return this.modifiedParameters.contains("password");
|
return this.modifiedParameters.contains("password") && this.modifiedParameters.contains("repeatPassword");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOfficeChanged() {
|
public boolean isOfficeChanged() {
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import java.util.List;
|
|||||||
public class AppUserData {
|
public class AppUserData {
|
||||||
|
|
||||||
private Long id;
|
private Long id;
|
||||||
|
private String username;
|
||||||
private Long officeId;
|
private Long officeId;
|
||||||
private String officeName;
|
private String officeName;
|
||||||
private String username;
|
|
||||||
private String firstname;
|
private String firstname;
|
||||||
private String lastname;
|
private String lastname;
|
||||||
private String email;
|
private String email;
|
||||||
|
|||||||
+8
-5
@@ -88,7 +88,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
|
|||||||
|
|
||||||
return appUser.getId();
|
return appUser.getId();
|
||||||
} catch (DataIntegrityViolationException dve) {
|
} catch (DataIntegrityViolationException dve) {
|
||||||
handleOfficeDataIntegrityIssues(command, dve);
|
handleAppUserDataIntegrityIssues(command, dve);
|
||||||
return Long.valueOf(-1);
|
return Long.valueOf(-1);
|
||||||
} catch (PlatformEmailSendException e) {
|
} catch (PlatformEmailSendException e) {
|
||||||
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||||
@@ -127,7 +127,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
|
|||||||
userToUpdate.update(allRoles, office, command);
|
userToUpdate.update(allRoles, office, command);
|
||||||
this.appUserRepository.saveAndFlush(userToUpdate);
|
this.appUserRepository.saveAndFlush(userToUpdate);
|
||||||
|
|
||||||
if (command.getPassword() != null || command.getRepeatPassword() != null) {
|
if (command.isPasswordChanged()) {
|
||||||
PlatformUser dummyPlatformUser = new BasicPasswordEncodablePlatformUser(
|
PlatformUser dummyPlatformUser = new BasicPasswordEncodablePlatformUser(
|
||||||
userToUpdate.getId(),
|
userToUpdate.getId(),
|
||||||
userToUpdate.getUsername(), command.getPassword());
|
userToUpdate.getUsername(), command.getPassword());
|
||||||
@@ -140,7 +140,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
|
|||||||
|
|
||||||
return userToUpdate.getId();
|
return userToUpdate.getId();
|
||||||
} catch (DataIntegrityViolationException dve) {
|
} catch (DataIntegrityViolationException dve) {
|
||||||
handleOfficeDataIntegrityIssues(command, dve);
|
handleAppUserDataIntegrityIssues(command, dve);
|
||||||
return Long.valueOf(-1);
|
return Long.valueOf(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,6 +164,8 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
|
|||||||
return allRoles;
|
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
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public void deleteUser(final Long userId) {
|
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.
|
* 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();
|
Throwable realCause = dve.getMostSpecificCause();
|
||||||
if (realCause.getMessage().contains("username_org")) {
|
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);
|
logger.error(dve.getMessage(), dve);
|
||||||
|
|||||||
Reference in New Issue
Block a user