BigW Consortium Gitlab

protected_branch_access.rb 772 Bytes
Newer Older
1 2 3
module ProtectedBranchAccess
  extend ActiveSupport::Concern

4 5 6 7 8 9
  ALLOWED_ACCESS_LEVELS ||= [
    Gitlab::Access::MASTER,
    Gitlab::Access::DEVELOPER,
    Gitlab::Access::NO_ACCESS
  ].freeze

10
  included do
11 12
    include ProtectedRefAccess

13
    belongs_to :protected_branch
14

15
    delegate :project, to: :protected_branch
16

17
    validates :access_level, presence: true, inclusion: {
18
      in: ALLOWED_ACCESS_LEVELS
19
    }
20 21 22 23 24 25 26 27 28 29 30 31 32 33

    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
34
  end
35
end