Skip to content

Commit

Permalink
Development: Fix cases of ignored return values (#8575)
Browse files Browse the repository at this point in the history
  • Loading branch information
Strohgelaender authored May 12, 2024
1 parent d5df0b0 commit ff8e9e7
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ public AnswerPost updateAnswerPost(Long courseId, Long answerPostId, AnswerPost
}
AnswerPost existingAnswerPost = this.findById(answerPostId);
final Course course = courseRepository.findByIdElseThrow(courseId);
authorizationCheckService.isAtLeastStudentInCourse(course, user);
authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.STUDENT, course, user);
parseUserMentions(course, answerPost.getContent());

AnswerPost updatedAnswerPost;

// determine if the update operation is to mark the answer post as resolving the original post
if (existingAnswerPost.doesResolvePost() != answerPost.doesResolvePost()) {
if (!Objects.equals(existingAnswerPost.doesResolvePost(), answerPost.doesResolvePost())) {
// check if requesting user is allowed to mark this answer post as resolving, i.e. if user is author or original post or at least tutor
mayMarkAnswerPostAsResolvingElseThrow(existingAnswerPost, user, course);
existingAnswerPost.setResolvesPost(answerPost.doesResolvePost());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,6 @@ private Set<User> findUsersByRegistrationNumbers(Set<String> registrationNumbers

private Set<User> findUsersByLogins(Set<String> logins, String groupName) {
return new HashSet<>(userRepository.findAllWithGroupsByIsDeletedIsFalseAndGroupsContainsAndLoginIn(groupName, logins));

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ public ResponseEntity<Void> deleteChannel(@PathVariable Long courseId, @PathVari
var requestingUser = userRepository.getUserWithGroupsAndAuthorities();
channelAuthorizationService.isAllowedToDeleteChannel(channel, requestingUser);

tutorialGroupChannelManagementService.getTutorialGroupBelongingToChannel(channel).ifPresentOrElse(tutorialGroup -> {
tutorialGroupChannelManagementService.getTutorialGroupBelongingToChannel(channel).ifPresent(tutorialGroup -> {
throw new BadRequestAlertException("The channel belongs to tutorial group " + tutorialGroup.getTitle(), CHANNEL_ENTITY_NAME, "channel.tutorialGroup.mismatch");
}, Optional::empty);
});

var usersToNotify = conversationParticipantRepository.findConversationParticipantsByConversationId(channel.getId()).stream().map(ConversationParticipant::getUser)
.collect(Collectors.toSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ void getConversationsOfUser_onlyCourseWideChannelsIfMessagingDisabled() throws E
setCourseInformationSharingConfiguration(CourseInformationSharingConfiguration.COMMUNICATION_ONLY);
List<ConversationDTO> channels = request.getList("/api/courses/" + exampleCourseId + "/conversations", HttpStatus.OK, ConversationDTO.class);

channels.forEach(conv -> assertThat(conv instanceof ChannelDTO ch && ch.getIsCourseWide()));
assertThat(channels).allSatisfy(ch -> {
assertThat(ch).isInstanceOf(ChannelDTO.class);
assertThat(((ChannelDTO) ch).getIsCourseWide()).isTrue();
});

// cleanup
conversationMessageRepository.deleteById(post.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void updateAttendanceCount_asTutor_shouldUpdateAttendanceCount() throws Exceptio

// when
request.patchWithResponseBody(getSessionsPathOfTutorialGroup(exampleTutorialGroupId, session.getId()) + "/attendance-count", null, TutorialGroupSession.class,
HttpStatus.OK).getId();
HttpStatus.OK);
updatedSession = tutorialGroupSessionRepository.findByIdElseThrow(updatedSessionId);
assertThat(updatedSession.getAttendanceCount()).isNull();

Expand Down

0 comments on commit ff8e9e7

Please sign in to comment.