2 Module : Gargantext.Database.Action.Share
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
12 module Gargantext.Database.Action.Share
15 import Control.Lens (view)
16 import Gargantext.Core.Types.Individu (User(..))
17 import Gargantext.Database.Action.Flow.Utils (getUserId)
18 import Gargantext.Database.Admin.Config (hasNodeType)
19 import Gargantext.Database.Admin.Types.Node (NodeId)
20 import Gargantext.Database.Admin.Types.Node -- (NodeType(..))
21 import Gargantext.Database.Prelude (Cmd)
22 import Gargantext.Database.Query.Table.Node (getNode, getNodesWith)
23 import Gargantext.Database.Query.Table.Node.Error (HasNodeError)
24 import Gargantext.Database.Query.Table.NodeNode (insertNodeNode, deleteNodeNode)
25 import Gargantext.Database.Query.Tree.Root (getRootId)
26 import Gargantext.Database.Schema.Node
27 import Gargantext.Database.Schema.NodeNode (NodeNodePoly(..))
28 import Gargantext.Prelude
30 ------------------------------------------------------------------------
31 shareNodeWith :: HasNodeError err
35 shareNodeWith n u = do
36 nodeToCheck <- getNode n
37 userIdCheck <- getUserId u
38 if not (hasNodeType nodeToCheck NodeTeam)
39 then panic "Can share node Team only"
40 else if (view node_userId nodeToCheck == userIdCheck)
41 then panic "Can share to others only"
43 folderSharedId <- getFolderSharedId u
44 insertNodeNode [NodeNode folderSharedId n Nothing Nothing]
45 ------------------------------------------------------------------------
47 getFolderSharedId :: User -> Cmd err NodeId
48 getFolderSharedId u = do
50 s <- getNodesWith rootId HyperdataAny (Just NodeFolderShared) Nothing Nothing
52 Nothing -> panic "No folder shared found"
53 Just f -> pure (_node_id f)
57 delFolderTeam :: User -> TeamId -> Cmd err Int
58 delFolderTeam u nId = do
59 folderSharedId <- getFolderSharedId u
60 deleteNodeNode folderSharedId nId