expand controller module for the settings

This commit is contained in:
nek0 2022-07-24 17:50:18 +02:00
parent 9557b613f1
commit 71846b63cf

View file

@ -8,7 +8,7 @@ import Servant
-- internal imports -- internal imports
import Types import Types
import Model.Settings import Model.Settings as Model
import Util (checkCapability) import Util (checkCapability)
getSettings getSettings
@ -28,3 +28,23 @@ getSettings (Just (uid, method)) = do
throwError $ err401 throwError $ err401
{ errBody = "Wrong Authentication present" { 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"
}