Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
3de8ddcb
Commit
3de8ddcb
authored
Aug 19, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add sessionless param to graphql context
parent
844dc3e0
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
2 deletions
+26
-2
app/controllers/graphql_controller.rb
app/controllers/graphql_controller.rb
+1
-1
app/graphql/mutations/base_mutation.rb
app/graphql/mutations/base_mutation.rb
+4
-0
spec/controllers/graphql_controller_spec.rb
spec/controllers/graphql_controller_spec.rb
+21
-1
No files found.
app/controllers/graphql_controller.rb
View file @
3de8ddcb
...
...
@@ -81,7 +81,7 @@ class GraphqlController < ApplicationController
end
def
context
@context
||=
{
current_user:
current_user
}
@context
||=
{
current_user:
current_user
,
is_sessionless_user:
!!
sessionless_user?
}
end
def
build_variables
(
variable_info
)
...
...
app/graphql/mutations/base_mutation.rb
View file @
3de8ddcb
...
...
@@ -17,6 +17,10 @@ module Mutations
context
[
:current_user
]
end
def
api_user?
context
[
:is_sessionless_user
]
end
# Returns Array of errors on an ActiveRecord object
def
errors_on_object
(
record
)
record
.
errors
.
full_messages
...
...
spec/controllers/graphql_controller_spec.rb
View file @
3de8ddcb
...
...
@@ -60,14 +60,28 @@ RSpec.describe GraphqlController do
it
'updates the users last_activity_on field'
do
expect
{
post
:execute
}.
to
change
{
user
.
reload
.
last_activity_on
}
end
it
"sets context's sessionless value as false"
do
post
:execute
expect
(
assigns
(
:context
)[
:is_sessionless_user
]).
to
be
false
end
end
context
'when user uses an API token'
do
let
(
:user
)
{
create
(
:user
,
last_activity_on:
Date
.
yesterday
)
}
let
(
:token
)
{
create
(
:personal_access_token
,
user:
user
,
scopes:
[
:api
])
}
subject
{
post
:execute
,
params:
{
access_token:
token
.
token
}
}
it
'updates the users last_activity_on field'
do
expect
{
post
:execute
,
params:
{
access_token:
token
.
token
}
}.
to
change
{
user
.
reload
.
last_activity_on
}
expect
{
subject
}.
to
change
{
user
.
reload
.
last_activity_on
}
end
it
"sets context's sessionless value as true"
do
subject
expect
(
assigns
(
:context
)[
:is_sessionless_user
]).
to
be
true
end
end
...
...
@@ -77,6 +91,12 @@ RSpec.describe GraphqlController do
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
end
it
"sets context's sessionless value as false"
do
post
:execute
expect
(
assigns
(
:context
)[
:is_sessionless_user
]).
to
be
false
end
end
end
...
...
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