Commit ed880e49 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Rename ChatService into ChatSlashCommandsService

parent 0d3e2435
...@@ -79,7 +79,6 @@ class Project < ActiveRecord::Base ...@@ -79,7 +79,6 @@ class Project < ActiveRecord::Base
has_one :last_event, -> {order 'events.created_at DESC'}, class_name: 'Event' has_one :last_event, -> {order 'events.created_at DESC'}, class_name: 'Event'
has_many :boards, before_add: :validate_board_limit, dependent: :destroy has_many :boards, before_add: :validate_board_limit, dependent: :destroy
has_many :chat_services
# Project services # Project services
has_one :campfire_service, dependent: :destroy has_one :campfire_service, dependent: :destroy
......
# Base class for Chat services # Base class for Chat services
# This class is not meant to be used directly, but only to inherit from. # This class is not meant to be used directly, but only to inherrit from.
class ChatService < Service class ChatSlashCommandsService < Service
default_value_for :category, 'chat' default_value_for :category, 'chat'
prop_accessor :token
has_many :chat_names, foreign_key: :service_id has_many :chat_names, foreign_key: :service_id
def valid_token?(token) def valid_token?(token)
...@@ -15,7 +17,39 @@ class ChatService < Service ...@@ -15,7 +17,39 @@ class ChatService < Service
[] []
end end
def can_test?
false
end
def fields
[
{ type: 'text', name: 'token', placeholder: '' }
]
end
def trigger(params) def trigger(params)
raise NotImplementedError 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
end end
...@@ -19,31 +19,7 @@ class MattermostSlashCommandsService < ChatService ...@@ -19,31 +19,7 @@ class MattermostSlashCommandsService < ChatService
'mattermost_slash_commands' 'mattermost_slash_commands'
end end
def fields def presenter
[ Gitlab::ChatCommands::Presenters::Mattermost.new
{ 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
end end
end end
class SlackSlashCommandsService < ChatService class SlackSlashCommandsService < ChatSlashCommandsService
include TriggersHelper include TriggersHelper
prop_accessor :token
def can_test?
false
end
def title def title
'Slack Slash Command' 'Slack Slash Command'
end end
...@@ -19,31 +13,7 @@ class SlackSlashCommandsService < ChatService ...@@ -19,31 +13,7 @@ class SlackSlashCommandsService < ChatService
'slack_slash_commands' 'slack_slash_commands'
end end
def fields def presenter
[ Gitlab::ChatCommands::Presenters::Mattermost.new
{ 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
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment