From d7d1f273036a2dba5113c04319cdf075fbdb829c Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Mon, 30 Sep 2019 16:18:48 +0200 Subject: [PATCH] fix(course-edit): edit courses without being school-wide lecturer Fixes #464 --- src/Handler/Course/Edit.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Handler/Course/Edit.hs b/src/Handler/Course/Edit.hs index fcb45369e..a670a8e1f 100644 --- a/src/Handler/Course/Edit.hs +++ b/src/Handler/Course/Edit.hs @@ -107,12 +107,13 @@ makeCourseForm miButtonAction template = identifyForm FIDcourse . validateFormDB MsgRenderer mr <- getMsgRenderer uid <- liftHandler requireAuthId - (lecturerSchools, adminSchools) <- liftHandler . runDB $ do + (lecturerSchools, adminSchools, oldSchool) <- liftHandler . runDB $ do lecturerSchools <- map (userFunctionSchool . entityVal) <$> selectList [UserFunctionUser ==. uid, UserFunctionFunction <-. [SchoolLecturer]] [] protoAdminSchools <- map (userFunctionSchool . entityVal) <$> selectList [UserFunctionUser ==. uid, UserFunctionFunction <-. [SchoolAdmin]] [] adminSchools <- filterM (hasWriteAccessTo . flip SchoolR SchoolEditR) protoAdminSchools - return (lecturerSchools, adminSchools) - let userSchools = nub $ lecturerSchools ++ adminSchools + oldSchool <- forM (cfCourseId =<< template) $ fmap courseSchool . getJust + return (lecturerSchools, adminSchools, oldSchool) + let userSchools = nub . maybe id (:) oldSchool $ lecturerSchools ++ adminSchools termsField <- case template of -- Change of term is only allowed if user may delete the course (i.e. no participants) or admin