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