Commit 6608495d authored by Stan Hu's avatar Stan Hu

Merge branch 'fix/500-settings-when-repository-does-not-exist' into 'master'

Fix 500 error on repository settings access when repository is empty

See merge request gitlab-org/gitlab!50844
parents 98635e4c 3a043e91
...@@ -12,6 +12,8 @@ class ProtectableDropdown ...@@ -12,6 +12,8 @@ class ProtectableDropdown
# Tags/branches which are yet to be individually protected # Tags/branches which are yet to be individually protected
def protectable_ref_names def protectable_ref_names
return [] if @project.empty_repo?
@protectable_ref_names ||= ref_names - non_wildcard_protected_ref_names @protectable_ref_names ||= ref_names - non_wildcard_protected_ref_names
end end
......
---
title: Fix 500 error on repository settings access when repository is empty
merge_request: 50844
author: Diego Louzán
type: fixed
...@@ -5,6 +5,7 @@ module EE ...@@ -5,6 +5,7 @@ module EE
module Settings module Settings
module RepositoryController module RepositoryController
extend ActiveSupport::Concern extend ActiveSupport::Concern
extend ::Gitlab::Utils::Override
prepended do prepended do
before_action :push_rule, only: [:show, :create_deploy_token] before_action :push_rule, only: [:show, :create_deploy_token]
...@@ -24,7 +25,8 @@ module EE ...@@ -24,7 +25,8 @@ module EE
end end
# rubocop:disable Gitlab/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
def acces_levels_options override :access_levels_options
def access_levels_options
super.merge( super.merge(
selected_merge_access_levels: @protected_branch.merge_access_levels.map { |access_level| access_level.user_id || access_level.access_level }, selected_merge_access_levels: @protected_branch.merge_access_levels.map { |access_level| access_level.user_id || access_level.access_level },
selected_push_access_levels: @protected_branch.push_access_levels.map { |access_level| access_level.user_id || access_level.access_level }, selected_push_access_levels: @protected_branch.push_access_levels.map { |access_level| access_level.user_id || access_level.access_level },
......
...@@ -14,21 +14,33 @@ RSpec.describe ProtectableDropdown do ...@@ -14,21 +14,33 @@ RSpec.describe ProtectableDropdown do
end end
describe '#protectable_ref_names' do describe '#protectable_ref_names' do
before do context 'when project repository is not empty' do
project.protected_branches.create(name: 'master') before do
end project.protected_branches.create(name: 'master')
end
it { expect(subject.protectable_ref_names).to include('feature') }
it { expect(subject.protectable_ref_names).not_to include('master') }
it "includes branches matching a protected branch wildcard" do
expect(subject.protectable_ref_names).to include('feature')
it { expect(subject.protectable_ref_names).to include('feature') } create(:protected_branch, name: 'feat*', project: project)
it { expect(subject.protectable_ref_names).not_to include('master') }
it "includes branches matching a protected branch wildcard" do subject = described_class.new(project.reload, :branches)
expect(subject.protectable_ref_names).to include('feature')
expect(subject.protectable_ref_names).to include('feature')
end
end
create(:protected_branch, name: 'feat*', project: project) context 'when project repository is empty' do
let(:project) { create(:project) }
subject = described_class.new(project.reload, :branches) it "returns empty list" do
subject = described_class.new(project, :branches)
expect(subject.protectable_ref_names).to include('feature') expect(subject.protectable_ref_names).to be_empty
end
end 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