BigW Consortium Gitlab

access.rb 1.67 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
# Gitlab::Access module
#
# Define allowed roles that can be used
# in GitLab code to determine authorization level
#
module Gitlab
  module Access
    GUEST     = 10
    REPORTER  = 20
    DEVELOPER = 30
    MASTER    = 40
    OWNER     = 50

14 15 16 17 18
    # Branch protection settings
    PROTECTION_NONE         = 0
    PROTECTION_DEV_CAN_PUSH = 1
    PROTECTION_FULL         = 2

19 20 21 22 23
    class << self
      def values
        options.values
      end

24 25 26 27
      def all_values
        options_with_owner.values
      end

28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
      def options
        {
          "Guest"     => GUEST,
          "Reporter"  => REPORTER,
          "Developer" => DEVELOPER,
          "Master"    => MASTER,
        }
      end

      def options_with_owner
        options.merge(
          "Owner" => OWNER
        )
      end

      def sym_options
        {
          guest:     GUEST,
          reporter:  REPORTER,
          developer: DEVELOPER,
          master:    MASTER,
        }
      end
51 52

      def protection_options
53
        {
54 55 56
          "Not protected: Both developers and masters can push new commits, force push, or delete the branch." => PROTECTION_NONE,
          "Partially protected: Developers can push new commits, but cannot force push or delete the branch. Masters can do all of those." => PROTECTION_DEV_CAN_PUSH,
          "Fully protected: Developers cannot push new commits, force push, or delete the branch. Only masters can do any of those." => PROTECTION_FULL,
57
        }
58
      end
59

60 61 62
      def protection_values
        protection_options.values
      end
63 64 65 66 67
    end

    def human_access
      Gitlab::Access.options_with_owner.key(access_field)
    end
68 69 70 71

    def owner?
      access_field == OWNER
    end
72 73
  end
end