Skip to content
Snippets Groups Projects
Commit 936a4465 authored by Otto Visser's avatar Otto Visser
Browse files

Merge branch '536-feedback-should-be-clearly-anonymous' into 'development'

Resolve "Feedback should be clearly anonymous"

Closes #536

See merge request !577
parents 223c7efe 81178c64
Branches
Tags
2 merge requests!598Dev to master,!577Resolve "Feedback should be clearly anonymous"
......@@ -221,7 +221,7 @@ public class HomeController {
@PreAuthorize("@permissionService.canViewOwnFeedback()")
public String ownFeedback(@AuthenticatedPerson Person person,
Model model, Pageable pageable) {
fillInFeedbackModel(person.getId(), model, pageable);
fillInFeedbackModel(person.getId(), person, model, pageable);
return "home/feedback";
}
......@@ -229,6 +229,7 @@ public class HomeController {
/**
* Maps the feedback url to a page. The Feedback page displays feedback for a user with the given ID.
*
* @param person The person that is currently authenticated.
* @param id The id of the person for which feedback will be shown.
* @param model The model to be filled out for Thymeleaf resolution.
* @param pageable The Pageable object representing the current page state.
......@@ -236,9 +237,9 @@ public class HomeController {
*/
@GetMapping("/feedback/{id}")
@PreAuthorize("@permissionService.canViewFeedback(#id)")
public String feedback(@PathVariable("id") Long id,
public String feedback(@AuthenticatedPerson Person person, @PathVariable("id") Long id,
Model model, Pageable pageable) {
fillInFeedbackModel(id, model, pageable);
fillInFeedbackModel(id, person, model, pageable);
return "home/feedback";
}
......@@ -247,13 +248,16 @@ public class HomeController {
* Fills in the model for a page where feedback is shown to the user.
*
* @param assistantId The id of the user to find assistant for (this could be the current user).
* @param person The person that is currently authenticated.
* @param model The model that is to be filled.
* @param pageable The pageable containing information on how much feedback needs to be shown.
*/
private void fillInFeedbackModel(Long assistantId, Model model, Pageable pageable) {
private void fillInFeedbackModel(Long assistantId, Person person, Model model, Pageable pageable) {
var assistant = pCache.getOrThrow(assistantId);
Page<Feedback> feedback = fr.findByAssistant(assistantId, pageable);
Page<Feedback> feedback = assistantId.equals(person.getId())
? fr.findByAssistantAnonymised(assistantId, pageable)
: fr.findByAssistant(assistantId, pageable);
model.addAttribute("assistant", assistant);
model.addAttribute("feedback",
......
......@@ -17,13 +17,17 @@
*/
package nl.tudelft.queue.repository;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import nl.tudelft.queue.model.Feedback;
import nl.tudelft.queue.model.QFeedback;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.repository.CrudRepository;
......@@ -74,4 +78,21 @@ public interface FeedbackRepository
return findAll(qf.id.assistantId.eq(assistantId)
.and(qf.feedback.isNotNull()).and(qf.feedback.isNotEmpty()), pageable);
}
/**
* Gets the feedback for an assistant, but leaves out too recent feedback.
*
* @param assistantId The assistant to find Feedback for.
* @param pageable The pageable object to page feedback with.
* @return The page of feedback for the given Assistant.
*/
default Page<Feedback> findByAssistantAnonymised(Long assistantId, Pageable pageable) {
var feedback = StreamSupport.stream(findAll(qf.id.assistantId.eq(assistantId)
.and(qf.feedback.isNotNull()).and(qf.feedback.isNotEmpty())
.and(qf.createdAt.before(LocalDateTime.now().minusMonths(1))), qf.createdAt.desc())
.spliterator(),
false)
.skip(10).collect(Collectors.toList());
return new PageImpl<>(feedback, pageable, feedback.size());
}
}
......@@ -83,6 +83,9 @@
</label>
</div>
</div>
<p>
Your feedback is anonymous: The TA will only be able to see the feedback and score you give, not your name.
</p>
<div class="form-group">
<label for="input-feedback" style="width: 100%">
<textarea id="input-feedback"
......
......@@ -160,7 +160,7 @@ class HomeControllerTest {
.andExpect(model().attributeExists("assistant", "feedback"))
.andExpect(view().name("home/feedback"));
verify(feedbackRepository).findByAssistant(student100.getId(), PageRequest.of(1, 1));
verify(feedbackRepository).findByAssistantAnonymised(student100.getId(), PageRequest.of(1, 1));
verify(permissionService, atLeastOnce()).canViewOwnFeedback();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment