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

Tutorial groups: Fix a usability issue when creating new tutorial for campus and language suggestions #7389

Merged
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public interface TutorialGroupRepository extends JpaRepository<TutorialGroup, Lo
WHERE tutorialGroup.course.id = :#{#courseId} AND tutorialGroup.campus IS NOT NULL""")
Set<String> findAllUniqueCampusValuesInCourse(@Param("courseId") Long courseId);

@Query("""
SELECT DISTINCT tutorialGroup.campus
FROM TutorialGroup tutorialGroup
WHERE tutorialGroup.course.instructorGroupName IN (:#{#userGroups}) AND tutorialGroup.campus IS NOT NULL""")
Set<String> findAllUniqueCampusValuesInRegisteredCourse(@Param("userGroups") Set<String> userGroups);

@Query("""
SELECT DISTINCT tutorialGroup.language
FROM TutorialGroup tutorialGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ public ResponseEntity<String> getTitle(@PathVariable Long tutorialGroupId) {
public ResponseEntity<Set<String>> 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);
var user = userRepository.getUserWithGroupsAndAuthorities();
authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, course, null);
return ResponseEntity.ok(tutorialGroupRepository.findAllUniqueCampusValuesInCourse(courseId));
return ResponseEntity.ok(tutorialGroupRepository.findAllUniqueCampusValuesInRegisteredCourse(user.getGroups()));
}

/**
Expand Down Expand Up @@ -161,7 +162,7 @@ public ResponseEntity<Set<String>> getUniqueLanguageValues(@PathVariable Long co
public ResponseEntity<List<TutorialGroup>> getAllForCourse(@PathVariable Long courseId) {
log.debug("REST request to get all tutorial groups of course with id: {}", courseId);
var course = courseRepository.findByIdElseThrow(courseId);
var user = userRepository.getUserWithGroupsAndAuthorities();
var user = userRepository.getUser();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The groups are needed in the next call (checkHasAtLeastRoleInCourseElseThrow), which currently leads to an additional database request.

authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.STUDENT, course, user);
// ToDo: Optimization Idea: Do not send all registered student information but just the number in a DTO
var tutorialGroups = tutorialGroupService.findAllForCourse(course, user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)],
});

Expand Down Expand Up @@ -367,6 +367,8 @@ export class TutorialGroupFormComponent implements OnInit, OnChanges, OnDestroy
),
).subscribe((languages: string[]) => {
this.languages = languages;
if (!languages.includes('English')) this.languages.push('English');
if (!languages.includes('Deutsch')) this.languages.push('Deutsch');
});
}
}