51 lines
1.2 KiB
Haskell
51 lines
1.2 KiB
Haskell
{-# LANGUAGE OverloadedStrings #-}
|
|
module Control.Settings where
|
|
|
|
import Control.Monad.Reader
|
|
|
|
import Servant
|
|
|
|
-- internal imports
|
|
|
|
import Types
|
|
import Model.Settings as Model
|
|
import Util (checkCapability)
|
|
|
|
getSettings
|
|
:: Maybe (Int, AuthMethod)
|
|
-> MateHandler Settings
|
|
getSettings Nothing = do
|
|
throwError $ err401
|
|
{ errBody = "No authentication present"
|
|
}
|
|
getSettings (Just (uid, method)) = do
|
|
isManager <- checkCapability uid roleCanManageSettings
|
|
if method `elem` [PrimaryPass, ChallengeResponse] && isManager
|
|
then do
|
|
conn <- asks rsConnection
|
|
selectSettings conn
|
|
else
|
|
throwError $ err401
|
|
{ errBody = "Wrong Authentication present"
|
|
}
|
|
|
|
updateSettings
|
|
:: Maybe (Int, AuthMethod)
|
|
-> Settings
|
|
-> MateHandler NoContent
|
|
updateSettings Nothing _ =
|
|
throwError $ err401
|
|
{ errBody = "No authentication present"
|
|
}
|
|
updateSettings (Just (uid, method)) newSettings = do
|
|
isManager <- checkCapability uid roleCanManageSettings
|
|
if method `elem` [PrimaryPass, ChallengeResponse] && isManager
|
|
then do
|
|
conn <- asks rsConnection
|
|
void $ Model.updateSettings newSettings conn
|
|
return NoContent
|
|
else
|
|
throwError $ err401
|
|
{ errBody = "Wrong Authentication present"
|
|
}
|