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) {
|
public boolean identifiedBy(final String identifier) {
|
||||||
return identifier.equalsIgnoreCase(this.externalId);
|
return identifier.equalsIgnoreCase(this.externalId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean identifiedBy(Long clientId) {
|
||||||
|
return getId().equals(clientId);
|
||||||
|
}
|
||||||
|
|
||||||
public void update(ClientCommand command) {
|
public void update(ClientCommand command) {
|
||||||
this.joiningDate = command.getJoiningLocalDate().toDate();
|
this.joiningDate = command.getJoiningLocalDate().toDate();
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ public class Note extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
@JoinColumn(name = "org_id", nullable = false)
|
@JoinColumn(name = "org_id", nullable = false)
|
||||||
private final Organisation organisation;
|
private final Organisation organisation;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "client_id", nullable = false)
|
@JoinColumn(name = "client_id", nullable = false)
|
||||||
private final Client client;
|
private final Client client;
|
||||||
@@ -113,4 +112,8 @@ public class Note extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
public void update(final String note) {
|
public void update(final String note) {
|
||||||
this.note = 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();
|
AppUser currentUser = context.authenticatedUser();
|
||||||
|
|
||||||
// FIXME - check client id matches.
|
|
||||||
Note noteForUpdate = this.noteRepository.findOne(notesThatMatch(currentUser.getOrganisation(), command.getId()));
|
Note noteForUpdate = this.noteRepository.findOne(notesThatMatch(currentUser.getOrganisation(), command.getId()));
|
||||||
if (noteForUpdate == null) {
|
if (noteForUpdate == null || noteForUpdate.isNotAgainstClientWithIdOf(command.getClientId())) {
|
||||||
throw new NoteNotFoundException(command.getClientId());
|
throw new NoteNotFoundException(command.getId(), command.getClientId(), "client");
|
||||||
}
|
}
|
||||||
|
|
||||||
noteForUpdate.update(command.getNote());
|
noteForUpdate.update(command.getNote());
|
||||||
|
|
||||||
return new EntityIdentifier(noteForUpdate.getId());
|
return new EntityIdentifier(noteForUpdate.getId());
|
||||||
|
|||||||
+4
@@ -8,4 +8,8 @@ public class NoteNotFoundException extends AbstractPlatformResourceNotFoundExcep
|
|||||||
public NoteNotFoundException(Long id) {
|
public NoteNotFoundException(Long id) {
|
||||||
super("error.msg.note.id.invalid", "Note with identifier " + id + " does not exist", 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