new admin notfifications are sent to fellow school admins as well now
This commit is contained in:
parent
75e2210ae5
commit
972bc11d46
@ -1,7 +1,7 @@
|
|||||||
School json
|
School json
|
||||||
name (CI Text)
|
name (CI Text)
|
||||||
shorthand (CI Text)
|
shorthand (CI Text) -- SchoolKey :: SchoolShorthand -> SchoolId
|
||||||
UniqueSchool name
|
UniqueSchool name
|
||||||
UniqueSchoolShorthand shorthand -- required for Normalisation of CI Text
|
UniqueSchoolShorthand shorthand -- required for Normalisation of CI Text
|
||||||
Primary shorthand -- newtype Key School = SchoolKey { unSchoolKey :: SchoolShorthand }
|
Primary shorthand -- newtype Key School = SchoolKey { unSchoolKey :: SchoolShorthand }
|
||||||
deriving Eq Show Generic
|
deriving Eq Show Generic
|
||||||
|
|||||||
@ -1,14 +1,16 @@
|
|||||||
module Database.Esqueleto.Utils where
|
module Database.Esqueleto.Utils where
|
||||||
|
|
||||||
-- | Convenience for using Esqueleto,
|
|
||||||
-- intended to be imported qualified
|
|
||||||
-- just like Esqueleto
|
|
||||||
|
|
||||||
import ClassyPrelude.Yesod hiding (isInfixOf, (||.))
|
import ClassyPrelude.Yesod hiding (isInfixOf, (||.))
|
||||||
import Data.Foldable as F
|
import Data.Foldable as F
|
||||||
import Database.Esqueleto as E
|
import Database.Esqueleto as E
|
||||||
|
|
||||||
|
|
||||||
|
{-|
|
||||||
|
Description : Convenience for using @Esqueleto@,
|
||||||
|
intended to be imported qualified
|
||||||
|
just like Esqueleto
|
||||||
|
-}
|
||||||
|
|
||||||
-- ezero = E.val (0 :: Int64)
|
-- ezero = E.val (0 :: Int64)
|
||||||
|
|
||||||
-- | Often needed with this concrete type
|
-- | Often needed with this concrete type
|
||||||
|
|||||||
@ -156,7 +156,8 @@ postAdminUserR uuid = do
|
|||||||
adminId <- requireAuthId
|
adminId <- requireAuthId
|
||||||
uid <- decrypt uuid
|
uid <- decrypt uuid
|
||||||
let fromSchoolList = Set.fromList . map (userAdminSchool . entityVal)
|
let fromSchoolList = Set.fromList . map (userAdminSchool . entityVal)
|
||||||
(User{..}, fromSchoolList -> adminSchools, userRights) <- runDB $ (,,)
|
let unValueRights (school, E.Value isAdmin, E.Value isLecturer) = (school,isAdmin,isLecturer)
|
||||||
|
(User{..}, fromSchoolList -> adminSchools, fmap unValueRights -> userRights) <- runDB $ (,,)
|
||||||
<$> get404 uid
|
<$> get404 uid
|
||||||
<*> selectList [UserAdminUser ==. adminId] []
|
<*> selectList [UserAdminUser ==. adminId] []
|
||||||
<*> E.select ( E.from $ \school -> do
|
<*> E.select ( E.from $ \school -> do
|
||||||
@ -172,7 +173,7 @@ postAdminUserR uuid = do
|
|||||||
-- above data is needed for both form generation and result evaluation
|
-- above data is needed for both form generation and result evaluation
|
||||||
let userRightsForm :: Form [(SchoolId, Bool, Bool)]
|
let userRightsForm :: Form [(SchoolId, Bool, Bool)]
|
||||||
userRightsForm csrf = do
|
userRightsForm csrf = do
|
||||||
boxRights <- forM userRights $ \(school@(Entity sid _), E.Value isAdmin, E.Value isLecturer) ->
|
boxRights <- forM userRights $ \(school@(Entity sid _), isAdmin, isLecturer) ->
|
||||||
if Set.member sid adminSchools
|
if Set.member sid adminSchools
|
||||||
then do
|
then do
|
||||||
cbAdmin <- mreq checkBoxField "" (Just isAdmin)
|
cbAdmin <- mreq checkBoxField "" (Just isAdmin)
|
||||||
@ -198,7 +199,7 @@ postAdminUserR uuid = do
|
|||||||
then void . insertUnique $ UserLecturer uid sid
|
then void . insertUnique $ UserLecturer uid sid
|
||||||
else deleteBy $ UniqueSchoolLecturer uid sid
|
else deleteBy $ UniqueSchoolLecturer uid sid
|
||||||
-- Note: deleteWhere would not work well here since we filter by adminSchools
|
-- Note: deleteWhere would not work well here since we filter by adminSchools
|
||||||
queueJob' . JobQueueNotification $ NotificationUserRightsUpdate uid
|
queueJob' . JobQueueNotification $ NotificationUserRightsUpdate uid (over _1 (schoolShorthand . entityVal) <$> userRights) -- original rights to check for difference
|
||||||
addMessageI Info MsgAccessRightsSaved
|
addMessageI Info MsgAccessRightsSaved
|
||||||
((result, formWidget),formEnctype) <- runFormPost userRightsForm
|
((result, formWidget),formEnctype) <- runFormPost userRightsForm
|
||||||
formResult result userRightsAction
|
formResult result userRightsAction
|
||||||
|
|||||||
@ -2,7 +2,9 @@ module Jobs.Handler.QueueNotification
|
|||||||
( dispatchJobQueueNotification
|
( dispatchJobQueueNotification
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Import
|
import Import hiding ((\\))
|
||||||
|
|
||||||
|
import Data.List ((\\))
|
||||||
|
|
||||||
import Jobs.Types
|
import Jobs.Types
|
||||||
|
|
||||||
@ -54,7 +56,19 @@ determineNotificationCandidates NotificationCorrectionsNotDistributed{nSheet}
|
|||||||
E.where_ $ sheet E.^. SheetId E.==. E.val nSheet
|
E.where_ $ sheet E.^. SheetId E.==. E.val nSheet
|
||||||
return user
|
return user
|
||||||
determineNotificationCandidates NotificationUserRightsUpdate{..}
|
determineNotificationCandidates NotificationUserRightsUpdate{..}
|
||||||
= selectList [UserId ==. nUser] []
|
= do
|
||||||
|
-- always send to affected user
|
||||||
|
affectedUser <- selectList [UserId ==. nUser] []
|
||||||
|
-- send to same-school admins only if there was an update
|
||||||
|
currentAdminSchools <- fmap (userAdminSchool . entityVal) <$> selectList [UserAdminUser ==. nUser] []
|
||||||
|
let oldAdminSchools = [ SchoolKey ssh | (ssh, True, _) <- originalRights ]
|
||||||
|
newAdminSchools = currentAdminSchools \\ oldAdminSchools
|
||||||
|
affectedAdmins <- E.select . E.from $ \(user `E.InnerJoin` admin) -> do
|
||||||
|
E.on $ admin E.^. UserAdminUser E.==. user E.^. UserId
|
||||||
|
E.where_ $ admin E.^. UserAdminSchool `E.in_` E.valList newAdminSchools
|
||||||
|
return user
|
||||||
|
return $ affectedUser <> affectedAdmins
|
||||||
|
|
||||||
|
|
||||||
classifyNotification :: Notification -> DB NotificationTrigger
|
classifyNotification :: Notification -> DB NotificationTrigger
|
||||||
classifyNotification NotificationSubmissionRated{..} = do
|
classifyNotification NotificationSubmissionRated{..} = do
|
||||||
|
|||||||
@ -12,8 +12,8 @@ import Handler.Utils.Mail
|
|||||||
import Text.Hamlet
|
import Text.Hamlet
|
||||||
-- import qualified Data.CaseInsensitive as CI
|
-- import qualified Data.CaseInsensitive as CI
|
||||||
|
|
||||||
dispatchNotificationUserRightsUpdate :: UserId -> UserId -> Handler ()
|
dispatchNotificationUserRightsUpdate :: UserId -> [(SchoolShorthand,Bool,Bool)]-> UserId -> Handler ()
|
||||||
dispatchNotificationUserRightsUpdate nUser jRecipient = userMailT jRecipient $ do
|
dispatchNotificationUserRightsUpdate nUser _originalRights jRecipient = userMailT jRecipient $ do
|
||||||
(User{..}, adminSchools, lecturerSchools) <- liftHandlerT . runDB $ do
|
(User{..}, adminSchools, lecturerSchools) <- liftHandlerT . runDB $ do
|
||||||
user <-getJust nUser
|
user <-getJust nUser
|
||||||
adminSchools <- getSchoolsOf nUser UserAdminSchool UserAdminUser
|
adminSchools <- getSchoolsOf nUser UserAdminSchool UserAdminUser
|
||||||
|
|||||||
@ -27,7 +27,7 @@ data Notification = NotificationSubmissionRated { nSubmission :: SubmissionId }
|
|||||||
| NotificationSheetInactive { nSheet :: SheetId }
|
| NotificationSheetInactive { nSheet :: SheetId }
|
||||||
| NotificationCorrectionsAssigned { nUser :: UserId, nSheet :: SheetId }
|
| NotificationCorrectionsAssigned { nUser :: UserId, nSheet :: SheetId }
|
||||||
| NotificationCorrectionsNotDistributed { nSheet :: SheetId }
|
| NotificationCorrectionsNotDistributed { nSheet :: SheetId }
|
||||||
| NotificationUserRightsUpdate { nUser :: UserId } -- User rights (admin, lecturer,...) were changed somehow
|
| NotificationUserRightsUpdate { nUser :: UserId, originalRights :: [(SchoolShorthand,Bool,Bool)] } -- User rights (admin, lecturer,...) were changed somehow
|
||||||
deriving (Eq, Ord, Show, Read, Generic, Typeable)
|
deriving (Eq, Ord, Show, Read, Generic, Typeable)
|
||||||
|
|
||||||
instance Hashable Job
|
instance Hashable Job
|
||||||
|
|||||||
@ -609,7 +609,6 @@ derivePersistFieldJSON ''NotificationSettings
|
|||||||
instance ToBackendKey SqlBackend record => Hashable (Key record) where
|
instance ToBackendKey SqlBackend record => Hashable (Key record) where
|
||||||
hashWithSalt s key = s `hashWithSalt` fromSqlKey key
|
hashWithSalt s key = s `hashWithSalt` fromSqlKey key
|
||||||
|
|
||||||
|
|
||||||
derivePersistFieldJSON ''MailLanguages
|
derivePersistFieldJSON ''MailLanguages
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user