]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Action/Share.hs
[REFACT] sharing action
[gargantext.git] / src / Gargantext / Database / Action / Share.hs
1 {-|
2 Module : Gargantext.Database.Action.Share
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
11 -}
12
13
14 module Gargantext.Database.Action.Share
15 where
16
17 import Control.Lens (view)
18 import Gargantext.Core.Types.Individu (User(..))
19 import Gargantext.Database.Action.Flow.Utils (getUserId)
20 import Gargantext.Database.Admin.Config (hasNodeType)
21 import Gargantext.Database.Admin.Types.Node (NodeId)
22 import Gargantext.Database.Admin.Types.Node -- (NodeType(..))
23 import Gargantext.Database.Prelude (Cmd)
24 import Gargantext.Database.Query.Table.Node (getNode)
25 import Gargantext.Database.Query.Table.Node.Error (HasNodeError)
26 import Gargantext.Database.Query.Table.NodeNode (insertNodeNode)
27 import Gargantext.Database.Query.Tree
28 import Gargantext.Database.Query.Tree.Root (getRoot)
29 import Gargantext.Database.Schema.Node
30 import Gargantext.Database.Schema.NodeNode (NodeNodePoly(..))
31 import Gargantext.Prelude
32
33 ------------------------------------------------------------------------
34 shareNodeWith :: HasNodeError err
35 => NodeId
36 -> User
37 -> Cmd err Int64
38 shareNodeWith n u = do
39 nodeToCheck <- getNode n
40 userIdCheck <- getUserId u
41 if not (hasNodeType nodeToCheck NodeTeam)
42 then panic "Can share node Team only"
43 else if (view node_userId nodeToCheck == userIdCheck)
44 then panic "Can share to others only"
45 else do
46 r <- map _node_id <$> getRoot u
47 s <- case head r of
48 Nothing -> panic "no root id"
49 Just r' -> findNodesId r' [NodeFolderShared]
50 insertNodeNode $ map (\s' -> NodeNode s' n Nothing Nothing) s
51 ------------------------------------------------------------------------
52