48 lines
1.1 KiB
Haskell
48 lines
1.1 KiB
Haskell
{-# LANGUAGE OverloadedStrings #-}
|
|
module Control.Journal where
|
|
|
|
import Servant
|
|
|
|
import Control.Monad (void, unless)
|
|
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
|
|
unless maySeeJournal throwUnauthAccess
|
|
if method `elem` [PrimaryPass, ChallengeResponse]
|
|
then do
|
|
conn <- asks rsConnection
|
|
selectJournalEntries mlimit moffset conn
|
|
else
|
|
throwWrongAuth
|
|
journalShow Nothing _ _ =
|
|
throwMissingAuth
|
|
|
|
journalCheck
|
|
:: Maybe (Int, AuthMethod)
|
|
-> JournalCashCheck
|
|
-> MateHandler NoContent
|
|
journalCheck (Just (uid, method)) check = do
|
|
mayCheckJournal <- checkCapability uid roleCanManageJournal
|
|
unless mayCheckJournal throwUnauthAccess
|
|
if method `elem` [PrimaryPass, ChallengeResponse]
|
|
then do
|
|
conn <- asks rsConnection
|
|
void $ insertNewCashCheck check conn
|
|
return NoContent
|
|
else
|
|
throwWrongAuth
|
|
journalCheck Nothing _ =
|
|
throwMissingAuth
|