]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/Node/Share.hs
[FIX] warnings
[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.API.Prelude
24 import Gargantext.Core.Types.Individu (User(..))
25 import Gargantext.Database.Action.Share (ShareNodeWith(..))
26 import Gargantext.Database.Action.Share as DB (shareNodeWith, unPublish)
27 import Gargantext.Database.Admin.Types.Node
28 import Gargantext.Database.Prelude
29 import Gargantext.Database.Query.Table.Node.Error (HasNodeError(..))
30 import Gargantext.Prelude
31 import Servant
32 import Test.QuickCheck (elements)
33 import Test.QuickCheck.Arbitrary
34
35 ------------------------------------------------------------------------
36 data ShareNodeParams = ShareTeamParams { username :: Text }
37 | SharePublicParams { node_id :: NodeId}
38 deriving (Generic)
39 ------------------------------------------------------------------------
40 -- TODO unPrefix "pn_" FromJSON, ToJSON, ToSchema, adapt frontend.
41 instance FromJSON ShareNodeParams where
42 parseJSON = genericParseJSON (defaultOptions { sumEncoding = ObjectWithSingleField })
43 instance ToJSON ShareNodeParams where
44 toJSON = genericToJSON (defaultOptions { sumEncoding = ObjectWithSingleField })
45 instance ToSchema ShareNodeParams
46 instance Arbitrary ShareNodeParams where
47 arbitrary = elements [ ShareTeamParams "user1"
48 , SharePublicParams (NodeId 1)
49 ]
50 ------------------------------------------------------------------------
51 -- TODO permission
52 api :: HasNodeError err
53 => NodeId
54 -> ShareNodeParams
55 -> Cmd err Int
56 api nId (ShareTeamParams user) =
57 fromIntegral <$> DB.shareNodeWith (ShareNodeWith_User NodeFolderShared (UserName user)) nId
58 api nId2 (SharePublicParams nId1) =
59 fromIntegral <$> DB.shareNodeWith (ShareNodeWith_Node NodeFolderPublic nId1) nId2
60
61 ------------------------------------------------------------------------
62 type API = Summary " Share Node with username"
63 :> ReqBody '[JSON] ShareNodeParams
64 :> Post '[JSON] Int
65
66 ------------------------------------------------------------------------
67 type Unpublish = Summary " Unpublish Node"
68 :> Capture "node_id" NodeId
69 :> Put '[JSON] Int
70
71 unPublish :: NodeId -> GargServer Unpublish
72 unPublish n = DB.unPublish n