Class: Projects::SlackApplicationInstallService

Inherits:
BaseService
  • Object
show all
Includes:
Gitlab::Routing
Defined in:
app/services/projects/slack_application_install_service.rb

Constant Summary collapse

SLACK_AUTHORIZE_URL =

Endpoint to initiate the OAuth flow, redirects to Slack’s authorization screen api.slack.com/authentication/oauth-v2#asking

'https://slack.com/oauth/v2/authorize'
SLACK_EXCHANGE_TOKEN_URL =

Endpoint to exchange the temporary authorization code for an access token api.slack.com/authentication/oauth-v2#exchanging

'https://slack.com/api/oauth.v2.access'

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods included from Gitlab::Routing

includes_helpers, redirect_legacy_paths, url_helpers

Methods inherited from BaseService

#initialize

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#executeObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/services/projects/slack_application_install_service.rb', line 15

def execute
  slack_data = exchange_slack_token

  return error("Slack: #{slack_data['error']}") unless slack_data['ok']

  integration = project.gitlab_slack_application_integration \
    || project.create_gitlab_slack_application_integration!

  installation = integration.slack_integration || integration.build_slack_integration

  installation.update!(
    bot_user_id: slack_data['bot_user_id'],
    bot_access_token: slack_data['access_token'],
    team_id: slack_data.dig('team', 'id'),
    team_name: slack_data.dig('team', 'name'),
    alias: project.full_path,
    user_id: slack_data.dig('authed_user', 'id'),
    authorized_scope_names: slack_data['scope']
  )

  update_legacy_installations!(installation)

  success
end