move utility funcitons to Util module

This commit is contained in:
nek0 2022-04-15 20:52:32 +02:00
parent 645f378bec
commit 853d825951
2 changed files with 18 additions and 21 deletions

View file

@ -11,6 +11,7 @@ import Control.Monad.Reader (asks)
import Types import Types
import Model import Model
import Util
roleList :: MateHandler [Role] roleList :: MateHandler [Role]
roleList = do roleList = do
@ -113,21 +114,3 @@ roleAssociationDelete Nothing _ =
throwError $ err401 throwError $ err401
{ errBody = "No Authentication present." { errBody = "No Authentication present."
} }
-- | This is the internal function to check a users authorization to do certain
-- actions
checkCapability
:: Int -- ^ User Id to check
-> (Role -> Bool) -- ^ Predicate to check
-> MateHandler Bool -- ^ Result
checkCapability uid accessRule = do
conn <- asks rsConnection
assocs <- selectUserAssociations uid conn
let rids = map roleAssociationRole assocs
roles <- selectRoleList rids conn
return $ any accessRule roles
notImplemented :: MateHandler a
notImplemented = throwError $ err501
{ errBody = "Function has not yet been implemented!"
}

View file

@ -30,11 +30,25 @@ import System.Directory (doesFileExist)
-- internal imports -- internal imports
import Model import Model
import Types import Types
import Control.User -- | This is the internal function to check a users authorization to do certain
import Types (UserDetails(userDetailsId)) -- actions
checkCapability
:: Int -- ^ User Id to check
-> (Role -> Bool) -- ^ Predicate to check
-> MateHandler Bool -- ^ Result
checkCapability uid accessRule = do
conn <- asks rsConnection
assocs <- selectUserAssociations uid conn
let rids = map roleAssociationRole assocs
roles <- selectRoleList rids conn
return $ any accessRule roles
notImplemented :: MateHandler a
notImplemented = throwError $ err501
{ errBody = "Function has not yet been implemented!"
}
printSql :: Default Unpackspec a a => Select a -> IO () printSql :: Default Unpackspec a a => Select a -> IO ()
printSql = putStrLn . fromMaybe "Empty query" . showSql printSql = putStrLn . fromMaybe "Empty query" . showSql