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