]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Action/User.hs
[FIX] memory leak, useable ngrams table version (WIP)
[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 u = do
31 maybeUser <- getUserId' u
32 case maybeUser of
33 Nothing -> nodeError NoUserFound
34 Just u' -> pure u'
35
36 getUserId' :: HasNodeError err
37 => User
38 -> Cmd err (Maybe UserId)
39 getUserId' (UserDBId uid) = pure (Just uid)
40 getUserId' (RootId rid) = do
41 n <- getNode rid
42 pure $ Just $ _node_userId n
43 getUserId' (UserName u ) = do
44 muser <- getUser u
45 case muser of
46 Just user -> pure $ Just $ userLight_id user
47 Nothing -> pure Nothing
48 getUserId' UserPublic = pure Nothing
49
50 ------------------------------------------------------------------------
51 -- | Username = Text
52 -- UserName is User
53 -- that is confusing, we should change this
54 type Username = Text
55 getUsername :: HasNodeError err
56 => User
57 -> Cmd err Username
58 getUsername (UserName u) = pure u
59 getUsername (UserDBId i) = do
60 users <- getUsersWithId i
61 case head users of
62 Just u -> pure $ userLight_username u
63 Nothing -> nodeError $ NodeError "G.D.A.U.getUserName: User not found with that id"
64 getUsername (RootId rid) = do
65 n <- getNode rid
66 getUsername (UserDBId $ _node_userId n)
67 getUsername UserPublic = pure "UserPublic"
68
69 --------------------------------------------------------------------------
70 -- getRootId is in Gargantext.Database.Query.Tree.Root
71