]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Action/Delete.hs
Merge remote-tracking branch 'origin/175-dev-doc-table-count' into dev-merge
[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 Control.Lens (view, (^.))
21 import Data.Text
22 import Servant
23
24 import Gargantext.Core
25 import Gargantext.Core.Types.Individu (User(..))
26 import Gargantext.Database.Action.Share (delFolderTeam)
27 import Gargantext.Database.Action.User (getUserId)
28 import Gargantext.Database.Admin.Types.Hyperdata.File
29 import Gargantext.Database.Admin.Types.Node -- (NodeType(..))
30 import Gargantext.Database.Prelude (Cmd', CmdCommon)
31 import Gargantext.Database.Query.Table.Node (getNodeWith)
32 import Gargantext.Database.Query.Table.Node.Error (HasNodeError)
33 import Gargantext.Database.Schema.Node
34 import Gargantext.Prelude
35 import qualified Gargantext.Database.GargDB as GargDB
36 import qualified Gargantext.Database.Query.Table.Node as N (getNode, deleteNode)
37
38 ------------------------------------------------------------------------
39 -- TODO
40 -- Delete Corpus children accoring its types
41 -- Delete NodeList (NodeStory + cbor file)
42 deleteNode :: (CmdCommon env, HasNodeError err)
43 => User
44 -> NodeId
45 -> Cmd' env err Int
46 deleteNode u nodeId = do
47 node' <- N.getNode nodeId
48 case (view node_typename node') of
49 nt | nt == toDBid NodeUser -> panic "[G.D.A.D.deleteNode] Not allowed to delete NodeUser (yet)"
50 nt | nt == toDBid NodeTeam -> do
51 uId <- getUserId u
52 if _node_user_id node' == uId
53 then N.deleteNode nodeId
54 else delFolderTeam u nodeId
55 nt | nt == toDBid NodeFile -> do
56 node <- getNodeWith nodeId (Proxy :: Proxy HyperdataFile)
57 let (HyperdataFile { _hff_path = path }) = node ^. node_hyperdata
58 GargDB.rmFile $ unpack path
59 N.deleteNode nodeId
60 _ -> N.deleteNode nodeId
61
62 -- if hasNodeType node' NodeUser
63 -- then panic "Not allowed to delete NodeUser (yet)"
64 -- else if hasNodeType node' NodeTeam
65 -- then do
66 -- uId <- getUserId u
67 -- if _node_user_id node' == uId
68 -- then N.deleteNode nodeId
69 -- else delFolderTeam u nodeId
70 -- else N.deleteNode nodeId