2 Module : Gargantext.Database.user
3 Description : User Database management tools
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 Functions to deal with users, database side.
13 {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
14 {-# OPTIONS_GHC -fno-warn-orphans #-}
16 {-# LANGUAGE TemplateHaskell #-}
17 {-# LANGUAGE FlexibleContexts #-}
18 {-# LANGUAGE FlexibleInstances #-}
19 {-# LANGUAGE MultiParamTypeClasses #-}
20 {-# LANGUAGE FunctionalDependencies #-}
21 {-# LANGUAGE Arrows #-}
22 {-# LANGUAGE NoImplicitPrelude #-}
23 {-# LANGUAGE OverloadedStrings #-}
24 {-# LANGUAGE RankNTypes #-}
26 module Gargantext.Database.Schema.User where
28 import Data.Maybe (Maybe)
29 import Data.Text (Text)
30 import Data.Time (UTCTime)
31 import GHC.Show(Show(..))
32 import Gargantext.Prelude
34 -- FIXME PLZ : the import below leads to an error, why ?
35 -- import Gargantext.Database.Schema.Prelude hiding (makeLensesWith, abbreviatedFields, makeAdaptorAndInstance)
37 -- When FIXED : Imports to remove:
38 import Control.Lens.TH (makeLensesWith, abbreviatedFields)
39 import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
42 ------------------------------------------------------------------------
43 data UserLight = UserLight { userLight_id :: !Int
44 , userLight_username :: !Text
45 , userLight_email :: !Text
46 , userLigth_password :: !Text
49 toUserLight :: UserDB -> UserLight
50 toUserLight (UserDB id p _ _ u _ _ e _ _ _ ) = UserLight id u e p
52 data UserPoly id pass llogin suser
54 mail staff active djoined =
55 UserDB { user_id :: !id
56 , user_password :: !pass
57 , user_lastLogin :: !llogin
58 , user_isSuperUser :: !suser
60 , user_username :: !uname
61 , user_firstName :: !fname
62 , user_lastName :: !lname
65 , user_isStaff :: !staff
66 , user_isActive :: !active
67 , user_dateJoined :: !djoined
70 type UserWrite = UserPoly (Maybe (Column PGInt4)) (Column PGText)
71 (Maybe (Column PGTimestamptz)) (Column PGBool)
72 (Column PGText) (Column PGText)
73 (Column PGText) (Column PGText)
74 (Column PGBool) (Column PGBool)
75 (Maybe (Column PGTimestamptz))
77 type UserRead = UserPoly (Column PGInt4) (Column PGText)
78 (Column PGTimestamptz) (Column PGBool)
79 (Column PGText) (Column PGText)
80 (Column PGText) (Column PGText)
81 (Column PGBool) (Column PGBool)
82 (Column PGTimestamptz)
84 type UserReadNull = UserPoly (Column (Nullable PGInt4)) (Column (Nullable PGText))
85 (Column (Nullable PGTimestamptz)) (Column (Nullable PGBool))
86 (Column (Nullable PGText)) (Column (Nullable PGText))
87 (Column (Nullable PGText)) (Column (Nullable PGText))
88 (Column (Nullable PGBool)) (Column (Nullable PGBool))
89 (Column (Nullable PGTimestamptz))
91 type UserDB = UserPoly Int Text (Maybe UTCTime) Bool Text Text Text Text Bool Bool UTCTime
93 $(makeAdaptorAndInstance "pUserDB" ''UserPoly)
94 $(makeLensesWith abbreviatedFields ''UserPoly)
96 userTable :: Table UserWrite UserRead
97 userTable = Table "auth_user"
98 (pUserDB UserDB { user_id = optional "id"
99 , user_password = required "password"
100 , user_lastLogin = optional "last_login"
101 , user_isSuperUser = required "is_superuser"
102 , user_username = required "username"
103 , user_firstName = required "first_name"
104 , user_lastName = required "last_name"
105 , user_email = required "email"
106 , user_isStaff = required "is_staff"
107 , user_isActive = required "is_active"
108 , user_dateJoined = optional "date_joined"