From ec626d5a0847a346073472ed4932b37cafa9c468 Mon Sep 17 00:00:00 2001 From: "Yann Esposito (Yogsototh)" Date: Mon, 1 Apr 2019 23:31:41 +0200 Subject: [PATCH] update --- src/Aggreact/Authorization.hs | 12 ++++++------ src/Aggreact/User.hs | 11 +++++------ src/Database/Store.hs | 1 - 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/Aggreact/Authorization.hs b/src/Aggreact/Authorization.hs index 3780bb5..8f96aa7 100644 --- a/src/Aggreact/Authorization.hs +++ b/src/Aggreact/Authorization.hs @@ -34,11 +34,11 @@ where import Protolude -import Aggreact.User (User,NewUser(..),Role(..)) +import Aggreact.User (NewUser (..), Role (..), User) +import Database.Store (Entity (..)) import Servant (Handler) import Servant.Errors (unauthorized) -import Database.Store (Entity(..)) data AuthorizationStrategy = Anybody @@ -52,7 +52,7 @@ newtype AuthorizationHandler = } data Scope = Scope { resource :: Text - , access :: Access } + , access :: Access } data Access = Read | Write | AdminAccess newAuthorizationHandler :: AuthorizationStrategy -> IO AuthorizationHandler @@ -67,7 +67,7 @@ _checkAccess Anybody (Scope _ Write) _ = pure () _checkAccess Anybody (Scope _ AdminAccess) (Just (Entity _ u _)) = case role u of Admin -> pure () - _ -> unauthorized "Need admin privilege" + _ -> unauthorized "Need admin privilege" _checkAccess Anybody (Scope _ AdminAccess) _ = unauthorized "Need admin privilege" @@ -78,7 +78,7 @@ _checkAccess LoggedInOnly (Scope _ Write) (Just _) = pure () _checkAccess LoggedInOnly (Scope _ AdminAccess) (Just (Entity _ u _)) = case role u of Admin -> pure () - _ -> unauthorized "Only for admins" + _ -> unauthorized "Only for admins" _checkAccess ProgressiveTrust (Scope _ Read) Nothing = pure () _checkAccess ProgressiveTrust (Scope _ _) Nothing = unauthorized "You must log in" @@ -87,4 +87,4 @@ _checkAccess ProgressiveTrust (Scope _ Write) (Just _) = pure () _checkAccess ProgressiveTrust (Scope _ AdminAccess) (Just (Entity _ u _)) = case role u of Admin -> pure () - _ -> unauthorized "Only for admins" + _ -> unauthorized "Only for admins" diff --git a/src/Aggreact/User.hs b/src/Aggreact/User.hs index 346a153..192023f 100644 --- a/src/Aggreact/User.hs +++ b/src/Aggreact/User.hs @@ -48,7 +48,7 @@ import Aggreact.Html (boilerplate, cvt, urlEncode) import qualified Crypto.Scrypt as Crypt import Data.Aeson (FromJSON (..), ToJSON (..)) import Data.Data (Data (..)) -import qualified Data.UUID as UUID +import qualified Data.UUID as UUID import Database.SQLite.Simple (NamedParam (..), SQLData (..)) import Database.SQLite.Simple.FromField (FromField (..), @@ -156,7 +156,6 @@ instance ToField Role where toField = toField . (show :: Role -> Text) instance (ToSQLiteFieldTypeList rest) => ToSQLiteFieldTypeList (Role ': rest) where toSqliteTypes _ = "TEXT":toSqliteTypes (Proxy :: Proxy rest) - -- For HTTP deriving anyclass instance ToJSON NewUser deriving anyclass instance FromJSON NewUser @@ -282,9 +281,9 @@ getUserByNick muser userHandler userNick = do SQL.SR (SQL.Paginated mu _ _) <- liftIO $ searchUsers userHandler (Filter {params = ["nick" := userNick]}) case mu of - [] -> Err.notFound "user not found" - [u] -> pure (UserPage u muser) - _ -> Err.internalServerError "Incoherent DB" + [] -> Err.notFound "user not found" + [u] -> pure (UserPage u muser) + _ -> Err.internalServerError "Incoherent DB" getUserById :: Maybe User -> UserHandler -> Id -> Handler UserPage getUserById muser userHandler userId = do @@ -295,7 +294,7 @@ getUserById muser userHandler userId = do data UserPage = UserPage - { user :: User + { user :: User , muser :: Maybe User } diff --git a/src/Database/Store.hs b/src/Database/Store.hs index daca4e5..767c5ad 100644 --- a/src/Database/Store.hs +++ b/src/Database/Store.hs @@ -68,7 +68,6 @@ import qualified Data.UUID as UUID import qualified Generics.SOP as SOP import Servant.Auth.Server (FromJWT, ToJWT) import qualified Web.HttpApiData as FormI -import qualified Service.Service as Serv -- | This is the ID type, it is like @Text@. instance StringConv UUID [Char] where strConv l = strConv l . UUID.toString