Skip to content

Commit

Permalink
Only show grade to users with student access to the thesis
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian committed Dec 5, 2024
1 parent b84caae commit 47406ab
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ const ThesisFinalGradeSection = () => {
}, 'Thesis successfully marked as finished')

if (!checkMinimumThesisState(thesis, ThesisState.ASSESSED)) {
return <></>
return null
}

if (!access.student) {
return null
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public ResponseEntity<PaginationDto<ThesisDto>> getTheses(
);

return ResponseEntity.ok(PaginationDto.fromSpringPage(
theses.map(thesis -> ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser)))
theses.map(thesis -> ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser), thesis.hasStudentAccess(authenticatedUser)))
));
}

Expand All @@ -108,7 +108,7 @@ public ResponseEntity<ThesisDto> getThesis(@PathVariable UUID thesisId, JwtAuthe
throw new AccessDeniedException("You do not have the required permissions to view this thesis");
}

return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser)));
return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser), thesis.hasStudentAccess(authenticatedUser)));
}

@PostMapping
Expand All @@ -129,7 +129,7 @@ public ResponseEntity<ThesisDto> createThesis(
true
);

return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser)));
return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser), thesis.hasStudentAccess(authenticatedUser)));
}

@PutMapping("/{thesisId}")
Expand Down Expand Up @@ -160,7 +160,7 @@ public ResponseEntity<ThesisDto> updateThesisConfig(
RequestValidator.validateNotNull(payload.states())
);

return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser)));
return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser), thesis.hasStudentAccess(authenticatedUser)));
}

@DeleteMapping("/{thesisId}")
Expand All @@ -177,7 +177,7 @@ public ResponseEntity<ThesisDto> closeThesis(

thesis = thesisService.closeThesis(authenticatedUser, thesis);

return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser)));
return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser), thesis.hasStudentAccess(authenticatedUser)));
}

@PutMapping("/{thesisId}/info")
Expand All @@ -199,7 +199,7 @@ public ResponseEntity<ThesisDto> updateThesisInfo(
RequestValidator.validateStringMaxLength(payload.infoText(), StringLimits.UNLIMITED_TEXT.getLimit())
);

return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser)));
return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser), thesis.hasStudentAccess(authenticatedUser)));
}

/* FEEDBACK ENDPOINTS */
Expand All @@ -219,7 +219,7 @@ public ResponseEntity<ThesisDto> completeFeedback(

thesis = thesisService.completeFeedback(thesis, feedbackId, action.equals("complete"));

return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser)));
return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser), thesis.hasStudentAccess(authenticatedUser)));
}

@DeleteMapping("/{thesisId}/feedback/{feedbackId}")
Expand All @@ -237,7 +237,7 @@ public ResponseEntity<ThesisDto> deleteFeedback(

thesis = thesisService.deleteFeedback(thesis, feedbackId);

return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser)));
return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser), thesis.hasStudentAccess(authenticatedUser)));
}

@PostMapping("/{thesisId}/feedback")
Expand All @@ -260,7 +260,7 @@ public ResponseEntity<ThesisDto> requestChanges(
RequestValidator.validateNotNull(payload.requestedChanges())
);

return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser)));
return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser), thesis.hasStudentAccess(authenticatedUser)));
}

/* PROPOSAL ENDPOINTS */
Expand Down Expand Up @@ -302,7 +302,7 @@ public ResponseEntity<ThesisDto> deleteProposal(

thesis = thesisService.deleteProposal(thesis, proposalId);

return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser)));
return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser), thesis.hasStudentAccess(authenticatedUser)));
}

@PostMapping("/{thesisId}/proposal")
Expand All @@ -324,7 +324,7 @@ public ResponseEntity<ThesisDto> uploadProposal(

thesis = thesisService.uploadProposal(authenticatedUser, thesis, RequestValidator.validateNotNull(proposalFile));

return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser)));
return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser), thesis.hasStudentAccess(authenticatedUser)));
}

@PutMapping("/{thesisId}/proposal/accept")
Expand All @@ -341,7 +341,7 @@ public ResponseEntity<ThesisDto> acceptProposal(

thesis = thesisService.acceptProposal(authenticatedUser, thesis);

return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser)));
return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser), thesis.hasStudentAccess(authenticatedUser)));
}

/* WRITING ENDPOINTS */
Expand All @@ -360,7 +360,7 @@ public ResponseEntity<ThesisDto> submitThesis(

thesis = thesisService.submitThesis(thesis);

return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser)));
return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser), thesis.hasStudentAccess(authenticatedUser)));
}

@PostMapping("/{thesisId}/files")
Expand All @@ -383,7 +383,7 @@ public ResponseEntity<ThesisDto> uploadThesisFile(

thesis = thesisService.uploadThesisFile(authenticatedUser, thesis, type, RequestValidator.validateNotNull(file));

return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser)));
return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser), thesis.hasStudentAccess(authenticatedUser)));
}

