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
48 toUserLight :: UserDB -> UserLight
49 toUserLight (UserDB id _ _ _ u _ _ e _ _ _ ) = UserLight id u e
51 data UserPoly id pass llogin suser
53 mail staff active djoined =
54 UserDB { user_id :: !id
55 , user_password :: !pass
56 , user_lastLogin :: !llogin
57 , user_isSuperUser :: !suser
59 , user_username :: !uname
60 , user_firstName :: !fname
61 , user_lastName :: !lname
64 , user_isStaff :: !staff
65 , user_isActive :: !active
66 , user_dateJoined :: !djoined
69 type UserWrite = UserPoly (Maybe (Column PGInt4)) (Column PGText)
70 (Maybe (Column PGTimestamptz)) (Column PGBool)
71 (Column PGText) (Column PGText)
72 (Column PGText) (Column PGText)
73 (Column PGBool) (Column PGBool)
74 (Maybe (Column PGTimestamptz))
76 type UserRead = UserPoly (Column PGInt4) (Column PGText)
77 (Column PGTimestamptz) (Column PGBool)
78 (Column PGText) (Column PGText)
79 (Column PGText) (Column PGText)
80 (Column PGBool) (Column PGBool)
81 (Column PGTimestamptz)
83 type UserReadNull = UserPoly (Column (Nullable PGInt4)) (Column (Nullable PGText))
84 (Column (Nullable PGTimestamptz)) (Column (Nullable PGBool))
85 (Column (Nullable PGText)) (Column (Nullable PGText))
86 (Column (Nullable PGText)) (Column (Nullable PGText))
87 (Column (Nullable PGBool)) (Column (Nullable PGBool))
88 (Column (Nullable PGTimestamptz))
90 type UserDB = UserPoly Int Text (Maybe UTCTime) Bool Text Text Text Text Bool Bool UTCTime
92 $(makeAdaptorAndInstance "pUserDB" ''UserPoly)
93 $(makeLensesWith abbreviatedFields ''UserPoly)
95 userTable :: Table UserWrite UserRead
96 userTable = Table "auth_user"
97 (pUserDB UserDB { user_id = optional "id"
98 , user_password = required "password"
99 , user_lastLogin = optional "last_login"
100 , user_isSuperUser = required "is_superuser"
101 , user_username = required "username"
102 , user_firstName = required "first_name"
103 , user_lastName = required "last_name"
104 , user_email = required "email"
105 , user_isStaff = required "is_staff"
106 , user_isActive = required "is_active"
107 , user_dateJoined = optional "date_joined"