]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/Node/Share.hs
[RENAME] ScraperStatus -> JobLog
[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 = ShareNode { username :: Text }
35 deriving (Generic)
36 ------------------------------------------------------------------------
37 -- TODO unPrefix "pn_" FromJSON, ToJSON, ToSchema, adapt frontend.
38 instance FromJSON ShareNode
39 instance ToJSON ShareNode
40 instance ToSchema ShareNode
41 instance Arbitrary ShareNode where
42 arbitrary = elements [ ShareNode "user1"
43 , ShareNode "user2"
44 ]
45 ------------------------------------------------------------------------
46 -- TODO permission
47 api :: HasNodeError err
48 => NodeId
49 -> ShareNode
50 -> Cmd err Int
51 api nId (ShareNode user) =
52 fromIntegral <$> shareNodeWith nId (UserName user)
53
54 ------------------------------------------------------------------------
55 type API = Summary " Share Node with username"
56 :> ReqBody '[JSON] ShareNode
57 :> Post '[JSON] Int
58