Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iris: Preserve settings on course and exercise update #7265

Merged
merged 6 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ SELECT CASE WHEN (count(c) > 0) THEN true ELSE false END
@EntityGraph(type = LOAD, attributePaths = { "lectures", "lectures.lectureUnits" })
Optional<Course> findWithEagerLecturesAndLectureUnitsById(long courseId);

@EntityGraph(type = LOAD, attributePaths = { "organizations", "competencies", "prerequisites", "tutorialGroupsConfiguration", "onlineCourseConfiguration" })
@EntityGraph(type = LOAD, attributePaths = { "organizations", "competencies", "prerequisites", "tutorialGroupsConfiguration", "onlineCourseConfiguration", "irisSettings" })
Optional<Course> findWithEagerOrganizationsAndCompetenciesAndOnlineConfigurationById(long courseId);
Hialus marked this conversation as resolved.
Show resolved Hide resolved

@EntityGraph(type = LOAD, attributePaths = { "exercises", "lectures", "lectures.lectureUnits", "competencies", "prerequisites" })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package de.tum.in.www1.artemis.repository.iris;

import java.util.Optional;
import java.util.Set;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import de.tum.in.www1.artemis.domain.iris.settings.IrisSettings;

Expand All @@ -15,8 +17,18 @@ public interface IrisSettingsRepository extends JpaRepository<IrisSettings, Long
@Query("""
SELECT irisSettings
FROM IrisSettings irisSettings
LEFT JOIN FETCH irisSettings.irisChatSettings ics
LEFT JOIN FETCH irisSettings.irisChatSettings ics
WHERE irisSettings.isGlobal = true
""")
Set<IrisSettings> findAllGlobalSettings();

@Query("""
SELECT irisSettings
FROM IrisSettings irisSettings
LEFT JOIN FETCH irisSettings.irisChatSettings ics
LEFT JOIN FETCH irisSettings.irisHestiaSettings ihs
LEFT JOIN ProgrammingExercise pe ON pe.irisSettings.id = irisSettings.id
WHERE pe.id = :programmingExerciseId
""")
Optional<IrisSettings> findByProgrammingExerciseId(@Param("programmingExerciseId") Long programmingExerciseId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,16 @@ public IrisSettings saveIrisSettings(ProgrammingExercise exercise, IrisSettings
}
}

/**
* Update the Iris settings for a programming exercise.
*
* @param programmingExerciseBeforeUpdate the programming exercise before the update
* @param updatedProgrammingExercise the programming exercise after the update
*/
public void updateIrisSettings(ProgrammingExercise programmingExerciseBeforeUpdate, ProgrammingExercise updatedProgrammingExercise) {
irisSettingsRepository.findByProgrammingExerciseId(programmingExerciseBeforeUpdate.getId()).ifPresent(updatedProgrammingExercise::setIrisSettings);
Hialus marked this conversation as resolved.
Show resolved Hide resolved
}

