Commit b3cd850c authored by Sean McGivern's avatar Sean McGivern Committed by Lin Jen-Shin

Remove EE-specific code from ProtectedRefAccess

parent 9357585e
...@@ -3,18 +3,22 @@ ...@@ -3,18 +3,22 @@
module ProtectedRefAccess module ProtectedRefAccess
extend ActiveSupport::Concern extend ActiveSupport::Concern
ALLOWED_ACCESS_LEVELS = [
Gitlab::Access::MAINTAINER,
Gitlab::Access::DEVELOPER,
Gitlab::Access::NO_ACCESS
].freeze
HUMAN_ACCESS_LEVELS = { HUMAN_ACCESS_LEVELS = {
Gitlab::Access::MAINTAINER => "Maintainers".freeze, Gitlab::Access::MAINTAINER => "Maintainers".freeze,
Gitlab::Access::DEVELOPER => "Developers + Maintainers".freeze, Gitlab::Access::DEVELOPER => "Developers + Maintainers".freeze,
Gitlab::Access::NO_ACCESS => "No one".freeze Gitlab::Access::NO_ACCESS => "No one".freeze
}.freeze }.freeze
class_methods do
def allowed_access_levels
[
Gitlab::Access::MAINTAINER,
Gitlab::Access::DEVELOPER,
Gitlab::Access::NO_ACCESS
]
end
end
included do included do
scope :master, -> { maintainer } # @deprecated scope :master, -> { maintainer } # @deprecated
scope :maintainer, -> { where(access_level: Gitlab::Access::MAINTAINER) } scope :maintainer, -> { where(access_level: Gitlab::Access::MAINTAINER) }
...@@ -26,7 +30,7 @@ module ProtectedRefAccess ...@@ -26,7 +30,7 @@ module ProtectedRefAccess
scope :for_group, -> { where.not(group_id: nil) } scope :for_group, -> { where.not(group_id: nil) }
validates :access_level, presence: true, if: :role?, inclusion: { validates :access_level, presence: true, if: :role?, inclusion: {
in: ALLOWED_ACCESS_LEVELS in: self.allowed_access_levels
} }
end end
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
**Valid access levels** **Valid access levels**
The access levels are defined in the `ProtectedRefAccess::ALLOWED_ACCESS_LEVELS` constant. Currently, these levels are recognized: The access levels are defined in the `ProtectedRefAccess.allowed_access_levels` method. Currently, these levels are recognized:
``` ```
0 => No access 0 => No access
30 => Developer access 30 => Developer access
......
...@@ -44,10 +44,10 @@ module API ...@@ -44,10 +44,10 @@ module API
params do params do
requires :name, type: String, desc: 'The name of the protected branch' requires :name, type: String, desc: 'The name of the protected branch'
optional :push_access_level, type: Integer, optional :push_access_level, type: Integer,
values: ProtectedRefAccess::ALLOWED_ACCESS_LEVELS, values: ProtectedBranch::PushAccessLevel.allowed_access_levels,
desc: 'Access levels allowed to push (defaults: `40`, maintainer access level)' desc: 'Access levels allowed to push (defaults: `40`, maintainer access level)'
optional :merge_access_level, type: Integer, optional :merge_access_level, type: Integer,
values: ProtectedRefAccess::ALLOWED_ACCESS_LEVELS, values: ProtectedBranch::MergeAccessLevel.allowed_access_levels,
desc: 'Access levels allowed to merge (defaults: `40`, maintainer access level)' desc: 'Access levels allowed to merge (defaults: `40`, maintainer access level)'
end end
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
......
...@@ -47,7 +47,7 @@ module API ...@@ -47,7 +47,7 @@ module API
params do params do
requires :name, type: String, desc: 'The name of the protected tag' requires :name, type: String, desc: 'The name of the protected tag'
optional :create_access_level, type: Integer, default: Gitlab::Access::MAINTAINER, optional :create_access_level, type: Integer, default: Gitlab::Access::MAINTAINER,
values: ProtectedRefAccess::ALLOWED_ACCESS_LEVELS, values: ProtectedTag::CreateAccessLevel.allowed_access_levels,
desc: 'Access levels allowed to create (defaults: `40`, maintainer access level)' desc: 'Access levels allowed to create (defaults: `40`, maintainer access level)'
end end
post ':id/protected_tags' do post ':id/protected_tags' do
......
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