Create relation between chat user and GitLab user and allow to authorize them [ci skip]

This commit is contained in:
Kamil Trzcinski 2016-11-13 20:35:47 +01:00 committed by Z.J. van de Weg
parent 242e291e89
commit 9191f538ba
2 changed files with 65 additions and 0 deletions

View file

@ -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

View file

@ -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