45 lines
1.1 KiB
Haskell
45 lines
1.1 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, throwMissingAuth, throwWrongAuth, throwUnauthAccess)
|
|
|
|
getSettings
|
|
:: Maybe (Int, AuthMethod)
|
|
-> MateHandler Settings
|
|
getSettings Nothing = do
|
|
throwMissingAuth
|
|
getSettings (Just (uid, method)) = do
|
|
isManager <- checkCapability uid roleCanManageSettings
|
|
unless isManager throwUnauthAccess
|
|
if method `elem` [PrimaryPass, ChallengeResponse]
|
|
then do
|
|
conn <- asks rsConnection
|
|
selectSettings conn
|
|
else
|
|
throwWrongAuth
|
|
|
|
updateSettings
|
|
:: Maybe (Int, AuthMethod)
|
|
-> Settings
|
|
-> MateHandler NoContent
|
|
updateSettings Nothing _ =
|
|
throwMissingAuth
|
|
updateSettings (Just (uid, method)) newSettings = do
|
|
isManager <- checkCapability uid roleCanManageSettings
|
|
unless isManager throwUnauthAccess
|
|
if method `elem` [PrimaryPass, ChallengeResponse]
|
|
then do
|
|
conn <- asks rsConnection
|
|
void $ Model.updateSettings newSettings conn
|
|
return NoContent
|
|
else
|
|
throwWrongAuth
|