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 Control.Lens.TH (makeLensesWith, abbreviatedFields)
29 import Data.Maybe (Maybe)
30 import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
31 import Data.Text (Text)
32 import Data.Time (UTCTime)
33 import GHC.Show(Show(..))
34 import Gargantext.Prelude
37 ------------------------------------------------------------------------
38 ------------------------------------------------------------------------
40 data UserLight = UserLight { userLight_id :: Int
41 , userLight_username :: Text
42 , userLight_email :: Text
45 toUserLight :: UserDB -> UserLight
46 toUserLight (UserDB id _ _ _ u _ _ e _ _ _ ) = UserLight id u e
48 data UserPoly id pass llogin suser
50 mail staff active djoined = UserDB { user_id :: id
51 , user_password :: pass
52 , user_lastLogin :: llogin
53 , user_isSuperUser :: suser
55 , user_username :: uname
56 , user_firstName :: fname
57 , user_lastName :: lname
60 , user_isStaff :: staff
61 , user_isActive :: active
62 , user_dateJoined :: djoined
65 type UserWrite = UserPoly (Maybe (Column PGInt4)) (Column PGText)
66 (Maybe (Column PGTimestamptz)) (Column PGBool)
67 (Column PGText) (Column PGText)
68 (Column PGText) (Column PGText)
69 (Column PGBool) (Column PGBool)
70 (Maybe (Column PGTimestamptz))
72 type UserRead = UserPoly (Column PGInt4) (Column PGText)
73 (Column PGTimestamptz) (Column PGBool)
74 (Column PGText) (Column PGText)
75 (Column PGText) (Column PGText)
76 (Column PGBool) (Column PGBool)
77 (Column PGTimestamptz)
79 type UserReadNull = UserPoly (Column (Nullable PGInt4)) (Column (Nullable PGText))
80 (Column (Nullable PGTimestamptz)) (Column (Nullable PGBool))
81 (Column (Nullable PGText)) (Column (Nullable PGText))
82 (Column (Nullable PGText)) (Column (Nullable PGText))
83 (Column (Nullable PGBool)) (Column (Nullable PGBool))
84 (Column (Nullable PGTimestamptz))
89 type UserDB = UserPoly Int Text (Maybe UTCTime) Bool Text Text Text Text Bool Bool UTCTime
91 $(makeAdaptorAndInstance "pUserDB" ''UserPoly)
92 $(makeLensesWith abbreviatedFields ''UserPoly)
95 userTable :: Table UserWrite UserRead
96 userTable = Table "auth_user" (pUserDB UserDB { user_id = optional "id"
97 , user_password = required "password"
98 , user_lastLogin = optional "last_login"
99 , user_isSuperUser = required "is_superuser"
100 , user_username = required "username"
101 , user_firstName = required "first_name"
102 , user_lastName = required "last_name"
103 , user_email = required "email"
104 , user_isStaff = required "is_staff"
105 , user_isActive = required "is_active"
106 , user_dateJoined = optional "date_joined"