Commit f9e849c0 authored by James Edwards-Jones's avatar James Edwards-Jones

Cleaned up duplication with ProtectedRefAccess concern

parent 3bb3a688
......@@ -23,17 +23,16 @@ module Projects
#TODO: consider protected tags
#TODO: Refactor ProtectedBranch::PushAccessLevel so it doesn't mention branches
{
push_access_levels: {
roles: ProtectedBranch::PushAccessLevel.human_access_levels.map do |id, text|
{ id: id, text: text, before_divider: true }
push_access_levels: levels_for_dropdown(ProtectedBranch::PushAccessLevel),
merge_access_levels: levels_for_dropdown(ProtectedBranch::MergeAccessLevel)
}
end
},
merge_access_levels: {
roles: ProtectedBranch::MergeAccessLevel.human_access_levels.map do |id, text|
def levels_for_dropdown(access_level_type)
roles = access_level_type.human_access_levels.map do |id, text|
{ id: id, text: text, before_divider: true }
end
}
}
{ roles: roles }
end
def protectable_tags_for_dropdown
......
......@@ -2,20 +2,9 @@ module ProtectedBranchAccess
extend ActiveSupport::Concern
included do
include ProtectedRefAccess
belongs_to :protected_branch
delegate :project, to: :protected_branch
scope :master, -> { where(access_level: Gitlab::Access::MASTER) }
scope :developer, -> { where(access_level: Gitlab::Access::DEVELOPER) }
end
def humanize
self.class.human_access_levels[self.access_level]
end
def check_access(user)
return true if user.is_admin?
project.team.max_member_access(user.id) >= access_level
end
end
#TODO: Refactor, checking EE
# module ProtectedRefAccess
# extend ActiveSupport::Concern
module ProtectedRefAccess
extend ActiveSupport::Concern
# included do
# # belongs_to :protected_branch
# # delegate :project, to: :protected_branch
included do
scope :master, -> { where(access_level: Gitlab::Access::MASTER) }
scope :developer, -> { where(access_level: Gitlab::Access::DEVELOPER) }
end
# scope :master, -> { where(access_level: Gitlab::Access::MASTER) }
# scope :developer, -> { where(access_level: Gitlab::Access::DEVELOPER) }
# end
def humanize
self.class.human_access_levels[self.access_level]
end
# def humanize
# self.class.human_access_levels[self.access_level]
# end
def check_access(user)
return true if user.is_admin?
# def check_access(user)
# return true if user.is_admin?
# project.team.max_member_access(user.id) >= access_level
# end
# end
project.team.max_member_access(user.id) >= access_level
end
end
......@@ -2,20 +2,9 @@ module ProtectedTagAccess
extend ActiveSupport::Concern
included do
include ProtectedRefAccess
belongs_to :protected_tag
delegate :project, to: :protected_tag
scope :master, -> { where(access_level: Gitlab::Access::MASTER) }
scope :developer, -> { where(access_level: Gitlab::Access::DEVELOPER) }
end
def humanize
self.class.human_access_levels[self.access_level]
end
def check_access(user)
return true if user.is_admin?
project.team.max_member_access(user.id) >= access_level
end
end
......@@ -164,7 +164,6 @@ describe Gitlab::UserAccess, lib: true do
end
end
describe 'push to protected tag' do
let(:tag) { create(:protected_tag, project: project, name: "test") }
let(:not_existing_tag) { create :protected_tag, project: 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