debian-mirror-gitlab/app/models/concerns/protected_ref_access.rb

42 lines
1,011 B
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
module ProtectedRefAccess
extend ActiveSupport::Concern
2018-03-17 18:26:18 +05:30
ALLOWED_ACCESS_LEVELS = [
Gitlab::Access::MASTER,
Gitlab::Access::DEVELOPER,
Gitlab::Access::NO_ACCESS
].freeze
HUMAN_ACCESS_LEVELS = {
Gitlab::Access::MASTER => "Masters".freeze,
Gitlab::Access::DEVELOPER => "Developers + Masters".freeze,
Gitlab::Access::NO_ACCESS => "No one".freeze
}.freeze
2017-08-17 22:00:37 +05:30
included do
scope :master, -> { where(access_level: Gitlab::Access::MASTER) }
scope :developer, -> { where(access_level: Gitlab::Access::DEVELOPER) }
2018-03-17 18:26:18 +05:30
validates :access_level, presence: true, if: :role?, inclusion: {
in: ALLOWED_ACCESS_LEVELS
}
2017-08-17 22:00:37 +05:30
end
def humanize
2018-03-17 18:26:18 +05:30
HUMAN_ACCESS_LEVELS[self.access_level]
end
# CE access levels are always role-based,
# where as EE allows groups and users too
def role?
true
2017-08-17 22:00:37 +05:30
end
def check_access(user)
return true if user.admin?
2018-03-27 19:54:05 +05:30
user.can?(:push_code, project) &&
project.team.max_member_access(user.id) >= access_level
2017-08-17 22:00:37 +05:30
end
end