BigW Consortium Gitlab

class_methods.rb 1.25 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
module Gitlab
  class CrossProjectAccess
    module ClassMethods
      def requires_cross_project_access(*args)
        positive_condition, negative_condition, actions = extract_params(args)

        Gitlab::CrossProjectAccess.add_check(
          self,
          actions: actions,
          positive_condition: positive_condition,
          negative_condition: negative_condition
        )
      end

      def skip_cross_project_access_check(*args)
        positive_condition, negative_condition, actions = extract_params(args)

        Gitlab::CrossProjectAccess.add_check(
          self,
          actions: actions,
          positive_condition: positive_condition,
          negative_condition: negative_condition,
          skip: true
        )
      end

      private

      def extract_params(args)
        actions = {}
        positive_condition = nil
        negative_condition = nil

        args.each do |argument|
          if argument.is_a?(Hash)
            positive_condition = argument.delete(:if)
            negative_condition = argument.delete(:unless)
            actions.merge!(argument)
          else
            actions[argument] = true
          end
        end

        [positive_condition, negative_condition, actions]
      end
    end
  end
end