2018-11-19 21:01:13 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-16 12:28:38 -05:00
|
|
|
module Gitlab
|
2017-05-31 01:50:53 -04:00
|
|
|
module SlashCommands
|
2016-11-16 12:28:38 -05:00
|
|
|
class BaseCommand
|
|
|
|
QUERY_LIMIT = 5
|
|
|
|
|
2016-11-18 05:38:54 -05:00
|
|
|
def self.match(_text)
|
2016-11-16 12:28:38 -05:00
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.help_message
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
2016-11-18 05:38:54 -05:00
|
|
|
def self.available?(_project)
|
2016-11-16 12:28:38 -05:00
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
2016-11-18 05:38:54 -05:00
|
|
|
def self.allowed?(_user, _ability)
|
2016-11-17 15:27:12 -05:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.can?(object, action, subject)
|
|
|
|
Ability.allowed?(object, action, subject)
|
|
|
|
end
|
|
|
|
|
2016-11-16 12:28:38 -05:00
|
|
|
def execute(_)
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
def collection
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
2018-02-22 12:34:04 -05:00
|
|
|
attr_accessor :project, :current_user, :params, :chat_name
|
2016-11-16 12:28:38 -05:00
|
|
|
|
2018-02-22 12:34:04 -05:00
|
|
|
def initialize(project, chat_name, params = {})
|
|
|
|
@project, @current_user, @params = project, chat_name.user, params.dup
|
|
|
|
@chat_name = chat_name
|
2016-11-16 12:28:38 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2016-11-16 12:28:38 -05:00
|
|
|
def find_by_iid(iid)
|
2016-11-25 09:41:28 -05:00
|
|
|
collection.find_by(iid: iid)
|
2016-11-16 12:28:38 -05:00
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2016-11-16 12:28:38 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|