From 8295e423d7108f8e8b3393aa92c70c102ba26524 Mon Sep 17 00:00:00 2001 From: johanneskarrer Date: Mon, 30 Sep 2024 15:13:18 +0200 Subject: [PATCH] fixed non-critical meiliStreamFilter bug, not filtering out private streams --- api/search.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/api/search.go b/api/search.go index 1b2cb8499..de1a38b04 100644 --- a/api/search.go +++ b/api/search.go @@ -350,7 +350,19 @@ func meiliSubtitleFilter(user *model.User, courses []model.Course) string { // Checking eligibility to search for courses and validation of model.Semester format is the caller's responsibility func meiliStreamFilter(c *gin.Context, user *model.User, semester model.Semester, courses []model.Course) string { if courses != nil { - return fmt.Sprintf("courseID IN %s", courseSliceToString(courses)) + administeredCourses := make([]model.Course, 0) + nonAdministeredCourses := make([]model.Course, 0) + for _, course := range courses { + if user.IsAdminOfCourse(course) { + administeredCourses = append(administeredCourses, course) + } else { + nonAdministeredCourses = append(nonAdministeredCourses, course) + } + } + if user == nil || len(administeredCourses) == 0 { + return fmt.Sprintf("courseID IN %s AND private = 0", courseSliceToString(nonAdministeredCourses)) + } + return fmt.Sprintf("(courseID IN %s OR (courseID IN %s AND private = 0))", courseSliceToString(administeredCourses), courseSliceToString(nonAdministeredCourses)) } semesterFilter := fmt.Sprintf("(year = %d AND semester = \"%s\")", semester.Year, semester.TeachingTerm)