]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Action/Delete.hs
[ngrams] add r_history %~ mempty to ngrams POST
[gargantext.git] / src / Gargantext / Database / Action / Delete.hs
1 {-|
2 Module : Gargantext.Database.Action.Delete
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 TODO: right managements of nodes children of node Team
11 -- TODO add proper Right Management Type
12
13 TODO: NodeError
14
15 -}
16
17 module Gargantext.Database.Action.Delete
18 where
19
20 import Gargantext.Core.Types.Individu (User(..))
21 import Gargantext.Database.Action.Flow.Utils (getUserId)
22 import Gargantext.Database.Admin.Config (hasNodeType)
23 import Gargantext.Database.Admin.Types.Node (NodeId)
24 import Gargantext.Database.Admin.Types.Node -- (NodeType(..))
25 import Gargantext.Database.Prelude (Cmd)
26 import Gargantext.Database.Query.Table.Node.Error (HasNodeError)
27 import Gargantext.Database.Schema.Node
28 import Gargantext.Prelude
29 import qualified Gargantext.Database.Query.Table.Node as N (getNode, deleteNode)
30 import Gargantext.Database.Action.Share (delFolderTeam)
31
32 ------------------------------------------------------------------------
33 deleteNode :: HasNodeError err
34 => User
35 -> NodeId
36 -> Cmd err Int
37 deleteNode u nodeId = do
38 node' <- N.getNode nodeId
39 if hasNodeType node' NodeUser
40 then panic "Not allowed to delete NodeUser (yet)"
41 else if hasNodeType node' NodeTeam
42 then do
43 uId <- getUserId u
44 if _node_userId node' == uId
45 then N.deleteNode nodeId
46 else delFolderTeam u nodeId
47 else N.deleteNode nodeId
48
49
50