Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
Prevent mentors from editing application in wrong states (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
Piumal1999 authored Jul 18, 2021
1 parent 4a9a3a4 commit ac631e7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public List<MentorResponse> editMentorResponses(
Authentication authentication,
@RequestBody List<MentorResponse> responses
)
throws ResourceNotFoundException{
throws ResourceNotFoundException, BadRequestException {
Profile profile = (Profile) authentication.getPrincipal();
return programService.editMentorResponses(id, profile.getId(), responses);
}
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/org/sefglobal/scholarx/service/ProgramService.java
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,12 @@ public List<MentorResponse> getMentorResponses(long mentorId) throws ResourceNot
* @param mentorResponses list of {@link MentorResponse}s to be updated
* @return the updated list of {@link MentorResponse}
* @throws ResourceNotFoundException if a mentor doesn't exist by the given profileId and programId
* @throws BadRequestException is thrown if the {@link Program} is not in the valid {@link ProgramState}
*/
public List<MentorResponse> editMentorResponses(long programId,
long profileId,
List<MentorResponse> mentorResponses)
throws ResourceNotFoundException {
throws ResourceNotFoundException, BadRequestException {
Optional<Mentor> mentor = mentorRepository.findByProfileIdAndProgramId(profileId, programId);
if (!mentor.isPresent()) {
String msg = "Error, Mentor by profile id: " + profileId + " and " +
Expand All @@ -356,6 +357,14 @@ public List<MentorResponse> editMentorResponses(long programId,
log.error(msg);
throw new ResourceNotFoundException(msg);
}

if (!ProgramState.MENTOR_APPLICATION.equals(mentor.get().getProgram().getState())) {
String msg = "Error, Unable to edit mentor application. " +
"Program with id: " + programId + " is not in the valid state.";
log.error(msg);
throw new BadRequestException(msg);
}

List<MentorResponse> updatedMentorResponses = new ArrayList<>();
for (MentorResponse response: mentorResponses) {
MentorResponse queriedResponse = mentorResponseRepository.getOne(response.getId());
Expand Down

0 comments on commit ac631e7

Please sign in to comment.