2016-11-18 15:16:45 +00:00
|
|
|
class MattermostSlashCommandsService < ChatService
|
2016-11-14 14:10:35 +00:00
|
|
|
include TriggersHelper
|
|
|
|
|
|
|
|
prop_accessor :token
|
|
|
|
|
|
|
|
def can_test?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2016-11-13 19:35:47 +00:00
|
|
|
def title
|
2016-11-17 11:06:45 +00:00
|
|
|
'Mattermost Command'
|
2016-11-13 19:35:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
2016-11-18 12:29:47 +00:00
|
|
|
"Perform common operations on GitLab in Mattermost"
|
2016-11-13 19:35:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_param
|
2016-11-18 15:16:45 +00:00
|
|
|
'mattermost_slash_commands'
|
2016-11-13 19:35:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def fields
|
|
|
|
[
|
2016-11-14 14:10:35 +00:00
|
|
|
{ type: 'text', name: 'token', placeholder: '' }
|
2016-11-13 19:35:47 +00:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
def trigger(params)
|
2016-11-17 11:06:45 +00:00
|
|
|
return nil unless valid_token?(params[:token])
|
2016-11-13 19:35:47 +00:00
|
|
|
|
2016-11-17 11:06:45 +00:00
|
|
|
user = find_chat_user(params)
|
|
|
|
unless user
|
|
|
|
url = authorize_chat_name_url(params)
|
2016-11-17 20:27:12 +00:00
|
|
|
return Mattermost::Presenter.authorize_chat_name(url)
|
2016-11-17 11:06:45 +00:00
|
|
|
end
|
|
|
|
|
2016-11-17 20:27:12 +00:00
|
|
|
Gitlab::ChatCommands::Command.new(project, user, params).execute
|
2016-11-17 11:06:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def find_chat_user(params)
|
2016-11-17 20:27:12 +00:00
|
|
|
ChatNames::FindUserService.new(self, params).execute
|
2016-11-17 11:06:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_chat_name_url(params)
|
2016-11-17 20:27:12 +00:00
|
|
|
ChatNames::AuthorizeUserService.new(self, params).execute
|
2016-11-13 19:35:47 +00:00
|
|
|
end
|
|
|
|
end
|