BigW Consortium Gitlab

base_command.rb 960 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
      def execute(_)
        raise NotImplementedError
      end

      def collection
        raise NotImplementedError
      end

34
      attr_accessor :project, :current_user, :params, :chat_name
35

36 37 38
      def initialize(project, chat_name, params = {})
        @project, @current_user, @params = project, chat_name.user, params.dup
        @chat_name = chat_name
39 40 41 42 43
      end

      private

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