2016-08-16 05:09:13 +00:00
|
|
|
module ProtectedBranchAccess
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2017-08-02 10:16:17 +00:00
|
|
|
ALLOWED_ACCESS_LEVELS ||= [
|
|
|
|
Gitlab::Access::MASTER,
|
|
|
|
Gitlab::Access::DEVELOPER,
|
|
|
|
Gitlab::Access::NO_ACCESS
|
|
|
|
].freeze
|
|
|
|
|
2016-09-06 05:05:34 +00:00
|
|
|
included do
|
2017-04-04 01:59:37 +00:00
|
|
|
include ProtectedRefAccess
|
|
|
|
|
2016-11-29 11:21:50 +00:00
|
|
|
belongs_to :protected_branch
|
2017-04-05 17:59:46 +00:00
|
|
|
|
2016-11-29 11:21:50 +00:00
|
|
|
delegate :project, to: :protected_branch
|
2017-05-10 08:46:50 +00:00
|
|
|
|
2017-05-12 10:41:39 +00:00
|
|
|
validates :access_level, presence: true, inclusion: {
|
2017-08-02 10:16:17 +00:00
|
|
|
in: ALLOWED_ACCESS_LEVELS
|
2017-05-12 10:41:39 +00:00
|
|
|
}
|
2017-05-10 08:46:50 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
2016-11-29 11:21:50 +00:00
|
|
|
end
|
2016-08-16 05:09:13 +00:00
|
|
|
end
|