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

Cleaned up duplication with ProtectedRefAccess concern

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