Rename ChatService into ChatSlashCommandsService
This commit is contained in:
parent
0d3e24358b
commit
ed880e4954
5 changed files with 60 additions and 81 deletions
|
@ -79,7 +79,6 @@ class Project < ActiveRecord::Base
|
|||
|
||||
has_one :last_event, -> {order 'events.created_at DESC'}, class_name: 'Event'
|
||||
has_many :boards, before_add: :validate_board_limit, dependent: :destroy
|
||||
has_many :chat_services
|
||||
|
||||
# Project services
|
||||
has_one :campfire_service, dependent: :destroy
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
# Base class for Chat services
|
||||
# This class is not meant to be used directly, but only to inherit from.
|
||||
class ChatService < Service
|
||||
default_value_for :category, 'chat'
|
||||
|
||||
has_many :chat_names, foreign_key: :service_id
|
||||
|
||||
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 trigger(params)
|
||||
raise NotImplementedError
|
||||
end
|
||||
end
|
55
app/models/project_services/chat_slash_commands_service.rb
Normal file
55
app/models/project_services/chat_slash_commands_service.rb
Normal file
|
@ -0,0 +1,55 @@
|
|||
# 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
|
||||
|
||||
has_many :chat_names, foreign_key: :service_id
|
||||
|
||||
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)
|
||||
return nil unless valid_token?(params[:token])
|
||||
|
||||
user = find_chat_user(params)
|
||||
unless user
|
||||
url = authorize_chat_name_url(params)
|
||||
return presenter.authorize_chat_name(url)
|
||||
end
|
||||
|
||||
Gitlab::ChatCommands::Command.new(presenter, project, user, params).execute
|
||||
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
|
||||
|
||||
def presenter
|
||||
throw NotImplementedError
|
||||
end
|
||||
end
|
|
@ -19,31 +19,7 @@ class MattermostSlashCommandsService < ChatService
|
|||
'mattermost_slash_commands'
|
||||
end
|
||||
|
||||
def fields
|
||||
[
|
||||
{ type: 'text', name: 'token', placeholder: '' }
|
||||
]
|
||||
end
|
||||
|
||||
def trigger(params)
|
||||
return nil unless valid_token?(params[:token])
|
||||
|
||||
user = find_chat_user(params)
|
||||
unless user
|
||||
url = authorize_chat_name_url(params)
|
||||
return Mattermost::Presenter.authorize_chat_name(url)
|
||||
end
|
||||
|
||||
Gitlab::ChatCommands::Command.new(project, user, params).execute
|
||||
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
|
||||
def presenter
|
||||
Gitlab::ChatCommands::Presenters::Mattermost.new
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
class SlackSlashCommandsService < ChatService
|
||||
class SlackSlashCommandsService < ChatSlashCommandsService
|
||||
include TriggersHelper
|
||||
|
||||
prop_accessor :token
|
||||
|
||||
def can_test?
|
||||
false
|
||||
end
|
||||
|
||||
def title
|
||||
'Slack Slash Command'
|
||||
end
|
||||
|
@ -19,31 +13,7 @@ class SlackSlashCommandsService < ChatService
|
|||
'slack_slash_commands'
|
||||
end
|
||||
|
||||
def fields
|
||||
[
|
||||
{ type: 'text', name: 'token', placeholder: '' }
|
||||
]
|
||||
end
|
||||
|
||||
def trigger(params)
|
||||
return nil unless valid_token?(params[:token])
|
||||
|
||||
user = find_chat_user(params)
|
||||
unless user
|
||||
url = authorize_chat_name_url(params)
|
||||
return Gitlab::ChatCommands::Presenters::Access.new(url).authorize
|
||||
end
|
||||
|
||||
Gitlab::ChatCommands::Command.new(project, user, params).execute
|
||||
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
|
||||
def presenter
|
||||
Gitlab::ChatCommands::Presenters::Mattermost.new
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue