]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/Node/Share.hs
[FIX] merge dev-phylo and dev
[gargantext.git] / src / Gargantext / API / Node / Share.hs
1 {-|
2 Module : Gargantext.API.Node.Share
3 Description :
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 -}
11
12 {-# LANGUAGE TemplateHaskell #-}
13 {-# LANGUAGE TypeOperators #-}
14 {-# OPTIONS_GHC -fno-warn-orphans #-}
15
16 module Gargantext.API.Node.Share
17 where
18
19 import Data.Aeson
20 import Data.Swagger
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
29 import Servant
30 import Test.QuickCheck (elements)
31 import Test.QuickCheck.Arbitrary
32
33 ------------------------------------------------------------------------
34 data ShareNode = ShareTeam { username :: Text }
35 | SharePublic { rights :: Text}
36 deriving (Generic)
37 ------------------------------------------------------------------------
38 -- TODO unPrefix "pn_" FromJSON, ToJSON, ToSchema, adapt frontend.
39 instance FromJSON ShareNode where
40 parseJSON = genericParseJSON (defaultOptions { sumEncoding = ObjectWithSingleField })
41 instance ToJSON ShareNode where
42 toJSON = genericToJSON (defaultOptions { sumEncoding = ObjectWithSingleField })
43 instance ToSchema ShareNode
44 instance Arbitrary ShareNode where
45 arbitrary = elements [ ShareTeam "user1"
46 , SharePublic "public"
47 ]
48 ------------------------------------------------------------------------
49 -- TODO permission
50 api :: HasNodeError err
51 => NodeId
52 -> ShareNode
53 -> Cmd err Int
54 api nId (ShareTeam user) =
55 fromIntegral <$> shareNodeWith nId NodeFolderShared (UserName user)
56 api nId (SharePublic _rights) =
57 fromIntegral <$> shareNodeWith nId NodeFolderPublic UserPublic
58
59 ------------------------------------------------------------------------
60 type API = Summary " Share Node with username"
61 :> ReqBody '[JSON] ShareNode
62 :> Post '[JSON] Int
63
64
65
66
67