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
7b41431a
Commit
7b41431a
authored
Apr 03, 2022
by
Karen Konou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP: [GQL] Basic mutation authentication
parent
2b241420
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
29 deletions
+63
-29
UserInfo.hs
src/Gargantext/API/GraphQL/UserInfo.hs
+34
-29
Utils.hs
src/Gargantext/API/GraphQL/Utils.hs
+29
-0
No files found.
src/Gargantext/API/GraphQL/UserInfo.hs
View file @
7b41431a
...
@@ -45,6 +45,7 @@ import Gargantext.Database.Schema.User (UserLight(..))
...
@@ -45,6 +45,7 @@ import Gargantext.Database.Schema.User (UserLight(..))
import
Gargantext.Database.Schema.Node
(
node_id
,
node_hyperdata
)
import
Gargantext.Database.Schema.Node
(
node_id
,
node_hyperdata
)
import
Gargantext.Prelude
import
Gargantext.Prelude
import
GHC.Generics
(
Generic
)
import
GHC.Generics
(
Generic
)
import
Gargantext.API.GraphQL.Utils
(
AuthStatus
(
Invalid
,
Valid
),
authUser
)
data
UserInfo
=
UserInfo
data
UserInfo
=
UserInfo
{
ui_id
::
Int
{
ui_id
::
Int
...
@@ -75,6 +76,7 @@ data UserInfoArgs
...
@@ -75,6 +76,7 @@ data UserInfoArgs
data
UserInfoMArgs
data
UserInfoMArgs
=
UserInfoMArgs
=
UserInfoMArgs
{
ui_id
::
Int
{
ui_id
::
Int
,
token
::
Text
,
ui_username
::
Maybe
Text
,
ui_username
::
Maybe
Text
,
ui_email
::
Maybe
Text
,
ui_email
::
Maybe
Text
,
ui_title
::
Maybe
Text
,
ui_title
::
Maybe
Text
...
@@ -108,7 +110,10 @@ updateUserInfo (UserInfoMArgs { ui_id, .. }) = do
...
@@ -108,7 +110,10 @@ updateUserInfo (UserInfoMArgs { ui_id, .. }) = do
users
<-
lift
(
getUsersWithNodeHyperdata
ui_id
)
users
<-
lift
(
getUsersWithNodeHyperdata
ui_id
)
case
users
of
case
users
of
[]
->
panic
$
"[updateUserInfo] User with id "
<>
(
T
.
pack
$
show
ui_id
)
<>
" doesn't exist."
[]
->
panic
$
"[updateUserInfo] User with id "
<>
(
T
.
pack
$
show
ui_id
)
<>
" doesn't exist."
((
UserLight
{
..
},
node_u
)
:
_
)
->
do
((
UserLight
{
..
},
node_u
)
:
_
)
->
case
authUser
ui_id
token
of
Invalid
->
panic
"[updateUserInfo] failed to validate user"
Valid
->
do
let
u_hyperdata
=
node_u
^.
node_hyperdata
let
u_hyperdata
=
node_u
^.
node_hyperdata
-- lift $ printDebug "[updateUserInfo] u" u
-- lift $ printDebug "[updateUserInfo] u" u
let
u_hyperdata'
=
uh
ui_titleL
ui_title
$
let
u_hyperdata'
=
uh
ui_titleL
ui_title
$
...
...
src/Gargantext/API/GraphQL/Utils.hs
View file @
7b41431a
...
@@ -4,8 +4,37 @@ import Data.Morpheus.Types (GQLTypeOptions, fieldLabelModifier)
...
@@ -4,8 +4,37 @@ import Data.Morpheus.Types (GQLTypeOptions, fieldLabelModifier)
import
qualified
Data.Text
as
T
import
qualified
Data.Text
as
T
import
Gargantext.Core.Utils.Prefix
(
unCapitalize
,
dropPrefix
)
import
Gargantext.Core.Utils.Prefix
(
unCapitalize
,
dropPrefix
)
import
Gargantext.Prelude
import
Gargantext.Prelude
import
Data.Text
(
Text
)
import
Data.Text.Encoding
(
encodeUtf8
)
import
Gargantext.API.Admin.Types
(
jwtSettings
,
HasSettings
(
settings
))
import
Servant.Auth.Server
(
verifyJWT
,
JWTSettings
)
import
Control.Lens.Getter
(
view
)
import
Gargantext.Database.Prelude
(
Cmd
'
)
import
Gargantext.API.Admin.Auth.Types
(
AuthenticatedUser
(
AuthenticatedUser
,
_authUser_id
))
import
Data.ByteString
(
ByteString
)
import
Gargantext.Database.Admin.Types.Node
(
unNodeId
)
unPrefix
::
T
.
Text
->
GQLTypeOptions
->
GQLTypeOptions
unPrefix
::
T
.
Text
->
GQLTypeOptions
->
GQLTypeOptions
unPrefix
prefix
options
=
options
{
fieldLabelModifier
=
nflm
}
unPrefix
prefix
options
=
options
{
fieldLabelModifier
=
nflm
}
where
where
nflm
label
=
unCapitalize
$
dropPrefix
(
T
.
unpack
prefix
)
$
(
fieldLabelModifier
options
)
label
nflm
label
=
unCapitalize
$
dropPrefix
(
T
.
unpack
prefix
)
$
(
fieldLabelModifier
options
)
label
data
AuthStatus
=
Valid
|
Invalid
authUser
::
(
HasSettings
env
)
=>
Int
->
Text
->
Cmd'
env
err
AuthStatus
authUser
ui_id
token
=
do
let
token'
=
encodeUtf8
token
jwtS
<-
view
$
settings
.
jwtSettings
u
<-
getUserFromToken
jwtS
token'
case
u
of
Nothing
->
pure
Invalid
Just
au
->
if
nId
au
==
ui_id
then
pure
Valid
else
pure
Invalid
where
nId
AuthenticatedUser
{
_authUser_id
}
=
unNodeId
_authUser_id
getUserFromToken
::
JWTSettings
->
ByteString
->
IO
(
Maybe
AuthenticatedUser
)
getUserFromToken
=
verifyJWT
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