]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Action/Delete.hs
Merge branch 'dev-refact-graph' into dev
[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 deleteNode :: HasNodeError err
33 => User
34 -> NodeId
35 -> Cmd err Int
36 deleteNode u nodeId = do
37 node' <- N.getNode nodeId
38 if hasNodeType node' NodeUser
39 then panic "Not allowed to delete NodeUser (yet)"
40 else if hasNodeType node' NodeTeam
41 then do
42 uId <- getUserId u
43 if _node_userId node' == uId
44 then N.deleteNode nodeId
45 else delFolderTeam u nodeId
46 else N.deleteNode nodeId
47
48