diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-11-13 20:35:47 +0100 |
---|---|---|
committer | Z.J. van de Weg <git@zjvandeweg.nl> | 2016-11-17 21:34:23 +0100 |
commit | 9191f538ba97f59d09c6ffbb747e4a34e30231ee (patch) | |
tree | 4f8a8b4e4be38dd162c1d64f817415c67e2c28e3 | |
parent | 242e291e8999705cb517b8c2dfa2c29704d4ace9 (diff) | |
download | gitlab-ce-9191f538ba97f59d09c6ffbb747e4a34e30231ee.tar.gz |
Create relation between chat user and GitLab user and allow to authorize them [ci skip]
-rw-r--r-- | app/models/project_services/chat_service.rb | 21 | ||||
-rw-r--r-- | app/models/project_services/mattermost_chat_service.rb | 44 |
2 files changed, 65 insertions, 0 deletions
diff --git a/app/models/project_services/chat_service.rb b/app/models/project_services/chat_service.rb new file mode 100644 index 00000000000..c1b6369a5bd --- /dev/null +++ b/app/models/project_services/chat_service.rb @@ -0,0 +1,21 @@ +# Base class for Chat services +class ChatService < Service + default_value_for :category, 'chat' + + has_many :chat_users + + 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) + # implement inside child + end + + def chat_user_params(params) + params.permit() + end +end diff --git a/app/models/project_services/mattermost_chat_service.rb b/app/models/project_services/mattermost_chat_service.rb new file mode 100644 index 00000000000..2adcbf5e5ce --- /dev/null +++ b/app/models/project_services/mattermost_chat_service.rb @@ -0,0 +1,44 @@ +# Base class for Chat services +class MattermostChatService < ChatService + def title + 'Mattermost' + end + + def description + 'Self-hosted Slack-alternative' + end + + def to_param + 'mattermost' + 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, + and enter the token below.' + end + + def fields + [ + { type: 'text', name: 'token', placeholder: 'https://hooks.slack.com/services/...' } + ] + end + + def trigger(params) + user = ChatNames::FindUserService.new(chat_names, params).execute + return authorize_chat_name(params) unless user + + Mattermost::CommandService.new(project, user, params).execute + end + + private + + def authorize_chat_name(params) + url = ChatNames::RequestService.new(service, params).execute + + { + response_type: :ephemeral, + message: "You are not authorized. Click this [link](#{url}) to authorize." + } + end +end |