Skip to content
Snippets Groups Projects
Commit 9191f538 authored by Kamil Trzcińśki's avatar Kamil Trzcińśki Committed by Z.J. van de Weg
Browse files

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

parent 242e291e
No related branches found
No related tags found
No related merge requests found
# 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
# 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment