fix(users-add): upsert tutorial only if users not empty
This commit is contained in:
parent
662445e8cc
commit
e65d38898e
@ -73,7 +73,11 @@ postCAddUserR tid ssh csh = do
|
|||||||
| otherwise
|
| otherwise
|
||||||
= CourseR tid ssh csh CUsersR
|
= CourseR tid ssh csh CUsersR
|
||||||
formResultModal usersToRegister dest $ \AddUsers{..} -> hoist runDBJobs $ do
|
formResultModal usersToRegister dest $ \AddUsers{..} -> hoist runDBJobs $ do
|
||||||
uids <- registerUsers cid auUsers
|
avsUsers :: Map Text (Maybe UserId) <- sequenceA . flip Map.fromSet auUsers $ liftHandler . upsertAvsUser
|
||||||
|
let retrievedUsers = catMaybes $ Map.elems avsUsers
|
||||||
|
if
|
||||||
|
| uids@(_:_) <- retrievedUsers -> do
|
||||||
|
registerUsers cid avsUsers
|
||||||
for_ auTutorial $ \tutorialName -> lift $ do
|
for_ auTutorial $ \tutorialName -> lift $ do
|
||||||
-- TODO: move somewhere else
|
-- TODO: move somewhere else
|
||||||
now <- liftIO getCurrentTime
|
now <- liftIO getCurrentTime
|
||||||
@ -103,6 +107,8 @@ postCAddUserR tid ssh csh = do
|
|||||||
}
|
}
|
||||||
[]
|
[]
|
||||||
-- tell . pure <=< messageI Success . MsgCourseParticipantsRegisteredTutorial $ length uids
|
-- tell . pure <=< messageI Success . MsgCourseParticipantsRegisteredTutorial $ length uids
|
||||||
|
| otherwise
|
||||||
|
-> tell . pure =<< messageI Error MsgCourseParticipantsRegisterNoneGiven
|
||||||
|
|
||||||
let heading = prependCourseTitle tid ssh csh MsgCourseParticipantsRegisterHeading
|
let heading = prependCourseTitle tid ssh csh MsgCourseParticipantsRegisterHeading
|
||||||
|
|
||||||
@ -114,19 +120,17 @@ postCAddUserR tid ssh csh = do
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
registerUsers :: CourseId -> Set Text -> WriterT [Message] (YesodJobDB UniWorX) [UserId]
|
--confirmAddUser :: ()
|
||||||
registerUsers cid auUsers = do
|
--confirmAddUser = do
|
||||||
avsUsers :: Map Text (Maybe UserId) <- sequenceA . flip Map.fromSet auUsers $
|
-- siteLayoutMsg MsgCourseParticipantsRegisterConfirmationHeading $ do
|
||||||
liftHandler . upsertAvsUser -- TODO: upsertAvsUser should return whole Entity
|
-- setTitleI MsgCourseParticipantsRegisterConfirmationHeading
|
||||||
|
|
||||||
if
|
|
||||||
| null avsUsers
|
|
||||||
-> tell . pure =<< messageI Error MsgCourseParticipantsRegisterNoneGiven
|
|
||||||
| otherwise
|
|
||||||
-- register retrieved users
|
|
||||||
-> tell <=< lift . addParticipantsResultMessages <=< lift . execWriterT . mapM_ (registerUser cid) $ Map.toList avsUsers
|
|
||||||
|
|
||||||
return . catMaybes $ Map.elems avsUsers
|
|
||||||
|
registerUsers :: CourseId -> Map Text (Maybe UserId) -> WriterT [Message] (YesodJobDB UniWorX) ()
|
||||||
|
registerUsers cid users
|
||||||
|
| null users = tell . pure =<< messageI Error MsgCourseParticipantsRegisterNoneGiven
|
||||||
|
| otherwise = tell <=< lift . addParticipantsResultMessages <=< lift . execWriterT . mapM_ (registerUser cid) $ Map.toList users
|
||||||
|
|
||||||
|
|
||||||
addParticipantsResultMessages :: (MonadHandler m, HandlerSite m ~ UniWorX)
|
addParticipantsResultMessages :: (MonadHandler m, HandlerSite m ~ UniWorX)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user