protected_ref_access.rb 514 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
module ProtectedBranchAccess
  extend ActiveSupport::Concern

  included do
    belongs_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