Commit 59619a80 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[REFACT] fix error messages

parent 565c8b01
...@@ -44,6 +44,7 @@ mkNodeWithParent :: (HasNodeError err) ...@@ -44,6 +44,7 @@ mkNodeWithParent :: (HasNodeError err)
mkNodeWithParent NodeUser (Just _) _ _ = nodeError UserNoParent mkNodeWithParent NodeUser (Just _) _ _ = nodeError UserNoParent
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- | MkNode, insert and eventually configure Hyperdata
mkNodeWithParent NodeUser Nothing uId name = mkNodeWithParent NodeUser Nothing uId name =
insertNodesWithParentR Nothing [node NodeUser name defaultHyperdataUser Nothing uId] insertNodesWithParentR Nothing [node NodeUser name defaultHyperdataUser Nothing uId]
...@@ -56,10 +57,10 @@ mkNodeWithParent NodeFrameCalc i u n = ...@@ -56,10 +57,10 @@ mkNodeWithParent NodeFrameCalc i u n =
mkNodeWithParent_ConfigureHyperdata NodeFrameCalc i u n mkNodeWithParent_ConfigureHyperdata NodeFrameCalc i u n
mkNodeWithParent nt (Just pId) uId name = insertNode nt (Just name) Nothing pId uId mkNodeWithParent nt (Just pId) uId name = insertNode nt (Just name) Nothing pId uId
-- mkNodeWithParent _ _ _ _ = errorMsg "[G.D.A.Node.mkNodeWithParent] nees parent" -- mkNodeWithParent _ _ _ _ = errorWith "[G.D.A.Node.mkNodeWithParent] nees parent"
-- | Sugar to create a node, get his NodeId and update his Hyperdata after -- | Sugar to create a node, get its NodeId and update its Hyperdata after
mkNodeWithParent_ConfigureHyperdata :: (HasNodeError err) mkNodeWithParent_ConfigureHyperdata :: (HasNodeError err)
=> NodeType => NodeType
-> Maybe ParentId -> Maybe ParentId
......
...@@ -22,7 +22,7 @@ import Gargantext.Database.Admin.Types.Node (NodeId) ...@@ -22,7 +22,7 @@ import Gargantext.Database.Admin.Types.Node (NodeId)
import Gargantext.Database.Admin.Types.Node -- (NodeType(..)) import Gargantext.Database.Admin.Types.Node -- (NodeType(..))
import Gargantext.Database.Prelude (Cmd) import Gargantext.Database.Prelude (Cmd)
import Gargantext.Database.Query.Table.Node (getNode, getNodesWith) import Gargantext.Database.Query.Table.Node (getNode, getNodesWith)
import Gargantext.Database.Query.Table.Node.Error (HasNodeError, msg) import Gargantext.Database.Query.Table.Node.Error (HasNodeError, errorWith)
import Gargantext.Database.Query.Table.NodeNode (insertNodeNode, deleteNodeNode) import Gargantext.Database.Query.Table.NodeNode (insertNodeNode, deleteNodeNode)
import Gargantext.Database.Query.Tree.Root (getRootId) import Gargantext.Database.Query.Tree.Root (getRootId)
import Gargantext.Database.Schema.Node import Gargantext.Database.Schema.Node
...@@ -50,10 +50,10 @@ shareNodeWith (ShareNodeWith_User NodeFolderShared u) n = do ...@@ -50,10 +50,10 @@ shareNodeWith (ShareNodeWith_User NodeFolderShared u) n = do
nodeToCheck <- getNode n nodeToCheck <- getNode n
userIdCheck <- getUserId u userIdCheck <- getUserId u
if not (hasNodeType nodeToCheck NodeTeam) 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 else
if (view node_userId nodeToCheck == userIdCheck) if (view node_userId nodeToCheck == userIdCheck)
then msg "Can share to others only" then errorWith "[G.D.A.S.shareNodeWith] Can share to others only"
else do else do
folderSharedId <- getFolderId u NodeFolderShared folderSharedId <- getFolderId u NodeFolderShared
insertNodeNode [NodeNode folderSharedId n Nothing Nothing] insertNodeNode [NodeNode folderSharedId n Nothing Nothing]
...@@ -61,14 +61,15 @@ shareNodeWith (ShareNodeWith_User NodeFolderShared u) n = do ...@@ -61,14 +61,15 @@ shareNodeWith (ShareNodeWith_User NodeFolderShared u) n = do
shareNodeWith (ShareNodeWith_Node NodeFolderPublic nId) n = do shareNodeWith (ShareNodeWith_Node NodeFolderPublic nId) n = do
nodeToCheck <- getNode n nodeToCheck <- getNode n
if not (isInNodeTypes nodeToCheck publicNodeTypes) 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 else do
folderToCheck <- getNode nId folderToCheck <- getNode nId
if hasNodeType folderToCheck NodeFolderPublic if hasNodeType folderToCheck NodeFolderPublic
then insertNodeNode [NodeNode nId n Nothing Nothing] then insertNodeNode [NodeNode nId n Nothing Nothing]
else msg "Can share NodeWith NodeFolderPublic only" 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 getFolderId :: HasNodeError err => User -> NodeType -> Cmd err NodeId
...@@ -76,7 +77,7 @@ getFolderId u nt = do ...@@ -76,7 +77,7 @@ getFolderId u nt = do
rootId <- getRootId u rootId <- getRootId u
s <- getNodesWith rootId HyperdataAny (Just nt) Nothing Nothing s <- getNodesWith rootId HyperdataAny (Just nt) Nothing Nothing
case head s of 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) Just f -> pure (_node_id f)
------------------------------------------------------------------------ ------------------------------------------------------------------------
......
...@@ -63,15 +63,10 @@ instance Show NodeError ...@@ -63,15 +63,10 @@ instance Show NodeError
class HasNodeError e where class HasNodeError e where
_NodeError :: Prism' e NodeError _NodeError :: Prism' e NodeError
errorMsg :: ( MonadError e m errorWith :: ( MonadError e m
, HasNodeError e) , HasNodeError e)
=> Text -> m a => Text -> m a
errorMsg = msg errorWith x = nodeError (NodeError x)
msg :: ( MonadError e m
, HasNodeError e)
=> Text -> m a
msg x = nodeError (NodeError x)
nodeError :: ( MonadError e m nodeError :: ( MonadError e m
, HasNodeError e) , HasNodeError e)
......
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