where
import Control.Lens (view)
+import Gargantext.Database
import Gargantext.Core.Types.Individu (User(..))
-import Gargantext.Database.Action.Flow.Utils (getUserId)
+import Gargantext.Database.Action.User (getUserId)
import Gargantext.Database.Admin.Config (hasNodeType, isInNodeTypes)
import Gargantext.Database.Admin.Types.Hyperdata (HyperdataAny(..))
-import Gargantext.Database.Admin.Types.Node (NodeId)
-import Gargantext.Database.Admin.Types.Node -- (NodeType(..))
-import Gargantext.Database.Prelude (Cmd)
+import Gargantext.Database.Admin.Types.Node
import Gargantext.Database.Query.Table.Node (getNode, getNodesWith)
-import Gargantext.Database.Query.Table.Node.Error (HasNodeError, msg)
-import Gargantext.Database.Query.Table.NodeNode (insertNodeNode, deleteNodeNode)
+import Gargantext.Database.Query.Table.Node.Error (HasNodeError, errorWith)
+import Gargantext.Database.Query.Table.NodeNode (deleteNodeNode)
import Gargantext.Database.Query.Tree.Root (getRootId)
import Gargantext.Database.Schema.Node
-import Gargantext.Database.Schema.NodeNode (NodeNodePoly(..))
import Gargantext.Prelude
-- | TODO move in Config of Gargantext
publicNodeTypes :: [NodeType]
-publicNodeTypes = [NodeDashboard, NodeGraph, NodePhylo]
+publicNodeTypes = [NodeDashboard, NodeGraph, NodePhylo, NodeFile]
------------------------------------------------------------------------
-
data ShareNodeWith = ShareNodeWith_User { snwu_nodetype :: NodeType
- , snwu_user :: User }
+ , snwu_user :: User
+ }
| ShareNodeWith_Node { snwn_nodetype :: NodeType
- , snwn_node_id :: NodeId
+ , snwn_node_id :: NodeId
}
-
------------------------------------------------------------------------
shareNodeWith :: HasNodeError err
=> ShareNodeWith
-> NodeId
- -> Cmd err Int64
+ -> Cmd err Int
shareNodeWith (ShareNodeWith_User NodeFolderShared u) n = do
nodeToCheck <- getNode n
userIdCheck <- getUserId u
if not (hasNodeType nodeToCheck NodeTeam)
- then msg "Can share node Team only"
+ then errorWith "[G.D.A.S.shareNodeWith] Can share node Team only"
else
- if (view node_userId nodeToCheck == userIdCheck)
- then msg "Can share to others only"
+ if (view node_user_id nodeToCheck == userIdCheck)
+ then errorWith "[G.D.A.S.shareNodeWith] Can share to others only"
else do
folderSharedId <- getFolderId u NodeFolderShared
- insertNodeNode [NodeNode folderSharedId n Nothing Nothing]
+ insertDB ([NodeNode folderSharedId n Nothing Nothing]:: [NodeNode])
shareNodeWith (ShareNodeWith_Node NodeFolderPublic nId) n = do
nodeToCheck <- getNode n
if not (isInNodeTypes nodeToCheck publicNodeTypes)
- then msg $ "Can share this nodesTypes only: " <> (cs $ show publicNodeTypes)
+ then errorWith $ "[G.D.A.S.shareNodeWith] Can share this nodesTypes only: "
+ <> (cs $ show publicNodeTypes)
else do
folderToCheck <- getNode nId
if hasNodeType folderToCheck NodeFolderPublic
- then insertNodeNode [NodeNode nId n Nothing Nothing]
- else msg "Can share NodeWith NodeFolderPublic only"
+ then insertDB ([NodeNode nId n Nothing Nothing] :: [NodeNode])
+ else errorWith "[G.D.A.S.shareNodeWith] Can share NodeWith NodeFolderPublic only"
-shareNodeWith _ _ = msg "shareNodeWith not implemented for this NodeType"
+shareNodeWith _ _ = errorWith "[G.D.A.S.shareNodeWith] Not implemented for this NodeType"
------------------------------------------------------------------------
getFolderId :: HasNodeError err => User -> NodeType -> Cmd err NodeId
rootId <- getRootId u
s <- getNodesWith rootId HyperdataAny (Just nt) Nothing Nothing
case head s of
- Nothing -> msg "No folder shared found"
+ Nothing -> errorWith "[G.D.A.S.getFolderId] No folder shared found"
Just f -> pure (_node_id f)
------------------------------------------------------------------------
folderSharedId <- getFolderId u NodeFolderShared
deleteNodeNode folderSharedId nId
-
unPublish :: HasNodeError err
=> ParentId -> NodeId
-> Cmd err Int