From 8398aa3158ac4bcd6653d295c6503ba65b0067ac Mon Sep 17 00:00:00 2001 From: Max Bergmann <80524502+max-bergmann@users.noreply.github.com> Date: Tue, 7 Nov 2023 22:00:11 +0100 Subject: [PATCH] Tutorial groups: Fix a usability issue for creating new tutorial for campus and language suggestions (#7389) --- .../TutorialGroupRepository.java | 8 ++++---- .../tutorialgroups/TutorialGroupResource.java | 18 ++++++++++-------- .../create-tutorial-group.component.ts | 1 - .../tutorial-group-form.component.ts | 9 ++++++++- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupRepository.java index 99197f028ea0..756e1138eeb0 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupRepository.java @@ -41,14 +41,14 @@ public interface TutorialGroupRepository extends JpaRepository findAllUniqueCampusValuesInCourse(@Param("courseId") Long courseId); + WHERE tutorialGroup.course.instructorGroupName IN (:#{#userGroups}) AND tutorialGroup.campus IS NOT NULL""") + Set findAllUniqueCampusValuesInRegisteredCourse(@Param("userGroups") Set userGroups); @Query(""" SELECT DISTINCT tutorialGroup.language FROM TutorialGroup tutorialGroup - WHERE tutorialGroup.course.id = :#{#courseId} AND tutorialGroup.language IS NOT NULL""") - Set findAllUniqueLanguageValuesInCourse(@Param("courseId") Long courseId); + WHERE tutorialGroup.course.instructorGroupName IN (:#{#userGroups}) AND tutorialGroup.language IS NOT NULL""") + Set findAllUniqueLanguageValuesInRegisteredCourse(@Param("userGroups") Set userGroups); @Query(""" SELECT tutorialGroup diff --git a/src/main/java/de/tum/in/www1/artemis/web/rest/tutorialgroups/TutorialGroupResource.java b/src/main/java/de/tum/in/www1/artemis/web/rest/tutorialgroups/TutorialGroupResource.java index f1009b9a172d..439763e7cf92 100644 --- a/src/main/java/de/tum/in/www1/artemis/web/rest/tutorialgroups/TutorialGroupResource.java +++ b/src/main/java/de/tum/in/www1/artemis/web/rest/tutorialgroups/TutorialGroupResource.java @@ -116,11 +116,11 @@ public ResponseEntity getTitle(@PathVariable Long tutorialGroupId) { } /** - * GET /courses/:courseId/tutorial-groups/campus-values : gets the campus values used for the tutorial groups of the course with the given id + * GET /courses/:courseId/tutorial-groups/campus-values : gets the campus values used for the tutorial groups of all tutorials where user is instructor * Note: Used for autocomplete in the client tutorial form * * @param courseId the id of the course to which the tutorial groups belong to - * @return ResponseEntity with status 200 (OK) and with body containing the unique campus values of the tutorial groups of the course + * @return ResponseEntity with status 200 (OK) and with body containing the unique campus values of all tutorials where user is instructor */ @GetMapping("/courses/{courseId}/tutorial-groups/campus-values") @EnforceAtLeastInstructor @@ -128,16 +128,17 @@ public ResponseEntity getTitle(@PathVariable Long tutorialGroupId) { public ResponseEntity> getUniqueCampusValues(@PathVariable Long courseId) { log.debug("REST request to get unique campus values used for tutorial groups in course : {}", courseId); var course = courseRepository.findByIdElseThrow(courseId); - authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, course, null); - return ResponseEntity.ok(tutorialGroupRepository.findAllUniqueCampusValuesInCourse(courseId)); + var user = userRepository.getUserWithGroupsAndAuthorities(); + authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, course, user); + return ResponseEntity.ok(tutorialGroupRepository.findAllUniqueCampusValuesInRegisteredCourse(user.getGroups())); } /** - * GET /courses/:courseId/tutorial-groups/language-values : gets the language values used for the tutorial groups of the course with the given id + * GET /courses/:courseId/tutorial-groups/language-values : gets the language values used for the tutorial groups of all tutorials where user is instructor * Note: Used for autocomplete in the client tutorial form * * @param courseId the id of the course to which the tutorial groups belong to - * @return ResponseEntity with status 200 (OK) and with body containing the unique language values of the tutorial groups of the course + * @return ResponseEntity with status 200 (OK) and with body containing the unique language values of all tutorials where user is instructor */ @GetMapping("/courses/{courseId}/tutorial-groups/language-values") @EnforceAtLeastInstructor @@ -145,8 +146,9 @@ public ResponseEntity> getUniqueCampusValues(@PathVariable Long cour public ResponseEntity> getUniqueLanguageValues(@PathVariable Long courseId) { log.debug("REST request to get unique language values used for tutorial groups in course : {}", courseId); var course = courseRepository.findByIdElseThrow(courseId); - authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, course, null); - return ResponseEntity.ok(tutorialGroupRepository.findAllUniqueLanguageValuesInCourse(courseId)); + var user = userRepository.getUserWithGroupsAndAuthorities(); + authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, course, user); + return ResponseEntity.ok(tutorialGroupRepository.findAllUniqueLanguageValuesInRegisteredCourse(user.getGroups())); } /** diff --git a/src/main/webapp/app/course/tutorial-groups/tutorial-groups-management/tutorial-groups/crud/create-tutorial-group/create-tutorial-group.component.ts b/src/main/webapp/app/course/tutorial-groups/tutorial-groups-management/tutorial-groups/crud/create-tutorial-group/create-tutorial-group.component.ts index 741596b0ef29..8d08d128296f 100644 --- a/src/main/webapp/app/course/tutorial-groups/tutorial-groups-management/tutorial-groups/crud/create-tutorial-group/create-tutorial-group.component.ts +++ b/src/main/webapp/app/course/tutorial-groups/tutorial-groups-management/tutorial-groups/crud/create-tutorial-group/create-tutorial-group.component.ts @@ -41,7 +41,6 @@ export class CreateTutorialGroupComponent implements OnInit, OnDestroy { createTutorialGroup(formData: TutorialGroupFormData) { const { title, teachingAssistant, additionalInformation, capacity, isOnline, language, campus, schedule } = formData; - this.tutorialGroupToCreate.title = title; this.tutorialGroupToCreate.teachingAssistant = teachingAssistant; this.tutorialGroupToCreate.additionalInformation = additionalInformation; diff --git a/src/main/webapp/app/course/tutorial-groups/tutorial-groups-management/tutorial-groups/crud/tutorial-group-form/tutorial-group-form.component.ts b/src/main/webapp/app/course/tutorial-groups/tutorial-groups-management/tutorial-groups/crud/tutorial-group-form/tutorial-group-form.component.ts index b9c98cb7d6bf..c4d619a8869d 100644 --- a/src/main/webapp/app/course/tutorial-groups/tutorial-groups-management/tutorial-groups/crud/tutorial-group-form/tutorial-group-form.component.ts +++ b/src/main/webapp/app/course/tutorial-groups/tutorial-groups-management/tutorial-groups/crud/tutorial-group-form/tutorial-group-form.component.ts @@ -256,7 +256,7 @@ export class TutorialGroupFormComponent implements OnInit, OnChanges, OnDestroy teachingAssistant: [undefined, [Validators.required]], capacity: [undefined, [Validators.min(1)]], isOnline: [false, [Validators.required]], - language: ['German', [Validators.required, Validators.maxLength(255)]], + language: [undefined, [Validators.required, Validators.maxLength(255)]], campus: [undefined, Validators.maxLength(255)], }); @@ -367,6 +367,13 @@ export class TutorialGroupFormComponent implements OnInit, OnChanges, OnDestroy ), ).subscribe((languages: string[]) => { this.languages = languages; + // default values for English & German + if (!languages.includes('English')) { + this.languages.push('English'); + } + if (!languages.includes('German')) { + this.languages.push('German'); + } }); } }