Skip to content
代码片段 群组 项目
提交 cf85510e 编辑于 作者: Avielle Wolfe's avatar Avielle Wolfe
浏览文件

Merge branch 'fp-fix-catalog-resource-anonymous-access' into 'master'

Fix 500 error when accessing resources as anonymous user

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/138527



Merged-by: default avatarAvielle Wolfe <awolfe@gitlab.com>
Approved-by: default avatarKasia Misirli <kmisirli@gitlab.com>
Approved-by: default avatarAvielle Wolfe <awolfe@gitlab.com>
Reviewed-by: default avatarKasia Misirli <kmisirli@gitlab.com>
Co-authored-by: default avatarKasia Misirli <kmisirli@gitlab.com>
Co-authored-by: default avatarFabio Pitino <fpitino@gitlab.com>
No related branches found
No related tags found
无相关合并请求
...@@ -35,7 +35,7 @@ def find_resource(id:) ...@@ -35,7 +35,7 @@ def find_resource(id:)
return unless resource.present? return unless resource.present?
return unless resource.published? return unless resource.published?
return unless current_user.can?(:read_code, resource.project) return unless Ability.allowed?(current_user, :read_code, resource.project)
resource resource
end end
......
...@@ -185,11 +185,11 @@ ...@@ -185,11 +185,11 @@
end end
describe '#find_resource' do describe '#find_resource' do
let_it_be(:accessible_resource) { create(:ci_catalog_resource, :published, project: public_project) }
subject { list.find_resource(id: id) } subject { list.find_resource(id: id) }
context 'when the resource is published and visible to the user' do context 'when the resource is published and visible to the user' do
let_it_be(:accessible_resource) { create(:ci_catalog_resource, :published, project: public_project) }
let(:id) { accessible_resource.id } let(:id) { accessible_resource.id }
it 'fetches the resource' do it 'fetches the resource' do
...@@ -200,9 +200,7 @@ ...@@ -200,9 +200,7 @@
context 'when the resource is not found' do context 'when the resource is not found' do
let(:id) { 'not-an-id' } let(:id) { 'not-an-id' }
it 'returns nil' do it { is_expected.to be_nil }
is_expected.to be_nil
end
end end
context 'when the resource is not published' do context 'when the resource is not published' do
...@@ -210,9 +208,7 @@ ...@@ -210,9 +208,7 @@
let(:id) { draft_resource.id } let(:id) { draft_resource.id }
it 'returns nil' do it { is_expected.to be_nil }
is_expected.to be_nil
end
end end
context "when the current user cannot read code on the resource's project" do context "when the current user cannot read code on the resource's project" do
...@@ -220,8 +216,25 @@ ...@@ -220,8 +216,25 @@
let(:id) { inaccessible_resource.id } let(:id) { inaccessible_resource.id }
it 'returns nil' do it { is_expected.to be_nil }
is_expected.to be_nil end
context 'when the current user is anonymous' do
let(:user) { nil }
context 'when the resource is public' do
let(:id) { accessible_resource.id }
it 'fetches the public resource' do
is_expected.to eq(accessible_resource)
end
end
context 'when the resource is internal' do
let(:internal_resource) { create(:ci_catalog_resource, :published, project: internal_project) }
let(:id) { internal_resource.id }
it { is_expected.to be_nil }
end end
end end
end end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册