2016-12-15 17:45:10 -05:00
|
|
|
# Base class for Chat services
|
|
|
|
# This class is not meant to be used directly, but only to inherrit from.
|
|
|
|
class ChatSlashCommandsService < Service
|
|
|
|
default_value_for :category, 'chat'
|
|
|
|
|
|
|
|
prop_accessor :token
|
|
|
|
|
2016-12-16 08:21:06 -05:00
|
|
|
has_many :chat_names, foreign_key: :service_id, dependent: :destroy
|
2016-12-15 17:45:10 -05:00
|
|
|
|
|
|
|
def valid_token?(token)
|
|
|
|
self.respond_to?(:token) &&
|
|
|
|
self.token.present? &&
|
|
|
|
ActiveSupport::SecurityUtils.variable_size_secure_compare(token, self.token)
|
|
|
|
end
|
|
|
|
|
|
|
|
def supported_events
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_test?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def fields
|
|
|
|
[
|
|
|
|
{ type: 'text', name: 'token', placeholder: '' }
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
def trigger(params)
|
2016-12-19 07:32:37 -05:00
|
|
|
return unless valid_token?(params[:token])
|
2016-12-15 17:45:10 -05:00
|
|
|
|
|
|
|
user = find_chat_user(params)
|
|
|
|
unless user
|
|
|
|
url = authorize_chat_name_url(params)
|
2016-12-15 18:00:54 -05:00
|
|
|
return presenter.authorize_chat_name(url)
|
2016-12-15 17:45:10 -05:00
|
|
|
end
|
|
|
|
|
2016-12-15 18:00:54 -05:00
|
|
|
Gitlab::ChatCommands::Command.new(project, user,
|
2016-12-16 09:08:10 -05:00
|
|
|
params).execute
|
2016-12-15 17:45:10 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def find_chat_user(params)
|
|
|
|
ChatNames::FindUserService.new(self, params).execute
|
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_chat_name_url(params)
|
|
|
|
ChatNames::AuthorizeUserService.new(self, params).execute
|
|
|
|
end
|
2016-12-15 18:00:54 -05:00
|
|
|
|
|
|
|
def presenter
|
2016-12-16 09:08:10 -05:00
|
|
|
Gitlab::ChatCommands::Presenter.new
|
2016-12-15 18:00:54 -05:00
|
|
|
end
|
2016-12-15 17:45:10 -05:00
|
|
|
end
|