54 lines
1.3 KiB
Haskell
54 lines
1.3 KiB
Haskell
{-# LANGUAGE OverloadedStrings #-}
|
|
module Control.Journal where
|
|
|
|
import Servant
|
|
|
|
import Control.Monad (void)
|
|
import Control.Monad.Reader (asks)
|
|
|
|
-- internal imports
|
|
|
|
import Types
|
|
import Model.Journal
|
|
import Util
|
|
|
|
journalShow
|
|
:: Maybe (Int, AuthMethod)
|
|
-> Maybe Int
|
|
-> Maybe Int
|
|
-> MateHandler [JournalEntry]
|
|
journalShow (Just (uid, method)) mlimit moffset = do
|
|
maySeeJournal <- checkCapability uid roleCanManageJournal
|
|
if method `elem` [PrimaryPass, ChallengeResponse] && maySeeJournal
|
|
then do
|
|
conn <- asks rsConnection
|
|
selectJournalEntries mlimit moffset conn
|
|
else
|
|
throwError $ err401
|
|
{ errBody = "Wrong Authentication present"
|
|
}
|
|
journalShow Nothing _ _ =
|
|
throwError $ err401
|
|
{ errBody = "No Authentication present"
|
|
}
|
|
|
|
journalCheck
|
|
:: Maybe (Int, AuthMethod)
|
|
-> JournalCashCheck
|
|
-> MateHandler NoContent
|
|
journalCheck (Just (uid, method)) check = do
|
|
mayCheckJournal <- checkCapability uid roleCanManageJournal
|
|
if method `elem` [PrimaryPass, ChallengeResponse] && mayCheckJournal
|
|
then do
|
|
conn <- asks rsConnection
|
|
void $ insertNewCashCheck check conn
|
|
return NoContent
|
|
else
|
|
throwError $ err401
|
|
{ errBody = "Wrong Authentication present"
|
|
}
|
|
journalCheck Nothing _ =
|
|
throwError $ err401
|
|
{ errBody = "No Authentication present"
|
|
}
|