Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
2b3007dc
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
2b3007dc
编写于
9月 20, 2019
作者:
G
GitLab Bot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add latest changes from gitlab-org/gitlab@master
上级
434a9955
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
92 addition
and
1 deletion
+92
-1
app/graphql/mutations/base_mutation.rb
app/graphql/mutations/base_mutation.rb
+10
-0
changelogs/unreleased/32279-fix_graphql_for_secondary_node.yml
...elogs/unreleased/32279-fix_graphql_for_secondary_node.yml
+5
-0
lib/gitlab/middleware/read_only/controller.rb
lib/gitlab/middleware/read_only/controller.rb
+7
-1
locale/gitlab.pot
locale/gitlab.pot
+6
-0
spec/lib/gitlab/middleware/read_only_spec.rb
spec/lib/gitlab/middleware/read_only_spec.rb
+7
-0
spec/requests/api/graphql/read_only_spec.rb
spec/requests/api/graphql/read_only_spec.rb
+57
-0
未找到文件。
app/graphql/mutations/base_mutation.rb
浏览文件 @
2b3007dc
...
...
@@ -5,6 +5,8 @@ module Mutations
prepend
Gitlab
::
Graphql
::
Authorize
::
AuthorizeResource
prepend
Gitlab
::
Graphql
::
CopyFieldDescription
ERROR_MESSAGE
=
'You cannot perform write operations on a read-only instance'
field
:errors
,
[
GraphQL
::
STRING_TYPE
],
null:
false
,
description:
"Reasons why the mutation failed."
...
...
@@ -17,5 +19,13 @@ module Mutations
def
errors_on_object
(
record
)
record
.
errors
.
full_messages
end
def
ready?
(
**
args
)
if
Gitlab
::
Database
.
read_only?
raise
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
,
ERROR_MESSAGE
else
true
end
end
end
end
changelogs/unreleased/32279-fix_graphql_for_secondary_node.yml
0 → 100644
浏览文件 @
2b3007dc
---
title
:
Fix GraphQL for read-only instances
merge_request
:
17225
author
:
type
:
fixed
lib/gitlab/middleware/read_only/controller.rb
浏览文件 @
2b3007dc
...
...
@@ -20,6 +20,8 @@ module Gitlab
'projects/lfs_locks_api'
=>
%w{verify create unlock}
}.
freeze
GRAPHQL_URL
=
'/api/graphql'
def
initialize
(
app
,
env
)
@app
=
app
@env
=
env
...
...
@@ -79,7 +81,7 @@ module Gitlab
# Overridden in EE module
def
whitelisted_routes
grack_route?
||
internal_route?
||
lfs_route?
||
sidekiq_route?
grack_route?
||
internal_route?
||
lfs_route?
||
sidekiq_route?
||
graphql_query?
end
def
grack_route?
...
...
@@ -108,6 +110,10 @@ module Gitlab
def
sidekiq_route?
request
.
path
.
start_with?
(
"
#{
relative_url
}
/admin/sidekiq"
)
end
def
graphql_query?
request
.
post?
&&
request
.
path
.
start_with?
(
GRAPHQL_URL
)
end
end
end
end
...
...
locale/gitlab.pot
浏览文件 @
2b3007dc
...
...
@@ -9705,6 +9705,12 @@ msgstr ""
msgid "Metric was successfully updated."
msgstr ""
msgid "MetricChart|Please select a metric"
msgstr ""
msgid "MetricChart|Selected"
msgstr ""
msgid "Metrics"
msgstr ""
...
...
spec/lib/gitlab/middleware/read_only_spec.rb
浏览文件 @
2b3007dc
...
...
@@ -103,6 +103,13 @@ describe Gitlab::Middleware::ReadOnly do
expect
(
subject
).
not_to
disallow_request
end
it
'expects a graphql request to be allowed'
do
response
=
request
.
post
(
"/api/graphql"
)
expect
(
response
).
not_to
be_redirect
expect
(
subject
).
not_to
disallow_request
end
context
'sidekiq admin requests'
do
where
(
:mounted_at
)
do
[
...
...
spec/requests/api/graphql/read_only_spec.rb
0 → 100644
浏览文件 @
2b3007dc
# frozen_string_literal: true
require
'spec_helper'
describe
'Requests on a read-only node'
do
include
GraphqlHelpers
before
do
allow
(
Gitlab
::
Database
).
to
receive
(
:read_only?
)
{
true
}
end
context
'mutations'
do
let
(
:current_user
)
{
note
.
author
}
let!
(
:note
)
{
create
(
:note
)
}
let
(
:mutation
)
do
variables
=
{
id:
GitlabSchema
.
id_from_object
(
note
).
to_s
}
graphql_mutation
(
:destroy_note
,
variables
)
end
def
mutation_response
graphql_mutation_response
(
:destroy_note
)
end
it
'disallows the query'
do
post_graphql_mutation
(
mutation
,
current_user:
current_user
)
expect
(
json_response
[
'errors'
].
first
[
'message'
]).
to
eq
(
Mutations
::
BaseMutation
::
ERROR_MESSAGE
)
end
it
'does not destroy the Note'
do
expect
do
post_graphql_mutation
(
mutation
,
current_user:
current_user
)
end
.
not_to
change
{
Note
.
count
}
end
end
context
'read-only queries'
do
let
(
:current_user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
before
do
project
.
add_developer
(
current_user
)
end
it
'allows the query'
do
query
=
graphql_query_for
(
'project'
,
'fullPath'
=>
project
.
full_path
)
post_graphql
(
query
,
current_user:
current_user
)
expect
(
graphql_data
[
'project'
]).
not_to
be_nil
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录