Skip to content

Allow Slack app to be reinstalled

Markus Koller requested to merge 360681-allow-slack-app-to-be-reinstalled into master

What does this MR do and why?

To roll out future updates we have to provide a button on the integration form to reinstall the app, which works the same as installing the app for the first time.

This replaces the current "Add to Slack" PNG button with an SVG version, and also displays the button with the label "Reinstall Slack app" when the app is already installed.

In the backend we update the existing SlackIntegration record instead of failing when it already exists.

We also start storing the bot user ID and access token, which we don't use yet but will need for other features.

Issue: #360681 (closed)

Migration output

db/migrate/20220502150408_add_slack_integrations_bot_columns.rb

$ rails db:migrate:up VERSION=20220502150408
== 20220502150408 AddSlackIntegrationsBotColumns: migrating ===================
-- change_table(:slack_integrations)
   -> 0.0152s
== 20220502150408 AddSlackIntegrationsBotColumns: migrated (0.0152s) ==========

$ rails db:migrate:down VERSION=20220502150408
== 20220502150408 AddSlackIntegrationsBotColumns: reverting ===================
-- remove_column(:slack_integrations, :encrypted_bot_access_token_iv, :binary, {})
   -> 0.0051s
-- remove_column(:slack_integrations, :encrypted_bot_access_token, :binary, {})
   -> 0.0012s
-- remove_column(:slack_integrations, :bot_user_id, :text, {})
   -> 0.0011s
== 20220502150408 AddSlackIntegrationsBotColumns: reverted (0.0097s) ==========

db/migrate/20220502152633_add_slack_integrations_bot_user_id_text_limit.rb

$ rails db:migrate:up VERSION=20220502152633
== 20220502152633 AddSlackIntegrationsBotUserIdTextLimit: migrating ===========
-- transaction_open?()
   -> 0.0000s
-- current_schema()
   -> 0.0010s
-- transaction_open?()
   -> 0.0000s
-- execute("ALTER TABLE slack_integrations\nADD CONSTRAINT check_bc553aea8a\nCHECK ( char_length(bot_user_id) <= 255 )\nNOT VALID;\n")
   -> 0.0027s
-- current_schema()
   -> 0.0004s
-- execute("SET statement_timeout TO 0")
   -> 0.0008s
-- execute("ALTER TABLE slack_integrations VALIDATE CONSTRAINT check_bc553aea8a;")
   -> 0.0015s
-- execute("RESET statement_timeout")
   -> 0.0008s
== 20220502152633 AddSlackIntegrationsBotUserIdTextLimit: migrated (0.0353s) ==

$ rails db:migrate:down VERSION=20220502152633
== 20220502152633 AddSlackIntegrationsBotUserIdTextLimit: reverting ===========
-- transaction_open?()
   -> 0.0000s
-- transaction_open?()
   -> 0.0000s
-- execute("ALTER TABLE slack_integrations\nDROP CONSTRAINT IF EXISTS check_bc553aea8a\n")
   -> 0.0057s
== 20220502152633 AddSlackIntegrationsBotUserIdTextLimit: reverted (0.0256s) ==

Screenshots or screen recordings

Before After
image image
image image

How to set up and validate locally

You need access to Gitpod and the Ecosystem Slack workspace.

  1. Boot up a Gitpod instance with this MR.
  2. Set up the GitLab (dev) app: https://gitlab.com/gitlab-org/ecosystem-stage/integrations/team/-/blob/main/integrations/slack.md#set-up-a-development-environment-for-the-gitlab-dev-slack-application
  3. Install the app from a GitLab project.
  4. Check the SlackIntegration record in a Rails console, see bot_user_id and bot_access_token missing.
  5. Enable the FF: Feature.enable(:slack_app_use_v2_flow)
  6. Reinstall the app from the same project.
  7. Check the SlackIntegration record again, see bot_user_id and bot_access_token being present.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Markus Koller

Merge request reports