diff --git a/src/Control/Settings.hs b/src/Control/Settings.hs index a8acd3d..ecf5fbd 100644 --- a/src/Control/Settings.hs +++ b/src/Control/Settings.hs @@ -8,7 +8,7 @@ import Servant -- internal imports import Types -import Model.Settings +import Model.Settings as Model import Util (checkCapability) getSettings @@ -28,3 +28,23 @@ getSettings (Just (uid, method)) = do 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" + }