2 Module : Gargantext.Database.Action.Delete
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 TODO: right managements of nodes children of node Team
11 -- TODO add proper Right Management Type
17 module Gargantext.Database.Action.Delete
20 import Control.Lens (view, (^.))
24 import Gargantext.Core.Types.Individu (User(..))
25 import Gargantext.Database.Action.User (getUserId)
26 import Gargantext.Database.Action.Share (delFolderTeam)
27 import Gargantext.Core
28 import Gargantext.Database.Admin.Types.Hyperdata.File
29 import Gargantext.Database.Admin.Types.Node -- (NodeType(..))
30 import Gargantext.Database.Prelude (Cmd', HasConfig, HasConnectionPool)
31 import qualified Gargantext.Database.Query.Table.Node as N (getNode, deleteNode)
32 import Gargantext.Database.Query.Table.Node (getNodeWith)
33 import Gargantext.Database.Query.Table.Node.Error (HasNodeError)
34 import Gargantext.Database.Schema.Node
35 import Gargantext.Prelude
36 import qualified Gargantext.Prelude.Utils as GPU
38 ------------------------------------------------------------------------
40 deleteNode :: (HasConfig env, HasConnectionPool env, HasNodeError err)
44 deleteNode u nodeId = do
45 node' <- N.getNode nodeId
46 case (view node_typename node') of
47 nt | nt == toDBid NodeUser -> panic "Not allowed to delete NodeUser (yet)"
48 nt | nt == toDBid NodeTeam -> do
50 if _node_userId node' == uId
51 then N.deleteNode nodeId
52 else delFolderTeam u nodeId
53 nt | nt == toDBid NodeFile -> do
54 node <- getNodeWith nodeId (Proxy :: Proxy HyperdataFile)
55 let (HyperdataFile { _hff_path = path }) = node ^. node_hyperdata
56 GPU.removeFile $ unpack path
58 _ -> N.deleteNode nodeId
60 -- if hasNodeType node' NodeUser
61 -- then panic "Not allowed to delete NodeUser (yet)"
62 -- else if hasNodeType node' NodeTeam
65 -- if _node_userId node' == uId
66 -- then N.deleteNode nodeId
67 -- else delFolderTeam u nodeId
68 -- else N.deleteNode nodeId