]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Action/User.hs
Merge branch 'dev-phylo' of ssh://gitlab.iscpif.fr:20022/gargantext/haskell-gargantex...
[gargantext.git] / src / Gargantext / Database / Action / User.hs
1 {-|
2 Module : Gargantext.Database.Action.User
3 Description :
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 -}
11
12
13 module Gargantext.Database.Action.User
14 where
15
16 import Data.Text (Text)
17 import Gargantext.Core.Types.Individu (User(..))
18 import Gargantext.Database.Admin.Types.Node
19 import Gargantext.Database.Prelude (Cmd)
20 import Gargantext.Database.Query.Table.Node
21 import Gargantext.Database.Query.Table.User
22 import Gargantext.Database.Query.Table.Node.Error
23 import Gargantext.Database.Schema.Node
24 import Gargantext.Prelude
25
26 ------------------------------------------------------------------------
27 getUserId :: HasNodeError err
28 => User
29 -> Cmd err UserId
30 getUserId (UserDBId uid) = pure uid
31 getUserId (RootId rid) = do
32 n <- getNode rid
33 pure $ _node_userId n
34 getUserId (UserName u ) = do
35 muser <- getUser u
36 case muser of
37 Just user -> pure $ userLight_id user
38 Nothing -> nodeError NoUserFound
39 getUserId UserPublic = nodeError NoUserFound
40
41 ------------------------------------------------------------------------
42 -- | Username = Text
43 -- UserName is User
44 -- that is confusing, we should change this
45 type Username = Text
46 getUsername :: HasNodeError err
47 => User
48 -> Cmd err Username
49 getUsername (UserName u) = pure u
50 getUsername (UserDBId i) = do
51 users <- getUsersWithId i
52 case head users of
53 Just u -> pure $ userLight_username u
54 Nothing -> nodeError $ NodeError "G.D.A.U.getUserName: User not found with that id"
55 getUsername (RootId rid) = do
56 n <- getNode rid
57 getUsername (UserDBId $ _node_userId n)
58 getUsername UserPublic = pure "UserPublic"
59
60 --------------------------------------------------------------------------
61 -- getRootId is in Gargantext.Database.Query.Tree.Root
62