]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Action/User.hs
[FIX] Phylo is back
[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 getUserLightWithId :: HasNodeError err => Int -> Cmd err UserLight
28 getUserLightWithId i = do
29 candidates <- head <$> getUsersWithId i
30 case candidates of
31 Nothing -> nodeError NoUserFound
32 Just u -> pure u
33
34 getUserLightDB :: HasNodeError err => User -> Cmd err UserLight
35 getUserLightDB u = do
36 userId <- getUserId u
37 userLight <- getUserLightWithId userId
38 pure userLight
39
40 ------------------------------------------------------------------------
41 getUserId :: HasNodeError err
42 => User
43 -> Cmd err UserId
44 getUserId u = do
45 maybeUser <- getUserId' u
46 case maybeUser of
47 Nothing -> nodeError NoUserFound
48 Just u' -> pure u'
49
50 getUserId' :: HasNodeError err
51 => User
52 -> Cmd err (Maybe UserId)
53 getUserId' (UserDBId uid) = pure (Just uid)
54 getUserId' (RootId rid) = do
55 n <- getNode rid
56 pure $ Just $ _node_user_id n
57 getUserId' (UserName u ) = do
58 muser <- getUser u
59 case muser of
60 Just user -> pure $ Just $ userLight_id user
61 Nothing -> pure Nothing
62 getUserId' UserPublic = pure Nothing
63
64 ------------------------------------------------------------------------
65 -- | Username = Text
66 -- UserName is User
67 -- that is confusing, we should change this
68 type Username = Text
69 getUsername :: HasNodeError err
70 => User
71 -> Cmd err Username
72 getUsername (UserName u) = pure u
73 getUsername (UserDBId i) = do
74 users <- getUsersWithId i
75 case head users of
76 Just u -> pure $ userLight_username u
77 Nothing -> nodeError $ NodeError "G.D.A.U.getUserName: User not found with that id"
78 getUsername (RootId rid) = do
79 n <- getNode rid
80 getUsername (UserDBId $ _node_user_id n)
81 getUsername UserPublic = pure "UserPublic"
82
83 --------------------------------------------------------------------------
84 -- getRootId is in Gargantext.Database.Query.Tree.Root
85