Skip to content

Commit

Permalink
Fix tests (partial)
Browse files Browse the repository at this point in the history
  • Loading branch information
domlimm committed Mar 27, 2024
1 parent af36d78 commit ab40081
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected void testAccessControl() throws Exception {
};
Instructor instructorWhoGiveComment = typicalBundle.instructors.get("instructor1OfCourse1");

assertEquals(instructorWhoGiveComment.getEmail(), frc.getGiver());
assertEquals(instructorWhoGiveComment.getEmail(), frc.getGiver().getEmail());
loginAsInstructor(instructorWhoGiveComment.getGoogleId());
verifyCanAccess(submissionParams);

Expand Down
12 changes: 10 additions & 2 deletions src/main/java/teammates/storage/sqlapi/FeedbackResponsesDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import teammates.storage.sqlentity.FeedbackResponse;
import teammates.storage.sqlentity.FeedbackSession;
import teammates.storage.sqlentity.Section;
import teammates.storage.sqlentity.User;

import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaDelete;
Expand Down Expand Up @@ -130,10 +131,11 @@ public List<FeedbackResponse> getFeedbackResponsesFromGiverForQuestion(
CriteriaQuery<FeedbackResponse> cq = cb.createQuery(FeedbackResponse.class);
Root<FeedbackResponse> root = cq.from(FeedbackResponse.class);
Join<FeedbackResponse, FeedbackQuestion> frJoin = root.join("feedbackQuestion");
Join<FeedbackResponse, User> uJoin = root.join("giver");
cq.select(root)
.where(cb.and(
cb.equal(frJoin.get("id"), feedbackQuestionId),
cb.equal(root.get("giver"), giverEmail)));
cb.equal(uJoin.get("email"), giverEmail)));
return HibernateUtil.createQuery(cq).getResultList();
}

Expand Down Expand Up @@ -183,6 +185,11 @@ public List<FeedbackResponse> getResponsesForQuestion(UUID questionId) {

/**
* Checks whether a user has responses in a session.
*
* @param giver the email of the giver.
* @param feedbackSessionName the name of the feedback session.
* @param courseId the identifier of the course.
* @return a boolean if there are responses from the given giver in this feedback session.
*/
public boolean hasResponsesFromGiverInSession(
String giver, String feedbackSessionName, String courseId) {
Expand All @@ -192,10 +199,11 @@ public boolean hasResponsesFromGiverInSession(
Join<FeedbackResponse, FeedbackQuestion> fqJoin = root.join("feedbackQuestion");
Join<FeedbackQuestion, FeedbackSession> fsJoin = fqJoin.join("feedbackSession");
Join<FeedbackSession, Course> courseJoin = fsJoin.join("course");
Join<FeedbackResponse, User> uJoin = root.join("giver");

cq.select(root)
.where(cb.and(
cb.equal(root.get("giver"), giver),
cb.equal(uJoin.get("email"), giver),
cb.equal(fsJoin.get("name"), feedbackSessionName),
cb.equal(courseJoin.get("id"), courseId)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public abstract class FeedbackResponse extends BaseEntity {
@OneToMany(mappedBy = "feedbackResponse", cascade = CascadeType.REMOVE)
private List<FeedbackResponseComment> feedbackResponseComments = new ArrayList<>();

@ManyToOne
@ManyToOne(cascade = {CascadeType.MERGE, CascadeType.REMOVE})
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(name = "giverId", nullable = false)
private User giver;
Expand All @@ -57,7 +57,7 @@ public abstract class FeedbackResponse extends BaseEntity {
@JoinColumn(name = "giverSectionId")
private Section giverSection;

@ManyToOne
@ManyToOne(cascade = {CascadeType.MERGE, CascadeType.REMOVE})
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(name = "recipientId", nullable = false)
private User recipient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void checkSpecificAccessControl() throws UnauthorizedAccessException {
if (instructor == null) {
throw new UnauthorizedAccessException("Trying to access system using a non-existent instructor entity");
}
if (comment.getGiver().equals(instructor.getEmail())) { // giver, allowed by default
if (comment.getGiver().getEmail().equals(instructor.getEmail())) { // giver, allowed by default
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/teammates/ui/webapi/GateKeeper.java
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,10 @@ void verifyOwnership(FeedbackResponseCommentAttributes frc, String feedbackParti
void verifyOwnership(FeedbackResponseComment frc, String feedbackParticipant)
throws UnauthorizedAccessException {
verifyNotNull(frc, "feedback response comment");
verifyNotNull(frc.getGiver(), "feedback response comment giver");
verifyNotNull(frc.getGiver().getEmail(), "feedback response comment giver");
verifyNotNull(feedbackParticipant, "comment giver");

if (!frc.getGiver().equals(feedbackParticipant)) {
if (!frc.getGiver().getEmail().equals(feedbackParticipant)) {
throw new UnauthorizedAccessException("Comment [" + frc.getId() + "] is not accessible to "
+ feedbackParticipant);
}
Expand Down

0 comments on commit ab40081

Please sign in to comment.