Commit 28a3fd84 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[MULTIUSER DEMO] insertion and config/hack.

parent b3d13d65
Pipeline #215 canceled with stage
...@@ -40,13 +40,11 @@ import Gargantext.Database.Utils (Cmd) ...@@ -40,13 +40,11 @@ import Gargantext.Database.Utils (Cmd)
import Gargantext.Prelude hiding (reverse) import Gargantext.Prelude hiding (reverse)
import Test.QuickCheck (elements, oneof) import Test.QuickCheck (elements, oneof)
import Test.QuickCheck.Arbitrary (Arbitrary, arbitrary) import Test.QuickCheck.Arbitrary (Arbitrary, arbitrary)
import Gargantext.Core.Types.Individu (Username, Password, arbitraryUsername, arbitraryPassword)
--------------------------------------------------- ---------------------------------------------------
-- | Main types for AUTH API -- | Main types for AUTH API
type Username = Text
type Password = Text
data AuthRequest = AuthRequest { _authReq_username :: Username data AuthRequest = AuthRequest { _authReq_username :: Username
, _authReq_password :: Password , _authReq_password :: Password
} }
...@@ -76,18 +74,12 @@ type TreeId = NodeId ...@@ -76,18 +74,12 @@ type TreeId = NodeId
data CheckAuth = InvalidUser | InvalidPassword | Valid Token TreeId data CheckAuth = InvalidUser | InvalidPassword | Valid Token TreeId
deriving (Eq) deriving (Eq)
arbitraryUsername :: [Username]
arbitraryUsername = ["gargantua", "user1", "user2"]
arbitraryPassword :: [Password]
arbitraryPassword = map reverse arbitraryUsername
checkAuthRequest :: Username -> Password -> Cmd err CheckAuth checkAuthRequest :: Username -> Password -> Cmd err CheckAuth
checkAuthRequest u p checkAuthRequest u p
| not (u `elem` arbitraryUsername) = pure InvalidUser | not (u `elem` arbitraryUsername) = pure InvalidUser
| u /= reverse p = pure InvalidPassword | u /= reverse p = pure InvalidPassword
| otherwise = do | otherwise = do
muId <- getRoot u muId <- getRoot "user1"
pure $ maybe InvalidUser (Valid "token" . _node_id) $ head muId pure $ maybe InvalidUser (Valid "token" . _node_id) $ head muId
auth :: AuthRequest -> Cmd err AuthResponse auth :: AuthRequest -> Cmd err AuthResponse
......
...@@ -11,13 +11,31 @@ Individu defintions ...@@ -11,13 +11,31 @@ Individu defintions
-} -}
{-# OPTIONS_GHC -fno-warn-name-shadowing #-} {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
module Gargantext.Core.Types.Individu module Gargantext.Core.Types.Individu
where where
import Data.Text (Text) import Gargantext.Prelude hiding (reverse)
import Data.Text (Text, pack, reverse)
type Username = Text type Username = Text
type Password = Text
type UsernameMaster = Username type UsernameMaster = Username
type UsernameSimple = Username type UsernameSimple = Username
arbitraryUsername :: [Username]
arbitraryUsername = ["gargantua"] <> users
where
users = zipWith (\a b -> a <> (pack . show) b)
(repeat "user") ([1..20]::[Int])
arbitraryPassword :: [Password]
arbitraryPassword = map reverse arbitraryUsername
...@@ -219,7 +219,7 @@ extractNgramsT doc = do ...@@ -219,7 +219,7 @@ extractNgramsT doc = do
let institutes = map text2ngrams $ maybe ["Nothing"] (map toSchoolName . (splitOn ", ")) $ _hyperdataDocument_institutes doc let institutes = map text2ngrams $ maybe ["Nothing"] (map toSchoolName . (splitOn ", ")) $ _hyperdataDocument_institutes doc
let authors = map text2ngrams $ maybe ["Nothing"] (splitOn ", ") $ _hyperdataDocument_authors doc let authors = map text2ngrams $ maybe ["Nothing"] (splitOn ", ") $ _hyperdataDocument_authors doc
let leText = catMaybes [_hyperdataDocument_title doc, _hyperdataDocument_abstract doc] let leText = catMaybes [_hyperdataDocument_title doc, _hyperdataDocument_abstract doc]
terms' <- map text2ngrams <$> map (intercalate " " . _terms_label) <$> concat <$> liftIO (extractTerms (Mono EN) leText) terms' <- map text2ngrams <$> map (intercalate " " . _terms_label) <$> concat <$> liftIO (extractTerms (Multi EN) leText)
pure $ DM.fromList $ [(source, DM.singleton Sources 1)] pure $ DM.fromList $ [(source, DM.singleton Sources 1)]
<> [(i', DM.singleton Institutes 1) | i' <- institutes ] <> [(i', DM.singleton Institutes 1) | i' <- institutes ]
......
...@@ -33,11 +33,13 @@ import Data.Profunctor.Product.TH (makeAdaptorAndInstance) ...@@ -33,11 +33,13 @@ import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
import Data.Text (Text) import Data.Text (Text)
import Data.Time (UTCTime) import Data.Time (UTCTime)
import GHC.Show(Show(..)) import GHC.Show(Show(..))
import Gargantext.Core.Types.Individu (Username) import Gargantext.Core.Types.Individu (Username, arbitraryUsername)
import Gargantext.Database.Utils import Gargantext.Database.Utils
import Gargantext.Prelude import Gargantext.Prelude
import Opaleye import Opaleye
------------------------------------------------------------------------
------------------------------------------------------------------------ ------------------------------------------------------------------------
type UserId = Int type UserId = Int
...@@ -106,29 +108,17 @@ userTable = Table "auth_user" (pUser User { user_id = optional "id" ...@@ -106,29 +108,17 @@ userTable = Table "auth_user" (pUser User { user_id = optional "id"
insertUsers :: [UserWrite] -> Cmd err Int64 insertUsers :: [UserWrite] -> Cmd err Int64
insertUsers us = mkCmd $ \c -> runInsertMany c userTable us insertUsers us = mkCmd $ \c -> runInsertMany c userTable us
gargantuaUser :: UserWrite
gargantuaUser = User (Nothing) (pgStrictText "password")
(Nothing) (pgBool True) (pgStrictText "gargantua")
(pgStrictText "first_name")
(pgStrictText "last_name")
(pgStrictText "e@mail")
(pgBool True) (pgBool True) (Nothing)
simpleUser1 :: UserWrite gargantextUser :: Username -> UserWrite
simpleUser1 = User (Nothing) (pgStrictText "password") gargantextUser u = User (Nothing) (pgStrictText "password")
(Nothing) (pgBool False) (pgStrictText "user1") (Nothing) (pgBool True) (pgStrictText u)
(pgStrictText "first_name") (pgStrictText "first_name")
(pgStrictText "last_name") (pgStrictText "last_name")
(pgStrictText "e@mail") (pgStrictText "e@mail")
(pgBool False) (pgBool True) (Nothing) (pgBool True) (pgBool True) (Nothing)
simpleUser2 :: UserWrite insertUsersDemo :: Cmd err Int64
simpleUser2 = User (Nothing) (pgStrictText "password") insertUsersDemo = insertUsers $ map (\u -> gargantextUser u) arbitraryUsername
(Nothing) (pgBool False) (pgStrictText "user2")
(pgStrictText "first_name")
(pgStrictText "last_name")
(pgStrictText "e@mail")
(pgBool False) (pgBool True) (Nothing)
------------------------------------------------------------------ ------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment