summaryrefslogtreecommitdiff
path: root/app/models/project_services/mattermost_slash_commands_service.rb
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-11-18 16:16:45 +0100
committerKamil Trzcinski <ayufan@ayufan.eu>2016-11-18 17:27:14 +0100
commit1db1896ed2375481d53f74f7900d259fe068ef64 (patch)
treeec82ca5c9ba8da236aa78a207c7926dcf3ef5fe4 /app/models/project_services/mattermost_slash_commands_service.rb
parentc72c76fde3882b7c2f778bf85132cd2c80f01f5b (diff)
downloadgitlab-ce-1db1896ed2375481d53f74f7900d259fe068ef64.tar.gz
Rename mattermost_command to mattermost_slash_commandszj-slash-commands-mattermost
Diffstat (limited to 'app/models/project_services/mattermost_slash_commands_service.rb')
-rw-r--r--app/models/project_services/mattermost_slash_commands_service.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/app/models/project_services/mattermost_slash_commands_service.rb b/app/models/project_services/mattermost_slash_commands_service.rb
new file mode 100644
index 00000000000..67902329593
--- /dev/null
+++ b/app/models/project_services/mattermost_slash_commands_service.rb
@@ -0,0 +1,56 @@
+class MattermostSlashCommandsService < ChatService
+ include TriggersHelper
+
+ prop_accessor :token
+
+ def can_test?
+ false
+ end
+
+ def title
+ 'Mattermost Command'
+ end
+
+ def description
+ "Perform common operations on GitLab in Mattermost"
+ end
+
+ def to_param
+ 'mattermost_slash_commands'
+ end
+
+ def help
+ "This service allows you to use slash commands with your Mattermost installation.<br/>
+ To setup this Service you need to create a new <b>Slash commands</b> in your Mattermost integration panel.<br/>
+ <br/>
+ Create integration with URL #{service_trigger_url(self)} and enter the token below."
+ 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
+ end
+end