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

Fix ProtectedBranch access level validations

Before an access_level was required in EE even when an
it had been set for a user/group.
parent e548c613
module ProtectedBranchAccess module ProtectedBranchAccess
extend ActiveSupport::Concern extend ActiveSupport::Concern
ALLOWED_ACCESS_LEVELS ||= [
Gitlab::Access::MASTER,
Gitlab::Access::DEVELOPER,
Gitlab::Access::NO_ACCESS
].freeze
included do included do
include ProtectedRefAccess include ProtectedRefAccess
...@@ -14,10 +8,6 @@ module ProtectedBranchAccess ...@@ -14,10 +8,6 @@ module ProtectedBranchAccess
delegate :project, to: :protected_branch delegate :project, to: :protected_branch
validates :access_level, presence: true, inclusion: {
in: ALLOWED_ACCESS_LEVELS
}
def self.human_access_levels def self.human_access_levels
{ {
Gitlab::Access::MASTER => "Masters", Gitlab::Access::MASTER => "Masters",
......
module ProtectedRefAccess module ProtectedRefAccess
extend ActiveSupport::Concern extend ActiveSupport::Concern
ALLOWED_ACCESS_LEVELS = [
Gitlab::Access::MASTER,
Gitlab::Access::DEVELOPER,
Gitlab::Access::NO_ACCESS
].freeze
included do included do
scope :master, -> { where(access_level: Gitlab::Access::MASTER) } scope :master, -> { where(access_level: Gitlab::Access::MASTER) }
scope :developer, -> { where(access_level: Gitlab::Access::DEVELOPER) } scope :developer, -> { where(access_level: Gitlab::Access::DEVELOPER) }
validates :access_level, presence: true, if: :role?, inclusion: {
in: ALLOWED_ACCESS_LEVELS
}
end end
def humanize def humanize
self.class.human_access_levels[self.access_level] self.class.human_access_levels[self.access_level]
end end
# CE access levels are always role-based,
# where as EE allows groups and users too
def role?
true
end
def check_access(user) def check_access(user)
return true if user.admin? return true if user.admin?
......
class ProtectedTag::CreateAccessLevel < ActiveRecord::Base class ProtectedTag::CreateAccessLevel < ActiveRecord::Base
include ProtectedTagAccess include ProtectedTagAccess
validates :access_level, presence: true, inclusion: { in: [Gitlab::Access::MASTER,
Gitlab::Access::DEVELOPER,
Gitlab::Access::NO_ACCESS] }
def self.human_access_levels def self.human_access_levels
{ {
Gitlab::Access::MASTER => "Masters", Gitlab::Access::MASTER => "Masters",
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
**Valid access levels** **Valid access levels**
The access levels are defined in the `ProtectedBranchAccess::ALLOWED_ACCESS_LEVELS` constant. Currently, these levels are recognized: The access levels are defined in the `ProtectedRefAccess::ALLOWED_ACCESS_LEVELS` constant. Currently, these levels are recognized:
``` ```
0 => No access 0 => No access
30 => Developer access 30 => Developer access
......
...@@ -40,10 +40,10 @@ module API ...@@ -40,10 +40,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, default: Gitlab::Access::MASTER, optional :push_access_level, type: Integer, default: Gitlab::Access::MASTER,
values: ProtectedBranchAccess::ALLOWED_ACCESS_LEVELS, values: ProtectedRefAccess::ALLOWED_ACCESS_LEVELS,
desc: 'Access levels allowed to push (defaults: `40`, master access level)' desc: 'Access levels allowed to push (defaults: `40`, master access level)'
optional :merge_access_level, type: Integer, default: Gitlab::Access::MASTER, optional :merge_access_level, type: Integer, default: Gitlab::Access::MASTER,
values: ProtectedBranchAccess::ALLOWED_ACCESS_LEVELS, values: ProtectedRefAccess::ALLOWED_ACCESS_LEVELS,
desc: 'Access levels allowed to merge (defaults: `40`, master access level)' desc: 'Access levels allowed to merge (defaults: `40`, master access level)'
end end
post ':id/protected_branches' do post ':id/protected_branches' 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