Commit 27cd8cf4 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FIXME] Api_Node type error

parent 8f4ae06a
...@@ -246,7 +246,7 @@ serverGargAPI baseUrl -- orchestrator ...@@ -246,7 +246,7 @@ serverGargAPI baseUrl -- orchestrator
:<|> gargVersion :<|> gargVersion
:<|> serverPrivateGargAPI :<|> serverPrivateGargAPI
:<|> (Public.api baseUrl) :<|> (Public.api baseUrl)
-- :<|> orchestrator -- :<|> orchestrator
where where
gargVersion :: GargServer GargVersion gargVersion :: GargServer GargVersion
......
...@@ -16,6 +16,7 @@ Portability : POSIX ...@@ -16,6 +16,7 @@ Portability : POSIX
module Gargantext.API.Public module Gargantext.API.Public
where where
import Data.Set (Set)
import Control.Lens ((^?), (^.), _Just) import Control.Lens ((^?), (^.), _Just)
import Data.Maybe (catMaybes) import Data.Maybe (catMaybes)
import Data.Text (Text) import Data.Text (Text)
...@@ -23,6 +24,8 @@ import Data.List (replicate, null) ...@@ -23,6 +24,8 @@ import Data.List (replicate, null)
import Data.Aeson import Data.Aeson
import Data.Swagger import Data.Swagger
import GHC.Generics (Generic) import GHC.Generics (Generic)
import Gargantext.API.Prelude
import Gargantext.API.Node.File
import Gargantext.Database.Query.Table.Node.Error (HasNodeError(..)) import Gargantext.Database.Query.Table.Node.Error (HasNodeError(..))
import Gargantext.Database.Prelude import Gargantext.Database.Prelude
import Gargantext.Database.Admin.Types.Node import Gargantext.Database.Admin.Types.Node
...@@ -34,22 +37,44 @@ import Gargantext.Prelude ...@@ -34,22 +37,44 @@ import Gargantext.Prelude
import Servant import Servant
import Test.QuickCheck (elements) import Test.QuickCheck (elements)
import Test.QuickCheck.Arbitrary import Test.QuickCheck.Arbitrary
import qualified Data.List as List
import qualified Data.Map as Map import qualified Data.Map as Map
import qualified Data.Set as Set
------------------------------------------------------------------------ ------------------------------------------------------------------------
type API = Summary " Public API" type API = API_Home
-- :<|> API_Node
api :: Text -> GargServer API
api baseUrl = (api_home baseUrl)
-- :<|> api_node
-------------------------------------------------------------------------
type API_Home = Summary " Public API"
:> Get '[JSON] [PublicData] :> Get '[JSON] [PublicData]
api :: HasNodeError err api_home :: Text -> GargServer API_Home
=> Text -> Cmd err [PublicData] api_home baseUrl = catMaybes
api base = catMaybes <$> map (toPublicData baseUrl)
<$> map (toPublicData base)
<$> filterPublicDatas <$> filterPublicDatas
<$> selectPublic <$> selectPublic
-------------------------------------------------------------------------
type API_Node = Summary " Public Node API"
:> FileApi
api_node :: UserId -> NodeId -> GargServer FileApi
api_node uid nId = do
pubNodes <- publicNodes
case Set.member nId pubNodes of
False -> panic "Not allowed" -- TODO throwErr
True -> fileApi uid nId
-------------------------------------------------------------------------
selectPublic :: HasNodeError err selectPublic :: HasNodeError err
=> Cmd err [( Node HyperdataFolder, Maybe Int)] => Cmd err [( Node HyperdataFolder, Maybe Int)]
selectPublic = selectPublicNodes selectPublic = selectPublicNodes
-- For tests only -- For tests only
...@@ -66,6 +91,15 @@ filterPublicDatas datas = ...@@ -66,6 +91,15 @@ filterPublicDatas datas =
& Map.filter (not . null . snd) & Map.filter (not . null . snd)
& Map.elems & Map.elems
publicNodes :: HasNodeError err
=> Cmd err (Set NodeId)
publicNodes = do
candidates <- filterPublicDatas <$> selectPublicNodes
pure $ Set.fromList
$ List.concat
$ map (\(n, ns) -> (_node_id n) : ns) candidates
-- http://localhost:8008/api/v1.0/node/23543/file/download<Paste> -- http://localhost:8008/api/v1.0/node/23543/file/download<Paste>
-- http://localhost:8000/images/Gargantextuel-212x300.jpg -- http://localhost:8000/images/Gargantextuel-212x300.jpg
toPublicData :: Text -> (Node HyperdataFolder, [NodeId]) -> Maybe PublicData toPublicData :: Text -> (Node HyperdataFolder, [NodeId]) -> Maybe PublicData
......
...@@ -74,7 +74,7 @@ type GargAPI' = ...@@ -74,7 +74,7 @@ type GargAPI' =
-- TODO-ACCESS here we want to request a particular header for -- TODO-ACCESS here we want to request a particular header for
-- auth and capabilities. -- auth and capabilities.
:<|> GargPrivateAPI :<|> GargPrivateAPI
:<|> "public" :> Public.API :<|> "public" :> Public.API
type GargPrivateAPI = SA.Auth '[SA.JWT, SA.Cookie] AuthenticatedUser type GargPrivateAPI = SA.Auth '[SA.JWT, SA.Cookie] AuthenticatedUser
......
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