push_access_level.rb 844 Bytes
Newer Older
1
class ProtectedBranch::PushAccessLevel < ActiveRecord::Base
2 3
  include ProtectedBranchAccess

4
  belongs_to :protected_branch
5
  delegate :project, to: :protected_branch
6

7 8 9
  validates :access_level, presence: true, inclusion: { in: [Gitlab::Access::MASTER,
                                                             Gitlab::Access::DEVELOPER,
                                                             Gitlab::Access::NO_ACCESS] }
10

11 12
  def self.human_access_levels
    {
13 14 15
      Gitlab::Access::MASTER => "Masters",
      Gitlab::Access::DEVELOPER => "Developers + Masters",
      Gitlab::Access::NO_ACCESS => "No one"
16 17 18
    }.with_indifferent_access
  end

19
  def check_access(user)
20
    return false if access_level == Gitlab::Access::NO_ACCESS
21
    return true if user.is_admin?
22

23
    project.team.max_member_access(user.id) >= access_level
24
  end
25
end