From 71846b63cfd4c2ee10851338ed38e5bf4102375f Mon Sep 17 00:00:00 2001 From: nek0 Date: Sun, 24 Jul 2022 17:50:18 +0200 Subject: [PATCH] expand controller module for the settings --- src/Control/Settings.hs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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" + }