Commit 35124c54 authored by Alfredo Di Napoli's avatar Alfredo Di Napoli

Fix an unpublishing bug in Table.Node.Update

parent 3dc86d39
...@@ -809,6 +809,7 @@ test-suite garg-test-tasty ...@@ -809,6 +809,7 @@ test-suite garg-test-tasty
Test.API.Setup Test.API.Setup
Test.API.Prelude Test.API.Prelude
Test.API.UpdateList Test.API.UpdateList
Test.Core.AsyncUpdates
Test.Core.Notifications Test.Core.Notifications
Test.Core.Similarity Test.Core.Similarity
Test.Core.Text Test.Core.Text
......
...@@ -93,7 +93,7 @@ update loggedInUserId u@(Move sourceId targetId) = do ...@@ -93,7 +93,7 @@ update loggedInUserId u@(Move sourceId targetId) = do
case _node_user_id sourceNode == loggedInUserId of case _node_user_id sourceNode == loggedInUserId of
True -> do True -> do
userPublicFolderNode <- getUserRootPublicNode loggedInUserId userPublicFolderNode <- getUserRootPublicNode loggedInUserId
unpublishNode (SourceId $ _node_id userPublicFolderNode) (TargetId sourceId) unpublishNode (SourceId $ sourceId) (TargetId $ _node_id userPublicFolderNode)
-- Now we can perform the move -- Now we can perform the move
update' u update' u
False -> nodeError (NodeIsReadOnly targetId "logged user is not allowed to move/unpublish a read-only node") False -> nodeError (NodeIsReadOnly targetId "logged user is not allowed to move/unpublish a read-only node")
......
...@@ -80,6 +80,39 @@ tests = sequential $ aroundAll withTestDBAndPort $ do ...@@ -80,6 +80,39 @@ tests = sequential $ aroundAll withTestDBAndPort $ do
checkEither $ runClientM (get_tree token bobNodeId) clientEnv checkEither $ runClientM (get_tree token bobNodeId) clientEnv
containsNode aliceCorpusId tree `shouldBe` True containsNode aliceCorpusId tree `shouldBe` True
it "should unpublish Alice's published corpus when moved back to private" $ \(SpecContext testEnv serverPort app _) -> do
withApplication app $ do
aliceCorpusId <- withValidLogin serverPort "alice" (GargPassword "alice") $ \clientEnv token -> do
liftIO $ do
cId <- newCorpusForUser testEnv "alice"
alicePublicFolderId <- getRootPublicFolderIdForUser testEnv (UserName "alice")
_ <- checkEither $ runClientM (move_node token (SourceId cId) (TargetId alicePublicFolderId)) clientEnv
-- Check that we can see the folder
aliceNodeId <- myUserNodeId testEnv "alice"
tree <- checkEither $ runClientM (get_tree token aliceNodeId) clientEnv
assertBool "alice can't see her own corpus" (containsNode cId tree)
pure cId
withValidLogin serverPort "bob" (GargPassword "bob") $ \clientEnv token -> do
tree <- liftIO $ do
bobNodeId <- myUserNodeId testEnv "bob"
checkEither $ runClientM (get_tree token bobNodeId) clientEnv
containsNode aliceCorpusId tree `shouldBe` True
-- Now alice moves the node back to her private folder, effectively unpublishing it.
withValidLogin serverPort "alice" (GargPassword "alice") $ \clientEnv token -> do
liftIO $ do
alicePrivateFolderId <- getRootPrivateFolderIdForUser testEnv (UserName "alice")
void $ checkEither $ runClientM (move_node token (SourceId aliceCorpusId) (TargetId alicePrivateFolderId)) clientEnv
withValidLogin serverPort "bob" (GargPassword "bob") $ \clientEnv token -> do
tree <- liftIO $ do
bobNodeId <- myUserNodeId testEnv "bob"
checkEither $ runClientM (get_tree token bobNodeId) clientEnv
containsNode aliceCorpusId tree `shouldBe` False
it "shouldn't allow Alice to modify a (strictly) published node even if owner" $ \(SpecContext testEnv serverPort app _) -> do it "shouldn't allow Alice to modify a (strictly) published node even if owner" $ \(SpecContext testEnv serverPort app _) -> do
withApplication app $ do withApplication app $ do
withValidLogin serverPort "alice" (GargPassword "alice") $ \clientEnv token -> do withValidLogin serverPort "alice" (GargPassword "alice") $ \clientEnv token -> do
......
...@@ -15,7 +15,6 @@ import Gargantext.API.Node.Types ...@@ -15,7 +15,6 @@ import Gargantext.API.Node.Types
import Gargantext.API.Viz.Types import Gargantext.API.Viz.Types
import Gargantext.Core.Types.Phylo import Gargantext.Core.Types.Phylo
import qualified Gargantext.Core.Viz.Phylo as VizPhylo import qualified Gargantext.Core.Viz.Phylo as VizPhylo
import Gargantext.Database.Admin.Types.Hyperdata
import Gargantext.Database.Admin.Types.Node import Gargantext.Database.Admin.Types.Node
import Paths_gargantext import Paths_gargantext
import Prelude import Prelude
...@@ -32,6 +31,7 @@ jsonRoundtrip a = ...@@ -32,6 +31,7 @@ jsonRoundtrip a =
class (Show a, FromJSON a, ToJSON a, Eq a, Enum a, Bounded a) => EnumBoundedJSON a class (Show a, FromJSON a, ToJSON a, Eq a, Enum a, Bounded a) => EnumBoundedJSON a
instance EnumBoundedJSON BackendErrorCode instance EnumBoundedJSON BackendErrorCode
instance EnumBoundedJSON NodeType instance EnumBoundedJSON NodeType
instance EnumBoundedJSON NodePublishPolicy
jsonEnumRoundtrip :: forall a. Dict EnumBoundedJSON a -> Property jsonEnumRoundtrip :: forall a. Dict EnumBoundedJSON a -> Property
jsonEnumRoundtrip d = case d of jsonEnumRoundtrip d = case d of
......
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