2019-08-10 08:37:45 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module Control.Journal where
|
|
|
|
|
|
|
|
import Servant
|
|
|
|
|
2022-07-30 23:43:46 +00:00
|
|
|
import Control.Monad (void, unless)
|
2019-10-14 20:50:42 +00:00
|
|
|
import Control.Monad.Reader (asks)
|
2019-08-10 08:37:45 +00:00
|
|
|
|
|
|
|
-- internal imports
|
|
|
|
|
|
|
|
import Types
|
|
|
|
import Model.Journal
|
2022-04-15 19:06:18 +00:00
|
|
|
import Util
|
2019-08-10 08:37:45 +00:00
|
|
|
|
|
|
|
journalShow
|
2019-09-15 12:59:22 +00:00
|
|
|
:: Maybe (Int, AuthMethod)
|
2019-08-10 08:37:45 +00:00
|
|
|
-> Maybe Int
|
|
|
|
-> Maybe Int
|
|
|
|
-> MateHandler [JournalEntry]
|
2020-07-31 21:01:57 +00:00
|
|
|
journalShow (Just (uid, method)) mlimit moffset = do
|
2020-10-01 17:11:52 +00:00
|
|
|
maySeeJournal <- checkCapability uid roleCanManageJournal
|
2022-07-30 23:43:46 +00:00
|
|
|
unless maySeeJournal throwUnauthAccess
|
|
|
|
if method `elem` [PrimaryPass, ChallengeResponse]
|
2019-11-02 21:53:49 +00:00
|
|
|
then do
|
|
|
|
conn <- asks rsConnection
|
|
|
|
selectJournalEntries mlimit moffset conn
|
|
|
|
else
|
2022-07-30 23:43:46 +00:00
|
|
|
throwWrongAuth
|
2019-08-10 08:37:45 +00:00
|
|
|
journalShow Nothing _ _ =
|
2022-07-30 23:43:46 +00:00
|
|
|
throwMissingAuth
|
2019-12-11 23:47:46 +00:00
|
|
|
|
|
|
|
journalCheck
|
|
|
|
:: Maybe (Int, AuthMethod)
|
|
|
|
-> JournalCashCheck
|
2022-07-17 19:28:22 +00:00
|
|
|
-> MateHandler NoContent
|
2020-07-31 21:01:57 +00:00
|
|
|
journalCheck (Just (uid, method)) check = do
|
|
|
|
mayCheckJournal <- checkCapability uid roleCanManageJournal
|
2022-07-30 23:43:46 +00:00
|
|
|
unless mayCheckJournal throwUnauthAccess
|
|
|
|
if method `elem` [PrimaryPass, ChallengeResponse]
|
2019-12-11 23:47:46 +00:00
|
|
|
then do
|
|
|
|
conn <- asks rsConnection
|
|
|
|
void $ insertNewCashCheck check conn
|
2022-07-17 19:28:22 +00:00
|
|
|
return NoContent
|
2019-12-11 23:47:46 +00:00
|
|
|
else
|
2022-07-30 23:43:46 +00:00
|
|
|
throwWrongAuth
|
2019-12-11 23:47:46 +00:00
|
|
|
journalCheck Nothing _ =
|
2022-07-30 23:43:46 +00:00
|
|
|
throwMissingAuth
|