diff --git a/src/Database/Esqueleto/Utils.hs b/src/Database/Esqueleto/Utils.hs index 152d506ae..9c09b41f9 100644 --- a/src/Database/Esqueleto/Utils.hs +++ b/src/Database/Esqueleto/Utils.hs @@ -280,7 +280,8 @@ subSelectOr q = parens . E.subSelectUnsafe $ flip (E.unsafeSqlAggregateFunction parens :: E.SqlExpr (E.Value a) -> E.SqlExpr (E.Value a) parens = E.unsafeSqlFunction "" --- | Workaround for Esqueleto-Bug not placing parenthesis after NOT, see #155 +-- | Workaround for Esqueleto-Bug not placing parenthesis after NOT. +-- This leads to erroneous filters. For examples, see DevOps #1970 not__ :: E.SqlExpr (E.Value Bool) -> E.SqlExpr (E.Value Bool) not__ = E.not_ . parens diff --git a/src/Handler/Course/Edit.hs b/src/Handler/Course/Edit.hs index 1e06c919b..17fe34a67 100644 --- a/src/Handler/Course/Edit.hs +++ b/src/Handler/Course/Edit.hs @@ -70,7 +70,7 @@ courseToForm (Entity cid Course{..}) lecs lecInvites qualis = CourseForm , cfDeRegUntil = courseDeregisterUntil , cfLecturers = [Right (lecturerUser, lecturerType) | Lecturer{..} <- lecs] ++ [Left (email, mType) | (email, InvDBDataLecturer mType) <- Map.toList lecInvites ] - -- TODO: Filterung nach aktueller Schule, da ansonsten ein Sicherheitleck droht! Siehe #150 + -- TODO: Filterung nach aktueller Schule, da ansonsten ein Sicherheitleck droht! Siehe auch DevOps #1878 , cfQualis = [ (courseQualificationQualification, courseQualificationSortOrder) | CourseQualification{..} <- qualis, courseQualificationCourse == cid ] } @@ -471,7 +471,7 @@ upsertCourseQualifications uid cid qualis = do let newQualis = Map.fromList qualis oldQualis <- Map.fromList . fmap (\Entity{entityKey=k, entityVal=CourseQualification{..}} -> (courseQualificationQualification, (k, courseQualificationSortOrder))) <$> selectList [CourseQualificationCourse ==. cid] [Asc CourseQualificationQualification] - -- NOTE: CourseQualification allow the immediate assignment of these qualifications to any enrolled user. Hence SchoolAdmins must not be allowed to assign school-foreign qualifications, see #150 + -- NOTE: CourseQualification allow the immediate assignment of these qualifications to any enrolled user. Hence SchoolAdmins must not be allowed to assign school-foreign qualifications here! Also see DevOps #1878 okSchools <- Set.fromList . fmap (userFunctionSchool . entityVal) <$> selectList [UserFunctionUser ==. uid, UserFunctionFunction <-. [SchoolAdmin, SchoolLecturer]] [Asc UserFunctionSchool] {- Some debugging due to an error caused by using fromDistinctAscList with violated precondition: diff --git a/src/Handler/Health/Interface.hs b/src/Handler/Health/Interface.hs index 58cfcbe4a..e19945f1b 100644 --- a/src/Handler/Health/Interface.hs +++ b/src/Handler/Health/Interface.hs @@ -150,7 +150,7 @@ mkInterfaceLogTable interfs@(reqIfs, banIfs) = do ] unless (null reqIfs) $ E.where_ $ matchUIH reqIfs unless (null banIfs) $ E.where_ $ matchUIHnot banIfs - -- unless (null banIfs) $ E.where_ $ E.not_ $ matchUIH banIfs -- !!! DOES NOT WORK !!! Yields strange results, see #155 + -- unless (null banIfs) $ E.where_ $ E.not_ $ matchUIH banIfs -- !!! DOES NOT WORK !!! Yields strange results, see DevOps #1970 -- unless (null banIfs) $ E.where_ $ E.not_ $ E.parens $ matchUIH banIfs -- WORKS OKAY -- E.where_ $ E.not_ (ilog E.^. InterfaceLogInterface E.==. E.val "LMS" E.&&. ilog E.^. InterfaceLogSubtype E.==. E.val (sanitize "F")) -- BAD All missing, except for "Printer" "F" -- E.where_ $ E.not_ $ E.parens (ilog E.^. InterfaceLogInterface E.==. E.val "LMS" E.&&. ilog E.^. InterfaceLogSubtype E.==. E.val (sanitize "F")) -- WORKS OKAY diff --git a/src/Utils.hs b/src/Utils.hs index ff0a98212..4f20248d3 100644 --- a/src/Utils.hs +++ b/src/Utils.hs @@ -967,12 +967,13 @@ whenIsJust :: Monad m => Maybe a -> (a -> m ()) -> m () whenIsJust (Just x) f = f x whenIsJust Nothing _ = return () --- | -- Often a more convenient argument order as compared to the not quite identical `maybeM` +-- | Often a more convenient argument order as compared to the not quite identical `maybeM`. +-- -- @ -- ifNothingM m d a = maybe (return d) a m -- @ -ifNothingM :: Monad m => Maybe a -> b -> (a -> m b) -> m b -ifNothingM Nothing dft _ = return dft +ifNothingM :: Applicative m => Maybe a -> b -> (a -> m b) -> m b +ifNothingM Nothing dft _ = pure dft ifNothingM (Just x) _ act = act x maybePositive :: (Num a, Ord a) => a -> Maybe a -- convenient for Shakespeare: one $maybe instead of $with & $if