Commit 9da01c90 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[ERGO|COLLAB] can share Node Team to others only

parent 3d0edc1b
...@@ -31,7 +31,7 @@ module Gargantext.Database.Query.Tree ...@@ -31,7 +31,7 @@ module Gargantext.Database.Query.Tree
) )
where where
import Control.Lens ((^..), at, each, _Just, to, set, makeLenses) import Control.Lens ((^..), at, each, _Just, to, set, makeLenses, view)
import Control.Monad.Error.Class (MonadError()) import Control.Monad.Error.Class (MonadError())
import Data.List (tail, concat) import Data.List (tail, concat)
import Data.Map (Map, fromListWith, lookup) import Data.Map (Map, fromListWith, lookup)
...@@ -44,6 +44,7 @@ import Gargantext.Database.Admin.Types.Node -- (pgNodeId, NodeType(..)) ...@@ -44,6 +44,7 @@ import Gargantext.Database.Admin.Types.Node -- (pgNodeId, NodeType(..))
import Gargantext.Database.Admin.Config (fromNodeTypeId, nodeTypeId, hasNodeType) import Gargantext.Database.Admin.Config (fromNodeTypeId, nodeTypeId, hasNodeType)
import Gargantext.Database.Admin.Types.Node (NodeId, NodeType, DocId, allNodeTypes) import Gargantext.Database.Admin.Types.Node (NodeId, NodeType, DocId, allNodeTypes)
import Gargantext.Database.Query.Table.Node (getNode) import Gargantext.Database.Query.Table.Node (getNode)
import Gargantext.Database.Action.Flow.Utils (getUserId)
import Gargantext.Database.Prelude (Cmd, runPGSQuery) import Gargantext.Database.Prelude (Cmd, runPGSQuery)
import Gargantext.Database.Query.Tree.Error import Gargantext.Database.Query.Tree.Error
import Gargantext.Prelude import Gargantext.Prelude
...@@ -83,16 +84,18 @@ sharedTree p n nt = dbTree n nt ...@@ -83,16 +84,18 @@ sharedTree p n nt = dbTree n nt
shareNodeWith :: HasNodeError err => NodeId -> User -> Cmd err Int64 shareNodeWith :: HasNodeError err => NodeId -> User -> Cmd err Int64
shareNodeWith n u = do shareNodeWith n u = do
nodeToCheck <- getNode n nodeToCheck <- getNode n
if hasNodeType nodeToCheck NodeTeam userIdCheck <- getUserId u
then do if not (hasNodeType nodeToCheck NodeTeam)
then panic "Can share node Team only"
else if (view node_userId nodeToCheck == userIdCheck)
then panic "Can share to others only"
else do
r <- map _node_id <$> getRoot u r <- map _node_id <$> getRoot u
s <- case head r of s <- case head r of
Nothing -> panic "no root id" Nothing -> panic "no root id"
Just r' -> findNodesId r' [NodeFolderShared] Just r' -> findNodesId r' [NodeFolderShared]
insertNodeNode $ map (\s' -> NodeNode s' n Nothing Nothing) s insertNodeNode $ map (\s' -> NodeNode s' n Nothing Nothing) s
else
panic "node has not type Team"
-- TODO delete node, if not owned, then suppress the link only -- TODO delete node, if not owned, then suppress the link only
...@@ -221,6 +224,3 @@ isIn cId docId = ( == [Only True]) ...@@ -221,6 +224,3 @@ isIn cId docId = ( == [Only True])
|] (cId, docId) |] (cId, docId)
----------------------------------------------------- -----------------------------------------------------
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment