This instance will be upgraded to Heptapod 0.31.0rc on 2022-05-19 at 11:00 UTC+2 (a few minutes of down time)

Commit 9191f538 authored by Kamil Trzcinski's avatar Kamil Trzcinski 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 1dafd9108f78
# 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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment