Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Przemyslaw Kaminski
haskell-gargantext
Commits
8f01b456
Commit
8f01b456
authored
Jul 10, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[PUBLIC] API connected
parent
a9cac7ec
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
116 additions
and
18 deletions
+116
-18
API.hs
src/Gargantext/API.hs
+4
-1
Auth.hs
src/Gargantext/API/Admin/Auth.hs
+1
-2
Share.hs
src/Gargantext/API/Node/Share.hs
+1
-1
Public.hs
src/Gargantext/API/Public.hs
+86
-0
Routes.hs
src/Gargantext/API/Routes.hs
+11
-10
Node.hs
src/Gargantext/Database/Admin/Types/Node.hs
+1
-4
NodeNode.hs
src/Gargantext/Database/Query/Table/NodeNode.hs
+12
-0
No files found.
src/Gargantext/API.hs
View file @
8f01b456
...
...
@@ -76,6 +76,7 @@ import System.IO (FilePath)
import
qualified
Data.ByteString.Lazy.Char8
as
BL8
import
qualified
Data.Text.IO
as
T
import
qualified
Paths_gargantext
as
PG
-- cabal magic build module
import
qualified
Gargantext.API.Public
as
Public
data
Mode
=
Dev
|
Mock
|
Prod
...
...
@@ -219,7 +220,7 @@ server :: forall env. EnvC env => env -> IO (Server API)
server
env
=
do
-- orchestrator <- scrapyOrchestrator env
pure
$
schemaUiServer
swaggerDoc
:<|>
hoistServerWithContext
:<|>
hoistServerWithContext
(
Proxy
::
Proxy
GargAPI
)
(
Proxy
::
Proxy
AuthContext
)
transform
...
...
@@ -240,6 +241,8 @@ serverGargAPI -- orchestrator
=
auth
:<|>
gargVersion
:<|>
serverPrivateGargAPI
:<|>
Public
.
api
-- :<|> orchestrator
where
...
...
src/Gargantext/API/Admin/Auth.hs
View file @
8f01b456
...
...
@@ -201,8 +201,7 @@ withAccessM uId (PathNodeNode cId docId) m = do
withAccess
::
forall
env
err
m
api
.
(
GargServerC
env
err
m
,
HasServer
api
'[
]
)
=>
Proxy
api
->
Proxy
m
->
UserId
->
PathId
->
Proxy
api
->
Proxy
m
->
UserId
->
PathId
->
ServerT
api
m
->
ServerT
api
m
withAccess
p
_
uId
id
=
hoistServer
p
f
where
...
...
src/Gargantext/API/Node/Share.hs
View file @
8f01b456
...
...
@@ -20,13 +20,13 @@ import Data.Aeson
import
Data.Swagger
import
Data.Text
(
Text
)
import
GHC.Generics
(
Generic
)
import
Gargantext.API.Prelude
import
Gargantext.Core.Types.Individu
(
User
(
..
))
import
Gargantext.Database.Action.Share
(
ShareNodeWith
(
..
))
import
Gargantext.Database.Action.Share
as
DB
(
shareNodeWith
,
unPublish
)
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Prelude
import
Gargantext.Database.Query.Table.Node.Error
(
HasNodeError
(
..
))
import
Gargantext.API.Prelude
import
Gargantext.Prelude
import
Servant
import
Test.QuickCheck
(
elements
)
...
...
src/Gargantext/API/Public.hs
0 → 100644
View file @
8f01b456
{-|
Module : Gargantext.API.Public
Description :
Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3
Maintainer : team@gargantext.org
Stability : experimental
Portability : POSIX
-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
module
Gargantext.API.Public
where
import
Data.Text
(
Text
)
import
Data.List
(
replicate
)
import
Data.Aeson
import
Data.Swagger
import
GHC.Generics
(
Generic
)
import
Gargantext.Database.Query.Table.Node.Error
(
HasNodeError
(
..
))
import
Gargantext.Database.Prelude
-- import Gargantext.Database.Admin.Types.Node
-- import Gargantext.Database.Query.Table.NodeNode (selectPublicNodes)
-- import Gargantext.Database.Schema.Node (NodePoly(..))
import
Gargantext.Prelude
import
Servant
import
Test.QuickCheck
(
elements
)
import
Test.QuickCheck.Arbitrary
------------------------------------------------------------------------
type
API
=
Summary
" Public API"
:>
Get
'[
J
SON
]
[
PublicData
]
api
::
HasNodeError
err
=>
Cmd
err
[
PublicData
]
api
=
do
pure
$
replicate
6
defaultPublicData
{-
toPublicData :: (Node HyperdataFolder, Maybe Int) -> Maybe PublicData
toPublicData (n, mn) = Just $ PublicData t a i u d db au
where
d = _node_date n
t = _node_name n
-}
data
PublicData
=
PublicData
{
title
::
Text
,
abstract
::
Text
,
img
::
Text
,
url
::
Text
,
date
::
Text
,
database
::
Text
,
author
::
Text
}
|
NoData
{
nodata
::
Text
}
deriving
(
Generic
)
instance
FromJSON
PublicData
where
parseJSON
=
genericParseJSON
(
defaultOptions
{
sumEncoding
=
ObjectWithSingleField
})
instance
ToJSON
PublicData
where
toJSON
=
genericToJSON
(
defaultOptions
{
sumEncoding
=
ObjectWithSingleField
})
instance
ToSchema
PublicData
instance
Arbitrary
PublicData
where
arbitrary
=
elements
$
replicate
6
defaultPublicData
defaultPublicData
::
PublicData
defaultPublicData
=
PublicData
"Title"
(
foldl
(
<>
)
""
$
replicate
100
"abstract "
)
"images/Gargantextuel-212x300.jpg"
"https://.."
"YY/MM/DD"
"database"
"Author"
src/Gargantext/API/Routes.hs
View file @
8f01b456
...
...
@@ -24,34 +24,34 @@ Portability : POSIX
module
Gargantext.API.Routes
where
---------------------------------------------------------------------
import
Control.Concurrent
(
threadDelay
)
import
Data.Text
(
Text
)
import
Data.Validity
import
Servant
import
Servant.Auth
as
SA
import
Servant.Auth.Swagger
()
import
Servant.Job.Async
import
Servant.Swagger.UI
import
Gargantext.API.Admin.Auth
(
AuthRequest
,
AuthResponse
,
AuthenticatedUser
(
..
),
withAccess
,
PathId
(
..
))
import
Gargantext.API.Admin.FrontEnd
(
FrontEndAPI
)
import
Gargantext.API.Prelude
import
Gargantext.API.Count
(
CountAPI
,
count
,
Query
)
import
Gargantext.API.Ngrams
(
TableNgramsApi
,
apiNgramsTableDoc
)
import
Gargantext.API.Node
import
Gargantext.API.Prelude
import
Gargantext.API.Search
(
SearchPairsAPI
,
searchPairs
)
import
Gargantext.Core.Types.Individu
(
User
(
..
))
import
Gargantext.Database.Query.Table.Node.Contact
(
HyperdataContact
)
import
Gargantext.Database.Admin.Types.Hyperdata
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Admin.Types.Node
(
NodeId
,
CorpusId
,
AnnuaireId
)
import
Gargantext.Database.Query.Table.Node.Contact
(
HyperdataContact
)
import
Gargantext.Prelude
import
Gargantext.Viz.Graph.API
import
Servant
import
Servant.Auth
as
SA
import
Servant.Auth.Swagger
()
import
Servant.Job.Async
import
Servant.Swagger.UI
import
qualified
Gargantext.API.Ngrams.List
as
List
import
qualified
Gargantext.API.Node.Corpus.Annuaire
as
Annuaire
import
qualified
Gargantext.API.Node.Corpus.Export
as
Export
import
qualified
Gargantext.API.Node.Corpus.New
as
New
import
qualified
Gargantext.API.Ngrams.List
as
List
import
qualified
Gargantext.API.Public
as
Public
type
GargAPI
=
"api"
:>
Summary
"API "
:>
GargAPIVersion
...
...
@@ -75,6 +75,7 @@ type GargAPI' =
-- TODO-ACCESS here we want to request a particular header for
-- auth and capabilities.
:<|>
GargPrivateAPI
:<|>
"public"
:>
Public
.
API
type
GargPrivateAPI
=
SA
.
Auth
'[
S
A
.
JWT
,
SA
.
Cookie
]
AuthenticatedUser
...
...
src/Gargantext/Database/Admin/Types/Node.hs
View file @
8f01b456
...
...
@@ -233,10 +233,6 @@ instance Arbitrary Resource where
instance
ToSchema
Resource
where
declareNamedSchema
=
genericDeclareNamedSchema
(
unPrefixSwagger
"resource_"
)
------------------------------------------------------------------------
------------------------------------------------------------------------
-- | Then a Node can be either a Folder or a Corpus or a Document
data
NodeType
=
NodeUser
...
...
@@ -312,3 +308,4 @@ instance QueryRunnerColumnDefault (Nullable PGInt4) NodeId
where
queryRunnerColumnDefault
=
fieldQueryRunnerColumn
src/Gargantext/Database/Query/Table/NodeNode.hs
View file @
8f01b456
...
...
@@ -28,6 +28,7 @@ module Gargantext.Database.Query.Table.NodeNode
,
getNodeNode
,
insertNodeNode
,
deleteNodeNode
,
selectPublicNodes
)
where
...
...
@@ -153,3 +154,14 @@ joinInCorpus = leftJoin queryNodeTable queryNodeNodeTable cond
cond
::
(
NodeRead
,
NodeNodeRead
)
->
Column
PGBool
cond
(
n
,
nn
)
=
nn
^.
nn_node2_id
.==
(
view
node_id
n
)
------------------------------------------------------------------------
selectPublicNodes
::
(
Hyperdata
a
,
QueryRunnerColumnDefault
PGJsonb
a
)
=>
Cmd
err
[(
Node
a
,
Maybe
Int
)]
selectPublicNodes
=
runOpaQuery
(
queryWithType
NodeFolderPublic
)
queryWithType
::
NodeType
->
O
.
Query
(
NodeRead
,
Column
(
Nullable
PGInt4
))
queryWithType
nt
=
proc
()
->
do
(
n
,
nn
)
<-
joinInCorpus
-<
()
restrict
-<
n
^.
node_typename
.==
(
pgInt4
$
nodeTypeId
nt
)
returnA
-<
(
n
,
nn
^.
nn_node2_id
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment