Commit 64ee4bdf authored by charlie ablett's avatar charlie ablett

Merge branch 'fj-add-sessionless-param-to-graphql-context' into 'master'

Add sessionless param to graphql context

Closes #232841

See merge request gitlab-org/gitlab!39830
parents c8ea49b9 3de8ddcb
...@@ -81,7 +81,7 @@ class GraphqlController < ApplicationController ...@@ -81,7 +81,7 @@ class GraphqlController < ApplicationController
end end
def context def context
@context ||= { current_user: current_user } @context ||= { current_user: current_user, is_sessionless_user: !!sessionless_user? }
end end
def build_variables(variable_info) def build_variables(variable_info)
......
...@@ -17,6 +17,10 @@ module Mutations ...@@ -17,6 +17,10 @@ module Mutations
context[:current_user] context[:current_user]
end end
def api_user?
context[:is_sessionless_user]
end
# Returns Array of errors on an ActiveRecord object # Returns Array of errors on an ActiveRecord object
def errors_on_object(record) def errors_on_object(record)
record.errors.full_messages record.errors.full_messages
......
...@@ -60,14 +60,28 @@ RSpec.describe GraphqlController do ...@@ -60,14 +60,28 @@ RSpec.describe GraphqlController do
it 'updates the users last_activity_on field' do it 'updates the users last_activity_on field' do
expect { post :execute }.to change { user.reload.last_activity_on } expect { post :execute }.to change { user.reload.last_activity_on }
end end
it "sets context's sessionless value as false" do
post :execute
expect(assigns(:context)[:is_sessionless_user]).to be false
end
end end
context 'when user uses an API token' do context 'when user uses an API token' do
let(:user) { create(:user, last_activity_on: Date.yesterday) } let(:user) { create(:user, last_activity_on: Date.yesterday) }
let(:token) { create(:personal_access_token, user: user, scopes: [:api]) } 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 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
end end
...@@ -77,6 +91,12 @@ RSpec.describe GraphqlController do ...@@ -77,6 +91,12 @@ RSpec.describe GraphqlController do
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
end end
it "sets context's sessionless value as false" do
post :execute
expect(assigns(:context)[:is_sessionless_user]).to be false
end
end end
end end
......
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