Commit 9f285527 authored by James Edwards-Jones's avatar James Edwards-Jones

Deduplicate protected ref human_access_levels

Previously these were duplicated so they could be different for push/merge,
but this was no longer necessary after
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/11232
parent bd79d91b
......@@ -25,14 +25,14 @@ module Projects
def access_levels_options
{
create_access_levels: levels_for_dropdown(ProtectedTag::CreateAccessLevel),
push_access_levels: levels_for_dropdown(ProtectedBranch::PushAccessLevel),
merge_access_levels: levels_for_dropdown(ProtectedBranch::MergeAccessLevel)
create_access_levels: levels_for_dropdown,
push_access_levels: levels_for_dropdown,
merge_access_levels: levels_for_dropdown
}
end
def levels_for_dropdown(access_level_type)
roles = access_level_type.human_access_levels.map do |id, text|
def levels_for_dropdown
roles = ProtectedRefAccess::HUMAN_ACCESS_LEVELS.map do |id, text|
{ id: id, text: text, before_divider: true }
end
{ roles: roles }
......
......@@ -9,14 +9,6 @@ module ProtectedBranchAccess
delegate :project, to: :protected_branch
def self.human_access_levels
{
Gitlab::Access::MASTER => "Masters",
Gitlab::Access::DEVELOPER => "Developers + Masters",
Gitlab::Access::NO_ACCESS => "No one"
}.with_indifferent_access
end
def check_access(user)
return false if access_level == Gitlab::Access::NO_ACCESS
......
......@@ -7,6 +7,12 @@ module ProtectedRefAccess
Gitlab::Access::NO_ACCESS
].freeze
HUMAN_ACCESS_LEVELS = {
Gitlab::Access::MASTER => "Masters".freeze,
Gitlab::Access::DEVELOPER => "Developers + Masters".freeze,
Gitlab::Access::NO_ACCESS => "No one".freeze
}.freeze
included do
scope :master, -> { where(access_level: Gitlab::Access::MASTER) }
scope :developer, -> { where(access_level: Gitlab::Access::DEVELOPER) }
......@@ -17,7 +23,7 @@ module ProtectedRefAccess
end
def humanize
self.class.human_access_levels[self.access_level]
HUMAN_ACCESS_LEVELS[self.access_level]
end
# CE access levels are always role-based,
......
class ProtectedTag::CreateAccessLevel < ActiveRecord::Base
include ProtectedTagAccess
def self.human_access_levels
{
Gitlab::Access::MASTER => "Masters",
Gitlab::Access::DEVELOPER => "Developers + Masters",
Gitlab::Access::NO_ACCESS => "No one"
}.with_indifferent_access
end
def check_access(user)
return false if access_level == Gitlab::Access::NO_ACCESS
......
RSpec.shared_examples "protected tags > access control > EE" do
let(:users) { create_list(:user, 5) }
let(:groups) { create_list(:group, 5) }
let(:roles) { ProtectedTag::CreateAccessLevel.human_access_levels.except(0) }
let(:roles) { ProtectedRefAccess::HUMAN_ACCESS_LEVELS.except(0) }
before do
users.each { |user| project.team << [user, :developer] }
......@@ -146,7 +146,7 @@ RSpec.shared_examples "protected tags > access control > EE" do
visit project_protected_tags_path(project)
set_protected_tag_name('v1.0')
set_allowed_to('create', ProtectedTag::CreateAccessLevel.human_access_levels.values) # Last item (No one) should deselect the other ones
set_allowed_to('create', ProtectedRefAccess::HUMAN_ACCESS_LEVELS.values) # Last item (No one) should deselect the other ones
click_on "Protect"
......
shared_examples "protected branches > access control > EE" do
[['merge', ProtectedBranch::MergeAccessLevel], ['push', ProtectedBranch::PushAccessLevel]].each do |git_operation, access_level_class|
%w[merge push].each do |git_operation|
# Need to set a default for the `git_operation` access level that _isn't_ being tested
other_git_operation = git_operation == 'merge' ? 'push' : 'merge'
roles_except_noone = access_level_class.human_access_levels.except(0)
roles_except_noone = ProtectedRefAccess::HUMAN_ACCESS_LEVELS.except(0)
let(:users) { create_list(:user, 5) }
let(:groups) { create_list(:group, 5) }
......@@ -124,7 +124,7 @@ shared_examples "protected branches > access control > EE" do
context 'When updating a protected branch' do
it 'discards other roles when choosing "No one"' do
roles = ProtectedBranch::PushAccessLevel.human_access_levels.except(0)
roles = ProtectedRefAccess::HUMAN_ACCESS_LEVELS.except(0)
visit project_protected_branches_path(project)
set_protected_branch_name('fix')
set_allowed_to('merge')
......@@ -151,11 +151,11 @@ shared_examples "protected branches > access control > EE" do
context 'When creating a protected branch' do
it 'discards other roles when choosing "No one"' do
roles = ProtectedBranch::PushAccessLevel.human_access_levels.except(0)
roles = ProtectedRefAccess::HUMAN_ACCESS_LEVELS.except(0)
visit project_protected_branches_path(project)
set_protected_branch_name('master')
set_allowed_to('merge')
set_allowed_to('push', ProtectedBranch::PushAccessLevel.human_access_levels.values) # Last item (No one) should deselect the other ones
set_allowed_to('push', ProtectedRefAccess::HUMAN_ACCESS_LEVELS.values) # Last item (No one) should deselect the other ones
click_on "Protect"
wait_for_requests
......
RSpec.shared_examples "protected tags > access control > CE" do
ProtectedTag::CreateAccessLevel.human_access_levels.each do |(access_type_id, access_type_name)|
ProtectedRefAccess::HUMAN_ACCESS_LEVELS.each do |(access_type_id, access_type_name)|
it "allows creating protected tags that #{access_type_name} can create" do
visit project_protected_tags_path(project)
......
shared_examples "protected branches > access control > CE" do
ProtectedBranch::PushAccessLevel.human_access_levels.each do |(access_type_id, access_type_name)|
ProtectedRefAccess::HUMAN_ACCESS_LEVELS.each do |(access_type_id, access_type_name)|
it "allows creating protected branches that #{access_type_name} can push to" do
visit project_protected_branches_path(project)
......@@ -44,7 +44,7 @@ shared_examples "protected branches > access control > CE" do
end
end
ProtectedBranch::MergeAccessLevel.human_access_levels.each do |(access_type_id, access_type_name)|
ProtectedRefAccess::HUMAN_ACCESS_LEVELS.each do |(access_type_id, access_type_name)|
it "allows creating protected branches that #{access_type_name} can merge to" do
visit project_protected_branches_path(project)
......
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