2019-08-10 08:37:45 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module Control.Journal where
|
|
|
|
|
|
|
|
import Servant
|
|
|
|
|
2019-12-11 23:47:46 +00:00
|
|
|
import Control.Monad (void)
|
2019-10-14 20:50:42 +00:00
|
|
|
import Control.Monad.Reader (asks)
|
2020-07-31 21:01:57 +00:00
|
|
|
import Control.Monad.Extra (anyM)
|
2019-08-10 08:37:45 +00:00
|
|
|
|
|
|
|
-- internal imports
|
|
|
|
|
|
|
|
import Types
|
|
|
|
import Model.Journal
|
2020-07-31 21:01:57 +00:00
|
|
|
import Control.Role (checkCapability)
|
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
|
|
|
|
if method `elem` [PrimaryPass, ChallengeResponse] && maySeeJournal
|
2019-11-02 21:53:49 +00:00
|
|
|
then do
|
|
|
|
conn <- asks rsConnection
|
|
|
|
selectJournalEntries mlimit moffset conn
|
|
|
|
else
|
|
|
|
throwError $ err401
|
|
|
|
{ errBody = "Wrong Authentication present"
|
|
|
|
}
|
2019-08-10 08:37:45 +00:00
|
|
|
journalShow Nothing _ _ =
|
2019-09-11 11:54:18 +00:00
|
|
|
throwError $ err401
|
2019-08-10 08:37:45 +00:00
|
|
|
{ errBody = "No Authentication present"
|
|
|
|
}
|
2019-12-11 23:47:46 +00:00
|
|
|
|
|
|
|
journalCheck
|
|
|
|
:: Maybe (Int, AuthMethod)
|
|
|
|
-> JournalCashCheck
|
|
|
|
-> MateHandler ()
|
2020-07-31 21:01:57 +00:00
|
|
|
journalCheck (Just (uid, method)) check = do
|
|
|
|
mayCheckJournal <- checkCapability uid roleCanManageJournal
|
2020-08-24 07:43:22 +00:00
|
|
|
if method `elem` [PrimaryPass, ChallengeResponse] && mayCheckJournal
|
2019-12-11 23:47:46 +00:00
|
|
|
then do
|
|
|
|
conn <- asks rsConnection
|
|
|
|
void $ insertNewCashCheck check conn
|
|
|
|
else
|
|
|
|
throwError $ err401
|
|
|
|
{ errBody = "Wrong Authentication present"
|
|
|
|
}
|
|
|
|
journalCheck Nothing _ =
|
|
|
|
throwError $ err401
|
|
|
|
{ errBody = "No Authentication present"
|
|
|
|
}
|