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

Merge branch 'sh-handle-nil-project-feature' into 'master'

Gracefully handle missing project feature row in API

See merge request gitlab-org/gitlab!93326
No related branches found
No related tags found
无相关合并请求
...@@ -33,7 +33,7 @@ def preload_relation(projects_relation, options = {}) ...@@ -33,7 +33,7 @@ def preload_relation(projects_relation, options = {})
expose :requirements_enabled do |project, options| expose :requirements_enabled do |project, options|
project.feature_available?(:requirements, options[:current_user]) project.feature_available?(:requirements, options[:current_user])
end end
expose(:requirements_access_level) { |project, _| project.project_feature.string_access_level(:requirements) } expose(:requirements_access_level) { |project, _| project_feature_string_access_level(project, :requirements) }
expose :security_and_compliance_enabled do |project, options| expose :security_and_compliance_enabled do |project, options|
project.feature_available?(:security_and_compliance, options[:current_user]) project.feature_available?(:security_and_compliance, options[:current_user])
......
...@@ -67,18 +67,18 @@ class Project < BasicProjectDetails ...@@ -67,18 +67,18 @@ class Project < BasicProjectDetails
Ability.allowed?(options[:current_user], :create_merge_request_in, project) Ability.allowed?(options[:current_user], :create_merge_request_in, project)
end end
expose(:issues_access_level) { |project, options| project.project_feature.string_access_level(:issues) } expose(:issues_access_level) { |project, options| project_feature_string_access_level(project, :issues) }
expose(:repository_access_level) { |project, options| project.project_feature.string_access_level(:repository) } expose(:repository_access_level) { |project, options| project_feature_string_access_level(project, :repository) }
expose(:merge_requests_access_level) { |project, options| project.project_feature.string_access_level(:merge_requests) } expose(:merge_requests_access_level) { |project, options| project_feature_string_access_level(project, :merge_requests) }
expose(:forking_access_level) { |project, options| project.project_feature.string_access_level(:forking) } expose(:forking_access_level) { |project, options| project_feature_string_access_level(project, :forking) }
expose(:wiki_access_level) { |project, options| project.project_feature.string_access_level(:wiki) } expose(:wiki_access_level) { |project, options| project_feature_string_access_level(project, :wiki) }
expose(:builds_access_level) { |project, options| project.project_feature.string_access_level(:builds) } expose(:builds_access_level) { |project, options| project_feature_string_access_level(project, :builds) }
expose(:snippets_access_level) { |project, options| project.project_feature.string_access_level(:snippets) } expose(:snippets_access_level) { |project, options| project_feature_string_access_level(project, :snippets) }
expose(:pages_access_level) { |project, options| project.project_feature.string_access_level(:pages) } expose(:pages_access_level) { |project, options| project_feature_string_access_level(project, :pages) }
expose(:operations_access_level) { |project, options| project.project_feature.string_access_level(:operations) } expose(:operations_access_level) { |project, options| project_feature_string_access_level(project, :operations) }
expose(:analytics_access_level) { |project, options| project.project_feature.string_access_level(:analytics) } expose(:analytics_access_level) { |project, options| project_feature_string_access_level(project, :analytics) }
expose(:container_registry_access_level) { |project, options| project.project_feature.string_access_level(:container_registry) } expose(:container_registry_access_level) { |project, options| project_feature_string_access_level(project, :container_registry) }
expose(:security_and_compliance_access_level) { |project, options| project.project_feature.string_access_level(:security_and_compliance) } expose(:security_and_compliance_access_level) { |project, options| project_feature_string_access_level(project, :security_and_compliance) }
expose :emails_disabled expose :emails_disabled
expose :shared_runners_enabled expose :shared_runners_enabled
......
...@@ -9,6 +9,10 @@ def issues_available?(project, options) ...@@ -9,6 +9,10 @@ def issues_available?(project, options)
available?(:issues, project, options[:current_user]) available?(:issues, project, options[:current_user])
end end
def project_feature_string_access_level(project, feature)
project.project_feature&.string_access_level(feature)
end
def mrs_available?(project, options) def mrs_available?(project, options)
available?(:merge_requests, project, options[:current_user]) available?(:merge_requests, project, options[:current_user])
end end
......
...@@ -13,6 +13,19 @@ ...@@ -13,6 +13,19 @@
subject(:json) { entity.as_json } subject(:json) { entity.as_json }
context 'without project feature' do
before do
project.project_feature.destroy!
project.reload
end
it 'returns a response' do
expect(json[:issues_access_level]).to be_nil
expect(json[:repository_access_level]).to be_nil
expect(json[:merge_requests_access_level]).to be_nil
end
end
describe '.service_desk_address' do describe '.service_desk_address' do
before do before do
allow(project).to receive(:service_desk_enabled?).and_return(true) allow(project).to receive(:service_desk_enabled?).and_return(true)
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册