Skip to content

Commit a00c1b5

Browse files
committed
simplify authorization
1 parent 63c6925 commit a00c1b5

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

src/main/java/de/tum/cit/aet/artemis/lecture/domain/LectureUnit.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ public void setCompetencyLinks(Set<CompetencyLectureUnitLink> competencyLinks) {
111111
this.competencyLinks = competencyLinks;
112112
}
113113

114-
// NOTE: we explicitly do not add LectureTranscription here to avoid Hibernate loading issues because of its OneToOne relationship which is automatically EAGER and cannot be set
115-
// to LAZY
114+
// NOTE: we explicitly do not add LectureTranscription here to avoid Hibernate issues because of its OneToOne relationship which is EAGER and cannot be set to LAZY
116115

117116
@JsonIgnore(false)
118117
@JsonProperty("completed")

src/main/java/de/tum/cit/aet/artemis/lecture/web/LectureResource.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import de.tum.cit.aet.artemis.core.security.annotations.EnforceAtLeastInstructor;
5151
import de.tum.cit.aet.artemis.core.security.annotations.EnforceAtLeastStudent;
5252
import de.tum.cit.aet.artemis.core.security.annotations.enforceRoleInCourse.EnforceAtLeastInstructorInCourse;
53+
import de.tum.cit.aet.artemis.core.security.annotations.enforceRoleInCourse.EnforceAtLeastStudentInCourse;
5354
import de.tum.cit.aet.artemis.core.service.AuthorizationCheckService;
5455
import de.tum.cit.aet.artemis.core.util.HeaderUtil;
5556
import de.tum.cit.aet.artemis.exercise.domain.Exercise;
@@ -212,13 +213,10 @@ public ResponseEntity<Set<Lecture>> getLecturesForCourse(@PathVariable Long cour
212213
* @return the ResponseEntity with status 200 (OK) and the set of lectures in body
213214
*/
214215
@GetMapping("courses/{courseId}/lectures-with-slides")
215-
@EnforceAtLeastStudent
216+
@EnforceAtLeastStudentInCourse
216217
public ResponseEntity<List<LectureDTO>> getLecturesWithSlidesForCourse(@PathVariable Long courseId) {
217218
log.info("Getting all lectures with slides for course {}", courseId);
218219
long start = System.currentTimeMillis();
219-
var course = courseRepository.findByIdElseThrow(courseId);
220-
var user = userRepository.getUserWithGroupsAndAuthorities();
221-
authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.STUDENT, course, user);
222220

223221
var lectures = lectureRepository.findAllByCourseIdWithAttachmentsAndLectureUnits(courseId).stream().filter(Lecture::isVisibleToStudents).collect(Collectors.toSet());
224222
Set<Long> attachmentUnitIds = lectures.stream().flatMap(lecture -> lecture.getLectureUnits().stream()).filter(lectureUnit -> lectureUnit instanceof AttachmentUnit)
@@ -230,20 +228,15 @@ public ResponseEntity<List<LectureDTO>> getLecturesWithSlidesForCourse(@PathVari
230228
// Group slides by attachment unit id to combine them into the DTOs
231229
Map<Long, List<SlideDTO>> slidesByAttachmentUnitId = slides.stream().collect(Collectors.groupingBy(SlideDTO::attachmentUnitId));
232230
// Convert visible lectures to DTOs (filtering active attachments) and add non hidden slides to the DTOs
233-
List<LectureDTO> lectureDTOs = lectures.stream()
234-
.map(LectureDTO::from)
235-
.sorted(Comparator.comparingLong(LectureDTO::id))
236-
.toList();
237-
231+
List<LectureDTO> lectureDTOs = lectures.stream().map(LectureDTO::from).sorted(Comparator.comparingLong(LectureDTO::id)).toList();
232+
238233
lectureDTOs.forEach(lectureDTO -> {
239234
for (AttachmentUnitDTO attachmentUnitDTO : lectureDTO.lectureUnits) {
240235
List<SlideDTO> slidesForAttachmentUnit = slidesByAttachmentUnitId.get(attachmentUnitDTO.id);
241236
if (slidesForAttachmentUnit != null) {
242237
// remove unnecessary fields from the slide DTOs
243-
var finalSlides = slidesForAttachmentUnit.stream()
244-
.map(slideDTO -> new SlideDTO(slideDTO.id(), slideDTO.slideNumber(), null, null))
245-
.sorted(Comparator.comparingInt(SlideDTO::slideNumber))
246-
.toList();
238+
var finalSlides = slidesForAttachmentUnit.stream().map(slideDTO -> new SlideDTO(slideDTO.id(), slideDTO.slideNumber(), null, null))
239+
.sorted(Comparator.comparingInt(SlideDTO::slideNumber)).toList();
247240
attachmentUnitDTO.slides.addAll(finalSlides);
248241
}
249242
}

0 commit comments

Comments
 (0)