BigW Consortium Gitlab

access.rb 2.06 KB
Newer Older
1 2 3 4 5 6 7
# Gitlab::Access module
#
# Define allowed roles that can be used
# in GitLab code to determine authorization level
#
module Gitlab
  module Access
8
    AccessDeniedError = Class.new(StandardError)
9

10
    NO_ACCESS = 0
11 12 13 14 15 16
    GUEST     = 10
    REPORTER  = 20
    DEVELOPER = 30
    MASTER    = 40
    OWNER     = 50

17
    # Branch protection settings
18 19 20 21
    PROTECTION_NONE          = 0
    PROTECTION_DEV_CAN_PUSH  = 1
    PROTECTION_FULL          = 2
    PROTECTION_DEV_CAN_MERGE = 3
22

23
    class << self
Douwe Maan committed
24
      delegate :values, to: :options
25

26 27 28 29
      def all_values
        options_with_owner.values
      end

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

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

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

54 55 56 57
      def sym_options_with_owner
        sym_options.merge(owner: OWNER)
      end

58
      def protection_options
59
        {
60
          "Not protected: Both developers and masters can push new commits, force push, or delete the branch." => PROTECTION_NONE,
61
          "Protected against pushes: Developers cannot push new commits, but are allowed to accept merge requests to the branch." => PROTECTION_DEV_CAN_MERGE,
62
          "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,
63
          "Fully protected: Developers cannot push new commits, force push, or delete the branch. Only masters can do any of those." => PROTECTION_FULL
64
        }
65
      end
66

67 68 69
      def protection_values
        protection_options.values
      end
70 71 72 73

      def human_access(access)
        options_with_owner.key(access)
      end
74 75 76
    end

    def human_access
77
      Gitlab::Access.human_access(access_field)
78
    end
79 80 81 82

    def owner?
      access_field == OWNER
    end
83 84
  end
end