Commit c0ae89ce authored by Alfredo Di Napoli's avatar Alfredo Di Napoli

Add NodeReadOnly nodetype and Hyperdata

This commit adds a new `NodeType` called `NodeReadOnly`, to model nodes
which can be exported as read-only (frozen) snapshots. It also extends
the code to have a (provisional, in its shape) `HyperdataReadOnly`.
parent a0ec337b
...@@ -426,6 +426,7 @@ library ...@@ -426,6 +426,7 @@ library
Gargantext.Database.Admin.Types.Hyperdata.Model Gargantext.Database.Admin.Types.Hyperdata.Model
Gargantext.Database.Admin.Types.Hyperdata.Phylo Gargantext.Database.Admin.Types.Hyperdata.Phylo
Gargantext.Database.Admin.Types.Hyperdata.Prelude Gargantext.Database.Admin.Types.Hyperdata.Prelude
Gargantext.Database.Admin.Types.Hyperdata.ReadOnly
Gargantext.Database.Admin.Types.Hyperdata.Texts Gargantext.Database.Admin.Types.Hyperdata.Texts
Gargantext.Database.Admin.Types.Hyperdata.User Gargantext.Database.Admin.Types.Hyperdata.User
Gargantext.Database.Admin.Types.Metrics Gargantext.Database.Admin.Types.Metrics
...@@ -711,6 +712,7 @@ common testDependencies ...@@ -711,6 +712,7 @@ common testDependencies
, aeson-pretty ^>= 0.8.9 , aeson-pretty ^>= 0.8.9
, aeson-qq , aeson-qq
, async ^>= 2.2.4 , async ^>= 2.2.4
, bimap >= 0.5.0
, boolexpr ^>= 0.3 , boolexpr ^>= 0.3
, bytestring ^>= 0.11.5.3 , bytestring ^>= 0.11.5.3
, cache >= 0.1.3.0 , cache >= 0.1.3.0
...@@ -826,6 +828,7 @@ test-suite garg-test-tasty ...@@ -826,6 +828,7 @@ test-suite garg-test-tasty
Test.Ngrams.NLP Test.Ngrams.NLP
Test.Ngrams.Query Test.Ngrams.Query
Test.Ngrams.Query.PaginationCorpus Test.Ngrams.Query.PaginationCorpus
Test.Offline.Database
Test.Offline.Errors Test.Offline.Errors
Test.Offline.JSON Test.Offline.JSON
Test.Offline.Phylo Test.Offline.Phylo
......
...@@ -75,3 +75,4 @@ nodeTypes = Bimap.fromList $ allNodeTypes <&> \n -> case n of ...@@ -75,3 +75,4 @@ nodeTypes = Bimap.fromList $ allNodeTypes <&> \n -> case n of
Calc -> (n, 992) Calc -> (n, 992)
NodeFrameNotebook -> (n, 993) NodeFrameNotebook -> (n, 993)
NodeFrameVisio -> (n, 994) NodeFrameVisio -> (n, 994)
NodeReadOnly -> (n, 995)
...@@ -13,7 +13,8 @@ Portability : POSIX ...@@ -13,7 +13,8 @@ Portability : POSIX
{-# OPTIONS_GHC -fno-warn-unused-imports #-} {-# OPTIONS_GHC -fno-warn-unused-imports #-}
module Gargantext.Database.Admin.Types.Hyperdata module Gargantext.Database.Admin.Types.Hyperdata
( module Gargantext.Database.Admin.Types.Hyperdata.Any ( module Gargantext.Core.Viz.Graph.Types
, module Gargantext.Database.Admin.Types.Hyperdata.Any
, module Gargantext.Database.Admin.Types.Hyperdata.Contact , module Gargantext.Database.Admin.Types.Hyperdata.Contact
, module Gargantext.Database.Admin.Types.Hyperdata.Corpus , module Gargantext.Database.Admin.Types.Hyperdata.Corpus
, module Gargantext.Database.Admin.Types.Hyperdata.Dashboard , module Gargantext.Database.Admin.Types.Hyperdata.Dashboard
...@@ -23,14 +24,15 @@ module Gargantext.Database.Admin.Types.Hyperdata ...@@ -23,14 +24,15 @@ module Gargantext.Database.Admin.Types.Hyperdata
, module Gargantext.Database.Admin.Types.Hyperdata.Frame , module Gargantext.Database.Admin.Types.Hyperdata.Frame
, module Gargantext.Database.Admin.Types.Hyperdata.List , module Gargantext.Database.Admin.Types.Hyperdata.List
, module Gargantext.Database.Admin.Types.Hyperdata.Model , module Gargantext.Database.Admin.Types.Hyperdata.Model
, module Gargantext.Database.Admin.Types.Hyperdata.Phylo
, module Gargantext.Database.Admin.Types.Hyperdata.Prelude , module Gargantext.Database.Admin.Types.Hyperdata.Prelude
, module Gargantext.Database.Admin.Types.Hyperdata.ReadOnly
, module Gargantext.Database.Admin.Types.Hyperdata.Texts , module Gargantext.Database.Admin.Types.Hyperdata.Texts
, module Gargantext.Database.Admin.Types.Hyperdata.Phylo
, module Gargantext.Database.Admin.Types.Hyperdata.User , module Gargantext.Database.Admin.Types.Hyperdata.User
, module Gargantext.Core.Viz.Graph.Types
) )
where where
import Gargantext.Core.Viz.Graph.Types (HyperdataGraph(..), defaultHyperdataGraph)
import Gargantext.Database.Admin.Types.Hyperdata.Any import Gargantext.Database.Admin.Types.Hyperdata.Any
import Gargantext.Database.Admin.Types.Hyperdata.Contact import Gargantext.Database.Admin.Types.Hyperdata.Contact
import Gargantext.Database.Admin.Types.Hyperdata.Corpus import Gargantext.Database.Admin.Types.Hyperdata.Corpus
...@@ -41,8 +43,8 @@ import Gargantext.Database.Admin.Types.Hyperdata.Folder ...@@ -41,8 +43,8 @@ import Gargantext.Database.Admin.Types.Hyperdata.Folder
import Gargantext.Database.Admin.Types.Hyperdata.Frame import Gargantext.Database.Admin.Types.Hyperdata.Frame
import Gargantext.Database.Admin.Types.Hyperdata.List import Gargantext.Database.Admin.Types.Hyperdata.List
import Gargantext.Database.Admin.Types.Hyperdata.Model import Gargantext.Database.Admin.Types.Hyperdata.Model
import Gargantext.Database.Admin.Types.Hyperdata.Phylo
import Gargantext.Database.Admin.Types.Hyperdata.Prelude (Hyperdata, HyperdataC) import Gargantext.Database.Admin.Types.Hyperdata.Prelude (Hyperdata, HyperdataC)
import Gargantext.Database.Admin.Types.Hyperdata.ReadOnly
import Gargantext.Database.Admin.Types.Hyperdata.Texts import Gargantext.Database.Admin.Types.Hyperdata.Texts
import Gargantext.Database.Admin.Types.Hyperdata.Phylo
import Gargantext.Database.Admin.Types.Hyperdata.User import Gargantext.Database.Admin.Types.Hyperdata.User
import Gargantext.Core.Viz.Graph.Types (HyperdataGraph(..), defaultHyperdataGraph)
...@@ -19,7 +19,7 @@ import Gargantext.Database.Admin.Types.Hyperdata.Prelude ...@@ -19,7 +19,7 @@ import Gargantext.Database.Admin.Types.Hyperdata.Prelude
------------------------------------------------------------------------ ------------------------------------------------------------------------
newtype HyperdataAny = HyperdataAny Object newtype HyperdataAny = HyperdataAny Object
deriving (Show, Generic, ToJSON, FromJSON) deriving (Show, Eq, Generic, ToJSON, FromJSON)
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- Instances -- Instances
......
...@@ -49,6 +49,7 @@ data DefaultHyperdata = ...@@ -49,6 +49,7 @@ data DefaultHyperdata =
| DefaultFrameCode HyperdataFrame | DefaultFrameCode HyperdataFrame
| DefaultFile HyperdataFile | DefaultFile HyperdataFile
| DefaultReadOnly HyperdataReadOnly
instance Hyperdata DefaultHyperdata instance Hyperdata DefaultHyperdata
...@@ -81,7 +82,8 @@ instance ToJSON DefaultHyperdata where ...@@ -81,7 +82,8 @@ instance ToJSON DefaultHyperdata where
toJSON (DefaultFrameVisio x) = toJSON x toJSON (DefaultFrameVisio x) = toJSON x
toJSON (DefaultFrameCode x) = toJSON x toJSON (DefaultFrameCode x) = toJSON x
toJSON (DefaultFile x) = toJSON x toJSON (DefaultFile x) = toJSON x
toJSON (DefaultReadOnly x) = toJSON x
defaultHyperdata :: NodeType -> DefaultHyperdata defaultHyperdata :: NodeType -> DefaultHyperdata
...@@ -114,3 +116,4 @@ defaultHyperdata NodeFrameVisio = DefaultFrameVisio defaultHyperdataFrame ...@@ -114,3 +116,4 @@ defaultHyperdata NodeFrameVisio = DefaultFrameVisio defaultHyperdataFrame
defaultHyperdata NodeFrameNotebook = DefaultFrameCalc defaultHyperdataFrame defaultHyperdata NodeFrameNotebook = DefaultFrameCalc defaultHyperdataFrame
defaultHyperdata NodeFile = DefaultFile defaultHyperdataFile defaultHyperdata NodeFile = DefaultFile defaultHyperdataFile
defaultHyperdata NodeReadOnly = DefaultReadOnly defaultHyperdataReadOnly
{-# LANGUAGE TemplateHaskell #-}
module Gargantext.Database.Admin.Types.Hyperdata.ReadOnly (
HyperdataReadOnly(..)
, defaultHyperdataReadOnly
) where
import Data.Aeson.TH
import Prelude
import GHC.Generics
import Gargantext.Database.Admin.Types.Hyperdata.Any
import Gargantext.Core.Utils.Prefix (unPrefix)
import Test.QuickCheck
data HyperdataReadOnly =
HyperdataReadOnly { _hro_wrapped :: Maybe HyperdataAny }
deriving (Generic, Show, Eq)
defaultHyperdataReadOnly :: HyperdataReadOnly
defaultHyperdataReadOnly =
HyperdataReadOnly
{ _hro_wrapped = Nothing
}
--
-- Instances
--
$(deriveJSON (unPrefix "_hro_") ''HyperdataReadOnly)
instance Arbitrary HyperdataReadOnly where
arbitrary = HyperdataReadOnly <$> arbitrary
...@@ -433,6 +433,14 @@ data NodeType ...@@ -433,6 +433,14 @@ data NodeType
| NodeFrameVisio | NodeFrameVisio
| NodeFrameNotebook | NodeFrameNotebook
| NodeFile | NodeFile
-- Nodes that controls access
-- | A read-only node is a node that is non modifiable after
-- creation, and this access control extends to all its children
-- (even recursively). This can be used to publish things like
-- corpus or graphs without giving the possibility for third-parties
-- to modify/tamper it.
| NodeReadOnly
deriving (Show, Read, Eq, Ord, Generic, Bounded, Enum) deriving (Show, Read, Eq, Ord, Generic, Bounded, Enum)
instance GQLType NodeType instance GQLType NodeType
...@@ -489,6 +497,8 @@ instance ToJSON NodeType where ...@@ -489,6 +497,8 @@ instance ToJSON NodeType where
-> "NodeFrameNotebook" -> "NodeFrameNotebook"
NodeFile NodeFile
-> "NodeFile" -> "NodeFile"
NodeReadOnly
-> "NodeReadOnly"
instance FromJSON NodeType where instance FromJSON NodeType where
parseJSON = withText "NodeType" $ \t -> case t of parseJSON = withText "NodeType" $ \t -> case t of
...@@ -538,6 +548,8 @@ instance FromJSON NodeType where ...@@ -538,6 +548,8 @@ instance FromJSON NodeType where
-> pure NodeFrameNotebook -> pure NodeFrameNotebook
"NodeFile" "NodeFile"
-> pure NodeFile -> pure NodeFile
"NodeReadOnly"
-> pure NodeReadOnly
unhandled unhandled
-> typeMismatch "NodeType" (JSON.String unhandled) -> typeMismatch "NodeType" (JSON.String unhandled)
...@@ -591,6 +603,7 @@ defaultName NodeFrameVisio = "Visio" ...@@ -591,6 +603,7 @@ defaultName NodeFrameVisio = "Visio"
defaultName NodeFrameNotebook = "Code" defaultName NodeFrameNotebook = "Code"
defaultName NodeFile = "File" defaultName NodeFile = "File"
defaultName NodeReadOnly = "Frozen"
......
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE QuasiQuotes #-}
module Test.Offline.Database (tests) where
import Gargantext.Database.Admin.Config (nodeTypes)
import Prelude
import Test.Tasty
import Test.Tasty.QuickCheck
import qualified Data.Bimap as Bimap
import qualified Data.Set as Set
tests :: TestTree
tests = testGroup "Database" [
testProperty "NodeType -> NodeTypeId no clashes" nodeTypesNoClashing_prop
]
-- | Tests that the 'nodeTypes' bimap never yields clashing IDs, i.e.
-- different keys yielding the same value.
nodeTypesNoClashing_prop :: Property
nodeTypesNoClashing_prop =
let e = Bimap.elems nodeTypes
in counterexample "Careful! the nodeTypes bimap has clashing values!" $
Set.toList (Set.fromList e) === e
...@@ -6,14 +6,15 @@ ...@@ -6,14 +6,15 @@
module Test.Offline.JSON (tests) where module Test.Offline.JSON (tests) where
import Data.Aeson import Data.Aeson
import Data.ByteString qualified as B
import Data.ByteString.Lazy.Char8 qualified as C8 import Data.ByteString.Lazy.Char8 qualified as C8
import Data.ByteString qualified as B
import Data.Either import Data.Either
import Gargantext.API.Errors import Gargantext.API.Errors
import Gargantext.API.Node.Corpus.Types import Gargantext.API.Node.Corpus.Types
import Gargantext.API.Node.Types 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 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
...@@ -63,6 +64,7 @@ tests = testGroup "JSON" [ ...@@ -63,6 +64,7 @@ tests = testGroup "JSON" [
, testProperty "ObjectData" (jsonRoundtrip @ObjectData) , testProperty "ObjectData" (jsonRoundtrip @ObjectData)
, testProperty "PhyloData" (jsonRoundtrip @PhyloData) , testProperty "PhyloData" (jsonRoundtrip @PhyloData)
, testProperty "LayerData" (jsonRoundtrip @LayerData) , testProperty "LayerData" (jsonRoundtrip @LayerData)
, testProperty "HyperdataReadOnly" (jsonRoundtrip @HyperdataReadOnly)
, testCase "can parse bpa_phylo_test.json" testParseBpaPhylo , testCase "can parse bpa_phylo_test.json" testParseBpaPhylo
, testCase "can parse open_science.json" testOpenSciencePhylo , testCase "can parse open_science.json" testOpenSciencePhylo
] ]
......
...@@ -19,6 +19,7 @@ import qualified Test.Graph.Clustering as Graph ...@@ -19,6 +19,7 @@ import qualified Test.Graph.Clustering as Graph
import qualified Test.Ngrams.NLP as NLP import qualified Test.Ngrams.NLP as NLP
import qualified Test.Ngrams.Query as NgramsQuery import qualified Test.Ngrams.Query as NgramsQuery
import qualified Test.Offline.JSON as JSON import qualified Test.Offline.JSON as JSON
import qualified Test.Offline.Database as DBOffline
import qualified Test.Offline.Errors as Errors import qualified Test.Offline.Errors as Errors
import qualified Test.Offline.Phylo as Phylo import qualified Test.Offline.Phylo as Phylo
import qualified Test.Offline.Stemming.Lancaster as Lancaster import qualified Test.Offline.Stemming.Lancaster as Lancaster
...@@ -54,6 +55,7 @@ main = do ...@@ -54,6 +55,7 @@ main = do
, TSVParser.tests , TSVParser.tests
, JSON.tests , JSON.tests
, Errors.tests , Errors.tests
, DBOffline.tests
, similaritySpec , similaritySpec
, Phylo.tests , Phylo.tests
, testGroup "Stemming" [ Lancaster.tests ] , testGroup "Stemming" [ Lancaster.tests ]
......
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