BigW Consortium Gitlab

base_command.rb 902 Bytes
Newer Older
1
module Gitlab
2
  module SlashCommands
3 4 5
    class BaseCommand
      QUERY_LIMIT = 5

6
      def self.match(_text)
7 8 9 10 11 12 13
        raise NotImplementedError
      end

      def self.help_message
        raise NotImplementedError
      end

14
      def self.available?(_project)
15 16 17
        raise NotImplementedError
      end

18
      def self.allowed?(_user, _ability)
19 20 21 22 23 24 25
        true
      end

      def self.can?(object, action, subject)
        Ability.allowed?(object, action, subject)
      end

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
      def execute(_)
        raise NotImplementedError
      end

      def collection
        raise NotImplementedError
      end

      attr_accessor :project, :current_user, :params

      def initialize(project, user, params = {})
        @project, @current_user, @params = project, user, params.dup
      end

      private

      def find_by_iid(iid)
43
        collection.find_by(iid: iid)
44 45 46 47
      end
    end
  end
end