2 Module : Gargantext.API.Node.Share
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
12 {-# LANGUAGE TemplateHaskell #-}
13 {-# LANGUAGE TypeOperators #-}
14 {-# OPTIONS_GHC -fno-warn-orphans #-}
16 module Gargantext.API.Node.Share
21 import Data.Text (Text)
22 import GHC.Generics (Generic)
23 import Gargantext.Core.Types.Individu (User(..))
24 import Gargantext.Database.Action.Share (shareNodeWith)
25 import Gargantext.Database.Admin.Types.Node
26 import Gargantext.Database.Prelude
27 import Gargantext.Database.Query.Table.Node.Error (HasNodeError(..))
28 import Gargantext.Prelude
30 import Test.QuickCheck (elements)
31 import Test.QuickCheck.Arbitrary
33 ------------------------------------------------------------------------
34 data ShareNode = ShareTeam { username :: Text }
35 | SharePublic { rights :: Text}
37 ------------------------------------------------------------------------
38 -- TODO unPrefix "pn_" FromJSON, ToJSON, ToSchema, adapt frontend.
39 instance FromJSON ShareNode
40 instance ToJSON ShareNode
41 instance ToSchema ShareNode
42 instance Arbitrary ShareNode where
43 arbitrary = elements [ ShareTeam "user1"
44 , SharePublic "public"
46 ------------------------------------------------------------------------
48 api :: HasNodeError err
52 api nId (ShareTeam user) =
53 fromIntegral <$> shareNodeWith nId NodeFolderShared (UserName user)
54 api nId (SharePublic _rights) =
55 fromIntegral <$> shareNodeWith nId NodeFolderPublic UserPublic
57 ------------------------------------------------------------------------
58 type API = Summary " Share Node with username"
59 :> ReqBody '[JSON] ShareNode