add check for client id when updating client notes.
This commit is contained in:
@@ -86,6 +86,10 @@ public class Client extends AbstractAuditableCustom<AppUser, Long> {
|
||||
public boolean identifiedBy(final String identifier) {
|
||||
return identifier.equalsIgnoreCase(this.externalId);
|
||||
}
|
||||
|
||||
public boolean identifiedBy(Long clientId) {
|
||||
return getId().equals(clientId);
|
||||
}
|
||||
|
||||
public void update(ClientCommand command) {
|
||||
this.joiningDate = command.getJoiningLocalDate().toDate();
|
||||
|
||||
@@ -21,7 +21,6 @@ public class Note extends AbstractAuditableCustom<AppUser, Long> {
|
||||
@JoinColumn(name = "org_id", nullable = false)
|
||||
private final Organisation organisation;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "client_id", nullable = false)
|
||||
private final Client client;
|
||||
@@ -113,4 +112,8 @@ public class Note extends AbstractAuditableCustom<AppUser, Long> {
|
||||
public void update(final String note) {
|
||||
this.note = note;
|
||||
}
|
||||
|
||||
public boolean isNotAgainstClientWithIdOf(Long clientId) {
|
||||
return !this.client.identifiedBy(clientId);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -128,11 +128,11 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
|
||||
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
|
||||
// FIXME - check client id matches.
|
||||
Note noteForUpdate = this.noteRepository.findOne(notesThatMatch(currentUser.getOrganisation(), command.getId()));
|
||||
if (noteForUpdate == null) {
|
||||
throw new NoteNotFoundException(command.getClientId());
|
||||
if (noteForUpdate == null || noteForUpdate.isNotAgainstClientWithIdOf(command.getClientId())) {
|
||||
throw new NoteNotFoundException(command.getId(), command.getClientId(), "client");
|
||||
}
|
||||
|
||||
noteForUpdate.update(command.getNote());
|
||||
|
||||
return new EntityIdentifier(noteForUpdate.getId());
|
||||
|
||||
+4
@@ -8,4 +8,8 @@ public class NoteNotFoundException extends AbstractPlatformResourceNotFoundExcep
|
||||
public NoteNotFoundException(Long id) {
|
||||
super("error.msg.note.id.invalid", "Note with identifier " + id + " does not exist", id);
|
||||
}
|
||||
|
||||
public NoteNotFoundException(Long id, Long clientId, final String resource) {
|
||||
super("error.msg." + resource + ".note.id.invalid", "Note with identifier " + id + " does not exist for " + resource + " with identifier " + clientId, id, clientId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user