mateamt/src/Control/Settings.hs

45 lines
1.1 KiB
Haskell
Raw Permalink Normal View History

2022-07-24 14:50:06 +00:00
{-# LANGUAGE OverloadedStrings #-}
module Control.Settings where
import Control.Monad.Reader
import Servant
-- internal imports
import Types
import Model.Settings as Model
2022-07-30 23:43:46 +00:00
import Util (checkCapability, throwMissingAuth, throwWrongAuth, throwUnauthAccess)
2022-07-24 14:50:06 +00:00
getSettings
:: Maybe (Int, AuthMethod)
-> MateHandler Settings
getSettings Nothing = do
2022-07-30 23:43:46 +00:00
throwMissingAuth
2022-07-24 14:50:06 +00:00
getSettings (Just (uid, method)) = do
isManager <- checkCapability uid roleCanManageSettings
2022-07-30 23:43:46 +00:00
unless isManager throwUnauthAccess
if method `elem` [PrimaryPass, ChallengeResponse]
2022-07-24 14:50:06 +00:00
then do
conn <- asks rsConnection
selectSettings conn
else
2022-07-30 23:43:46 +00:00
throwWrongAuth
updateSettings
:: Maybe (Int, AuthMethod)
-> Settings
-> MateHandler NoContent
updateSettings Nothing _ =
2022-07-30 23:43:46 +00:00
throwMissingAuth
updateSettings (Just (uid, method)) newSettings = do
isManager <- checkCapability uid roleCanManageSettings
2022-07-30 23:43:46 +00:00
unless isManager throwUnauthAccess
if method `elem` [PrimaryPass, ChallengeResponse]
then do
conn <- asks rsConnection
void $ Model.updateSettings newSettings conn
return NoContent
else
2022-07-30 23:43:46 +00:00
throwWrongAuth