private IrisSubSettings copyIrisSubSettings(IrisSubSettings target, IrisSubSettings source) {
if (target == null || source == null) {
return source;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import de.tum.in.www1.artemis.service.connectors.ci.ContinuousIntegrationTriggerService;
import de.tum.in.www1.artemis.service.connectors.vcs.VersionControlService;
import de.tum.in.www1.artemis.service.hestia.ProgrammingExerciseTaskService;
import de.tum.in.www1.artemis.service.iris.IrisSettingsService;
import de.tum.in.www1.artemis.service.messaging.InstanceMessageSendService;
import de.tum.in.www1.artemis.service.metis.conversation.ChannelService;
import de.tum.in.www1.artemis.service.notifications.GroupNotificationScheduleService;
Expand Down Expand Up @@ -133,6 +134,8 @@ public class ProgrammingExerciseService {

private final ChannelService channelService;

private final IrisSettingsService irisSettingsService;

public ProgrammingExerciseService(ProgrammingExerciseRepository programmingExerciseRepository, GitService gitService, Optional<VersionControlService> versionControlService,
Optional<ContinuousIntegrationService> continuousIntegrationService, Optional<ContinuousIntegrationTriggerService> continuousIntegrationTriggerService,
TemplateProgrammingExerciseParticipationRepository templateProgrammingExerciseParticipationRepository,
Expand All @@ -143,7 +146,8 @@ public ProgrammingExerciseService(ProgrammingExerciseRepository programmingExerc
ProgrammingExerciseSolutionEntryRepository programmingExerciseSolutionEntryRepository, ProgrammingExerciseTaskService programmingExerciseTaskService,
ProgrammingExerciseGitDiffReportRepository programmingExerciseGitDiffReportRepository, ExerciseSpecificationService exerciseSpecificationService,
ProgrammingExerciseRepositoryService programmingExerciseRepositoryService, AuxiliaryRepositoryService auxiliaryRepositoryService,
SubmissionPolicyService submissionPolicyService, Optional<ProgrammingLanguageFeatureService> programmingLanguageFeatureService, ChannelService channelService) {
SubmissionPolicyService submissionPolicyService, Optional<ProgrammingLanguageFeatureService> programmingLanguageFeatureService, ChannelService channelService,
IrisSettingsService irisSettingsService) {
this.programmingExerciseRepository = programmingExerciseRepository;
this.gitService = gitService;
this.versionControlService = versionControlService;
Expand All @@ -169,6 +173,7 @@ public ProgrammingExerciseService(ProgrammingExerciseRepository programmingExerc
this.submissionPolicyService = submissionPolicyService;
this.programmingLanguageFeatureService = programmingLanguageFeatureService;
this.channelService = channelService;
this.irisSettingsService = irisSettingsService;
}

/**
Expand Down Expand Up @@ -438,6 +443,7 @@ public ProgrammingExercise updateProgrammingExercise(ProgrammingExercise program
connectAuxiliaryRepositoriesToExercise(updatedProgrammingExercise);

channelService.updateExerciseChannel(programmingExerciseBeforeUpdate, updatedProgrammingExercise);
irisSettingsService.updateIrisSettings(programmingExerciseBeforeUpdate, updatedProgrammingExercise);

ProgrammingExercise savedProgrammingExercise = programmingExerciseRepository.save(updatedProgrammingExercise);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ public ResponseEntity<Course> updateCourse(@PathVariable Long courseId, @Request
courseUpdate.setPrerequisites(existingCourse.getPrerequisites());
courseUpdate.setTutorialGroupsConfiguration(existingCourse.getTutorialGroupsConfiguration());
courseUpdate.setOnlineCourseConfiguration(existingCourse.getOnlineCourseConfiguration());
courseUpdate.setIrisSettings(existingCourse.getIrisSettings());

courseUpdate.validateEnrollmentConfirmationMessage();
courseUpdate.validateComplaintsAndRequestMoreFeedbackConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import de.tum.in.www1.artemis.service.dto.UserDTO;
import de.tum.in.www1.artemis.service.dto.UserPublicInfoDTO;
import de.tum.in.www1.artemis.service.export.CourseExamExportService;
import de.tum.in.www1.artemis.service.iris.IrisSettingsService;
import de.tum.in.www1.artemis.service.notifications.GroupNotificationService;
import de.tum.in.www1.artemis.service.scheduled.ParticipantScoreScheduleService;
import de.tum.in.www1.artemis.team.TeamUtilService;
Expand Down Expand Up @@ -216,6 +217,9 @@ public class CourseTestService {
@Autowired
private ParticipantScoreScheduleService participantScoreScheduleService;

@Autowired
private IrisSettingsService irisSettingsService;

private static final int numberOfStudents = 8;

private static final int numberOfTutors = 5;
Expand Down Expand Up @@ -606,6 +610,23 @@ public void testEditCourseShouldPreserveAssociations() throws Exception {
assertThat(updatedCourse.getPrerequisites()).containsExactlyElementsOf(prerequisites);
}

// Test
public void testEditCourseShouldPreserveIrisSettings() throws Exception {
Course course = courseUtilService.createCourseWithOrganizations();
course = courseRepo.save(course);

var courseWithSettings = courseRepo.findByIdElseThrow(course.getId());
courseWithSettings = irisSettingsService.addDefaultIrisSettingsTo(courseWithSettings);
courseWithSettings.getIrisSettings().getIrisChatSettings().setEnabled(true);
courseWithSettings.getIrisSettings().getIrisChatSettings().setPreferredModel(null);
courseRepo.save(courseWithSettings);

request.getMvc().perform(buildUpdateCourse(course.getId(), course)).andExpect(status().isOk());

Course updatedCourse = courseRepo.findByIdWithOrganizationsAndCompetenciesAndOnlineConfigurationElseThrow(course.getId());
assertThat(updatedCourse.getIrisSettings()).isEqualTo(courseWithSettings.getIrisSettings());
}

// Test
public void testUpdateCourseGroups() throws Exception {
Course course = programmingExerciseUtilService.addCourseWithOneProgrammingExercise();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ void testEditCourseShouldPreserveAssociations() throws Exception {
courseTestService.testEditCourseShouldPreserveAssociations();
}

@Test
@WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR")
void testEditCourseShouldPreserveIrisSettings() throws Exception {
courseTestService.testEditCourseShouldPreserveIrisSettings();
}

@Test
@WithMockUser(username = "admin", roles = "ADMIN")
void testUpdateCourseGroups() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ void testEditCourseShouldPreserveAssociations() throws Exception {
courseTestService.testEditCourseShouldPreserveAssociations();
}

@Test
@WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR")
void testEditCourseShouldPreserveIrisSettings() throws Exception {
courseTestService.testEditCourseShouldPreserveIrisSettings();
}

@Test
@WithMockUser(username = "admin", roles = "ADMIN")
void testUpdateCourseGroups() throws Exception {
Expand Down