@GetMapping("/{thesisId}/files/{fileId}")
Expand Down Expand Up @@ -423,7 +423,7 @@ public ResponseEntity<ThesisDto> deleteThesisFile(

thesis = thesisService.deleteThesisFile(thesis, fileId);

return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser)));
return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser), thesis.hasStudentAccess(authenticatedUser)));
}

@PostMapping("/{thesisId}/presentations")
Expand All @@ -450,7 +450,7 @@ public ResponseEntity<ThesisDto> createPresentation(
RequestValidator.validateNotNull(payload.date())
);

return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser)));
return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser), thesis.hasStudentAccess(authenticatedUser)));
}

@PutMapping("/{thesisId}/presentations/{presentationId}")
Expand Down Expand Up @@ -482,7 +482,7 @@ public ResponseEntity<ThesisDto> updatePresentation(
RequestValidator.validateNotNull(payload.date())
);

return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser)));
return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser), thesis.hasStudentAccess(authenticatedUser)));
}

@PostMapping("/{thesisId}/presentations/{presentationId}/schedule")
Expand All @@ -507,7 +507,7 @@ public ResponseEntity<ThesisDto> schedulePresentation(
RequestValidator.validateNotNull(payload.optionalAttendees())
);

return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser)));
return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser), thesis.hasStudentAccess(authenticatedUser)));
}

@DeleteMapping("/{thesisId}/presentations/{presentationId}")
Expand All @@ -525,7 +525,7 @@ public ResponseEntity<ThesisDto> deletePresentation(

Thesis thesis = thesisPresentationService.deletePresentation(authenticatedUser, presentation);

return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser)));
return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser), thesis.hasStudentAccess(authenticatedUser)));
}

@GetMapping("/{thesisId}/comments")
Expand Down Expand Up @@ -665,7 +665,7 @@ public ResponseEntity<ThesisDto> createAssessment(
RequestValidator.validateStringMaxLength(payload.gradeSuggestion(), StringLimits.THESIS_GRADE.getLimit())
);

return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser)));
return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser), thesis.hasStudentAccess(authenticatedUser)));
}

/* GRADE ENDPOINTS */
Expand All @@ -690,7 +690,7 @@ public ResponseEntity<ThesisDto> addGrade(
RequestValidator.validateNotNull(payload.visibility())
);

return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser)));
return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser), thesis.hasStudentAccess(authenticatedUser)));
}

@PostMapping("/{thesisId}/complete")
Expand All @@ -707,6 +707,6 @@ public ResponseEntity<ThesisDto> completeThesis(

thesis = thesisService.completeThesis(thesis);

return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser)));
return ResponseEntity.ok(ThesisDto.fromThesisEntity(thesis, thesis.hasAdvisorAccess(authenticatedUser), thesis.hasStudentAccess(authenticatedUser)));
}
}
6 changes: 3 additions & 3 deletions server/src/main/java/thesistrack/ls1/dto/ThesisDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public static ThesisStateChangeDto fromStateChangeEntity(ThesisStateChange state
}
}

public static ThesisDto fromThesisEntity(Thesis thesis, boolean protectedAccess) {
public static ThesisDto fromThesisEntity(Thesis thesis, boolean advisorAccess, boolean studentAccess) {
if (thesis == null) {
return null;
}
Expand Down Expand Up @@ -238,11 +238,11 @@ public static ThesisDto fromThesisEntity(Thesis thesis, boolean protectedAccess)
thesis.getStartDate(),
thesis.getEndDate(),
thesis.getCreatedAt(),
protectedAccess && !assessments.isEmpty() ? ThesisAssessmentDto.fromAssessmentEntity(assessments.getFirst()) : null,
advisorAccess && !assessments.isEmpty() ? ThesisAssessmentDto.fromAssessmentEntity(assessments.getFirst()) : null,
proposals.stream().map(ThesisProposalDto::fromProposalEntity).toList(),
thesis.getFeedback().stream().map(ThesisFeedbackDto::fromThesisFeedbackEntity).toList(),
thesis.getFiles().stream().map(ThesisFilesDto::fromThesisFileEntity).toList(),
ThesisGradeDto.fromThesisEntity(thesis),
studentAccess ? ThesisGradeDto.fromThesisEntity(thesis) : null,
presentations.stream().map(ThesisPresentationDto::fromPresentationEntity).toList(),
students,
advisors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public MailBuilder fillApplicationPlaceholders(Application application) {
}

public MailBuilder fillThesisPlaceholders(Thesis thesis) {
fillPlaceholder("thesis", ThesisDto.fromThesisEntity(thesis, false));
fillPlaceholder("thesis", ThesisDto.fromThesisEntity(thesis, false, true));
fillPlaceholder("thesisUrl", config.getClientHost() + "/theses/" + thesis.getId());

return this;
Expand Down

0 comments on commit 47406ab

Please sign in to comment.