add check for client id when updating client notes.

This commit is contained in:
Keith Woodlock
2012-06-01 11:10:42 +01:00
parent fa6af79a3a
commit 1eb4978eea
4 changed files with 15 additions and 4 deletions
@@ -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);
}
}
@@ -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());
@@ -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);
}
}