Skip to content

Commit

Permalink
Updated configuration in the server side
Browse files Browse the repository at this point in the history
  • Loading branch information
egekurt123 committed Jun 19, 2024
1 parent d37e3a6 commit 4378e4e
Show file tree
Hide file tree
Showing 18 changed files with 28 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@ public enum CourseInformationSharingConfiguration {
/**
* Only Communication is enabled VALUE = 2
*/
COMMUNICATION_ONLY,
/**
* Only Messaging is enabled VALUE = 3
*/
MESSAGING_ONLY;
COMMUNICATION_ONLY;

public boolean isMessagingEnabled() {
return this == MESSAGING_ONLY || this == COMMUNICATION_AND_MESSAGING;
return this == COMMUNICATION_AND_MESSAGING;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,7 @@ default Course findWithEagerLearningPathsAndCompetenciesByIdElseThrow(long cours
* @return true if the messaging feature is enabled for the course, false otherwise
*/
default boolean isMessagingEnabled(long courseId) {
return informationSharingConfigurationIsOneOf(courseId,
Set.of(CourseInformationSharingConfiguration.MESSAGING_ONLY, CourseInformationSharingConfiguration.COMMUNICATION_AND_MESSAGING));
return informationSharingConfigurationIsOneOf(courseId, Set.of(CourseInformationSharingConfiguration.COMMUNICATION_AND_MESSAGING));
}

/**
Expand All @@ -514,8 +513,8 @@ default boolean isMessagingEnabled(long courseId) {
* @return true if the communication feature is enabled for the course, false otherwise
*/
default boolean isMessagingOrCommunicationEnabled(long courseId) {
return informationSharingConfigurationIsOneOf(courseId, Set.of(CourseInformationSharingConfiguration.COMMUNICATION_ONLY,
CourseInformationSharingConfiguration.MESSAGING_ONLY, CourseInformationSharingConfiguration.COMMUNICATION_AND_MESSAGING));
return informationSharingConfigurationIsOneOf(courseId,
Set.of(CourseInformationSharingConfiguration.COMMUNICATION_ONLY, CourseInformationSharingConfiguration.COMMUNICATION_AND_MESSAGING));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package de.tum.in.www1.artemis.web.rest.metis.conversation;

import java.util.Set;

import org.springframework.http.HttpStatus;
import org.springframework.web.server.ResponseStatusException;

Expand Down Expand Up @@ -36,8 +34,7 @@ void checkMessagingEnabledElseThrow(Long courseId) {
* @param course the course to check
*/
void checkMessagingEnabledElseThrow(Course course) {
if (!Set.of(CourseInformationSharingConfiguration.MESSAGING_ONLY, CourseInformationSharingConfiguration.COMMUNICATION_AND_MESSAGING)
.contains(course.getCourseInformationSharingConfiguration())) {
if (course.getCourseInformationSharingConfiguration() != CourseInformationSharingConfiguration.COMMUNICATION_AND_MESSAGING) {
throw new ResponseStatusException(HttpStatus.FORBIDDEN, "Messaging is not enabled for this course");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
<changeSet id="20240620150000" author="ekurt">
<update tableName="course">
<column name="info_sharing_config" value="1"/>
<where>info_sharing_config = 3</where>
</update>
</changeSet>
</databaseChangeLog>
1 change: 1 addition & 0 deletions src/main/resources/config/liquibase/master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<include file="classpath:config/liquibase/changelog/20240522170000_changelog.xml" relativeToChangelogFile="false"/>
<include file="classpath:config/liquibase/changelog/20240522114700_changelog.xml" relativeToChangelogFile="false"/>
<include file="classpath:config/liquibase/changelog/20240531210000_changelog.xml" relativeToChangelogFile="false"/>
<include file="classpath:config/liquibase/changelog/20240620150000_changelog.xml" relativeToChangelogFile="false"/>
<!-- NOTE: please use the format "YYYYMMDDhhmmss_changelog.xml", i.e. year month day hour minutes seconds and not something else! -->
<!-- we should also stay in a chronological order! -->
<!-- you can use the command 'date '+%Y%m%d%H%M%S'' to get the current date and time in the correct format -->
Expand Down
9 changes: 2 additions & 7 deletions src/main/webapp/app/entities/course.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { LearningPath } from 'app/entities/competency/learning-path.model';
export enum CourseInformationSharingConfiguration {
COMMUNICATION_AND_MESSAGING = 'COMMUNICATION_AND_MESSAGING',
COMMUNICATION_ONLY = 'COMMUNICATION_ONLY',
MESSAGING_ONLY = 'MESSAGING_ONLY',
DISABLED = 'DISABLED',
}

Expand All @@ -33,19 +32,15 @@ export function isCommunicationEnabled(course: Course | undefined) {
*/
export function isMessagingEnabled(course: Course | undefined) {
const config = course?.courseInformationSharingConfiguration;
return config === CourseInformationSharingConfiguration.COMMUNICATION_AND_MESSAGING || config === CourseInformationSharingConfiguration.MESSAGING_ONLY;
return config === CourseInformationSharingConfiguration.COMMUNICATION_AND_MESSAGING;
}

/**
* Note: Keep in sync with method in CourseRepository.java
*/
export function isMessagingOrCommunicationEnabled(course: Course | undefined) {
const config = course?.courseInformationSharingConfiguration;
return (
config === CourseInformationSharingConfiguration.COMMUNICATION_AND_MESSAGING ||
config === CourseInformationSharingConfiguration.MESSAGING_ONLY ||
config === CourseInformationSharingConfiguration.COMMUNICATION_ONLY
);
return config === CourseInformationSharingConfiguration.COMMUNICATION_AND_MESSAGING || config === CourseInformationSharingConfiguration.COMMUNICATION_ONLY;
}

export const enum Language {
Expand Down
1 change: 0 additions & 1 deletion src/test/cypress/support/artemis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const courseList = pageObjects.course.list;
export const courseOverview = pageObjects.course.overview;
export const courseManagement = pageObjects.course.management;
export const courseManagementExercises = pageObjects.course.managementExercises;
export const courseCommunication = pageObjects.course.communication;
export const courseMessages = pageObjects.course.messages;
export const courseAssessment = pageObjects.assessment.course;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ export class CourseManagementAPIRequests {
course.courseInformationSharingMessagingCodeOfConduct = 'Code of Conduct';
} else if (allowCommunication) {
course.courseInformationSharingConfiguration = CourseInformationSharingConfiguration.COMMUNICATION_ONLY;
} else if (allowMessaging) {
course.courseInformationSharingConfiguration = CourseInformationSharingConfiguration.MESSAGING_ONLY;
course.courseInformationSharingMessagingCodeOfConduct = 'Code of Conduct';
} else {
course.courseInformationSharingConfiguration = CourseInformationSharingConfiguration.DISABLED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@ public static Course generateCourse(Long id, String shortName, ZonedDateTime sta
else if (communicationEnabled) {
course.setCourseInformationSharingConfiguration(CourseInformationSharingConfiguration.COMMUNICATION_ONLY);
}
else if (messagingEnabled) {
course.setCourseInformationSharingConfiguration(CourseInformationSharingConfiguration.MESSAGING_ONLY);
}
else {
course.setCourseInformationSharingConfiguration(CourseInformationSharingConfiguration.DISABLED);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ public void testCreateCourseWithCustomNonExistingGroupNames() throws Exception {
// Test
public void testCreateCourseWithOptions() throws Exception {
// Generate POST Request Body with maxComplaints = 5, maxComplaintTimeDays = 14, communication = false, messaging = true
Course course = CourseFactory.generateCourse(null, null, null, new HashSet<>(), null, null, null, null, 5, 5, 14, 2000, 2000, false, true, 0);
Course course = CourseFactory.generateCourse(null, null, null, new HashSet<>(), null, null, null, null, 5, 5, 14, 2000, 2000, false, false, 0);

mockDelegate.mockCreateGroupInUserManagement(course.getDefaultStudentGroupName());
mockDelegate.mockCreateGroupInUserManagement(course.getDefaultTeachingAssistantGroupName());
Expand All @@ -493,7 +493,7 @@ public void testCreateCourseWithOptions() throws Exception {
assertThat(getFromRepo.getMaxComplaints()).as("Course has right maxComplaints Value").isEqualTo(5);
assertThat(getFromRepo.getMaxComplaintTimeDays()).as("Course has right maxComplaintTimeDays Value").isEqualTo(14);
assertThat(getFromRepo.getCourseInformationSharingConfiguration()).as("Course has right information sharing config value")
.isEqualTo(CourseInformationSharingConfiguration.MESSAGING_ONLY);
.isEqualTo(CourseInformationSharingConfiguration.DISABLED);
assertThat(getFromRepo.getRequestMoreFeedbackEnabled()).as("Course has right requestMoreFeedbackEnabled value").isFalse();

// Test edit course
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1029,11 +1029,7 @@ public void saveCourse(Course course) {

public void enableMessagingForCourse(Course course) {
CourseInformationSharingConfiguration currentConfig = course.getCourseInformationSharingConfiguration();
if (currentConfig == CourseInformationSharingConfiguration.DISABLED) {
course.setCourseInformationSharingConfiguration(CourseInformationSharingConfiguration.MESSAGING_ONLY);
courseRepo.save(course);
}
else if (currentConfig == CourseInformationSharingConfiguration.COMMUNICATION_ONLY) {
if (currentConfig == CourseInformationSharingConfiguration.COMMUNICATION_ONLY) {
course.setCourseInformationSharingConfiguration(CourseInformationSharingConfiguration.COMMUNICATION_AND_MESSAGING);
courseRepo.save(course);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,6 @@ protected static List<Arguments> userMentionProvider() {
}

private static List<CourseInformationSharingConfiguration> courseInformationSharingConfigurationProvider() {
return List.of(CourseInformationSharingConfiguration.MESSAGING_ONLY, CourseInformationSharingConfiguration.COMMUNICATION_ONLY,
CourseInformationSharingConfiguration.COMMUNICATION_AND_MESSAGING);
return List.of(CourseInformationSharingConfiguration.COMMUNICATION_ONLY, CourseInformationSharingConfiguration.COMMUNICATION_AND_MESSAGING);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,6 @@ private List<Long> createExerciseAndExamAndLectureChannels(Course course, ZonedD
private static List<Arguments> courseConfigurationProvider() {
return List.of(Arguments.of(CourseInformationSharingConfiguration.DISABLED, HttpStatus.FORBIDDEN),
Arguments.of(CourseInformationSharingConfiguration.COMMUNICATION_AND_MESSAGING, HttpStatus.OK),
Arguments.of(CourseInformationSharingConfiguration.COMMUNICATION_ONLY, HttpStatus.OK),
Arguments.of(CourseInformationSharingConfiguration.MESSAGING_ONLY, HttpStatus.OK));
Arguments.of(CourseInformationSharingConfiguration.COMMUNICATION_ONLY, HttpStatus.OK));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,7 @@ private Post createPostAndAwaitAsyncCode(Post postToSave) throws Exception {
}

private static List<CourseInformationSharingConfiguration> courseInformationSharingConfigurationProvider() {
return List.of(CourseInformationSharingConfiguration.MESSAGING_ONLY, CourseInformationSharingConfiguration.COMMUNICATION_ONLY,
CourseInformationSharingConfiguration.COMMUNICATION_AND_MESSAGING);
return List.of(CourseInformationSharingConfiguration.COMMUNICATION_ONLY, CourseInformationSharingConfiguration.COMMUNICATION_AND_MESSAGING);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,6 @@ private void checkCreatedReaction(Reaction expectedReaction, Reaction createdRea

private static List<Arguments> courseConfigurationProvider() {
return List.of(Arguments.of(CourseInformationSharingConfiguration.DISABLED, false), Arguments.of(CourseInformationSharingConfiguration.COMMUNICATION_AND_MESSAGING, true),
Arguments.of(CourseInformationSharingConfiguration.COMMUNICATION_ONLY, true), Arguments.of(CourseInformationSharingConfiguration.MESSAGING_ONLY, true));
Arguments.of(CourseInformationSharingConfiguration.COMMUNICATION_ONLY, true));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,6 @@ void testCreateAnswerPostWithUserMention(String userMention, boolean isUserMenti
checkCreatedAnswerPost(answerPostToSave, createdAnswerPost);
}

@Test
@WithMockUser(username = TEST_PREFIX + "student1", roles = "USER")
void testPostingAllowedIfMessagingOnlySetting() throws Exception {
messagingFeatureDisabledTest(CourseInformationSharingConfiguration.MESSAGING_ONLY);
}

@Test
@WithMockUser(username = TEST_PREFIX + "student1", roles = "USER")
void testPostingNotAllowedIfDisabledSetting() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ describe('Metis Service', () => {

it('should not fetch course post tags if communication is not enabled', () => {
const updateCoursePostTagsSpy = jest.spyOn(metisService, 'updateCoursePostTags');
course.courseInformationSharingConfiguration = CourseInformationSharingConfiguration.MESSAGING_ONLY;
course.courseInformationSharingConfiguration = CourseInformationSharingConfiguration.DISABLED;
metisService.setCourse(course);
const getCourseReturn = metisService.getCourse();
expect(getCourseReturn).toEqual(course);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ export class CourseManagementAPIRequests {
course.courseInformationSharingMessagingCodeOfConduct = 'Code of Conduct';
} else if (allowCommunication) {
course.courseInformationSharingConfiguration = CourseInformationSharingConfiguration.COMMUNICATION_ONLY;
} else if (allowMessaging) {
course.courseInformationSharingConfiguration = CourseInformationSharingConfiguration.MESSAGING_ONLY;
course.courseInformationSharingMessagingCodeOfConduct = 'Code of Conduct';
} else {
course.courseInformationSharingConfiguration = CourseInformationSharingConfiguration.DISABLED;
}
Expand Down

0 comments on commit 4378e4e

Please sign in to comment.