From 3774d00b01d6a73d4e10049317e5f042f80101b1 Mon Sep 17 00:00:00 2001 From: Bojan Marjanovic <bmarjanovic@gitlab.com> Date: Fri, 3 Mar 2023 20:12:41 +0000 Subject: [PATCH] Remove integration_id column from chat_names As a part of Identify users in Slack without a project or integration epic, we are dropping the database column. With the column, we are removing associations as well. Changelog: changed --- app/models/chat_name.rb | 4 +++- app/models/integrations/base_slash_commands.rb | 2 -- .../profiles/chat_names/_chat_name.html.haml | 16 ---------------- app/views/profiles/chat_names/index.html.haml | 4 +--- .../lib/slack/block_kit/app_home_opened_spec.rb | 3 +-- .../incident_modal_submit_service_spec.rb | 3 +-- .../integrations/slack_option_service_spec.rb | 3 +-- spec/factories/chat_names.rb | 1 - spec/features/profiles/chat_names_spec.rb | 5 ++--- spec/models/chat_name_spec.rb | 7 ------- spec/models/project_spec.rb | 14 -------------- .../base_slash_commands_shared_examples.rb | 3 +-- 12 files changed, 10 insertions(+), 55 deletions(-) diff --git a/app/models/chat_name.rb b/app/models/chat_name.rb index 9bd618c100875..cda19273f52b4 100644 --- a/app/models/chat_name.rb +++ b/app/models/chat_name.rb @@ -3,7 +3,9 @@ class ChatName < ApplicationRecord LAST_USED_AT_INTERVAL = 1.hour - belongs_to :integration + include IgnorableColumns + ignore_column :integration_id, remove_with: '16.0', remove_after: '2023-04-22' + belongs_to :user validates :user, presence: true diff --git a/app/models/integrations/base_slash_commands.rb b/app/models/integrations/base_slash_commands.rb index eece67b86d4e0..7662da933ba9b 100644 --- a/app/models/integrations/base_slash_commands.rb +++ b/app/models/integrations/base_slash_commands.rb @@ -6,8 +6,6 @@ module Integrations class BaseSlashCommands < Integration attribute :category, default: 'chat' - has_many :chat_names, foreign_key: :integration_id, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent - def valid_token?(token) self.respond_to?(:token) && self.token.present? && diff --git a/app/views/profiles/chat_names/_chat_name.html.haml b/app/views/profiles/chat_names/_chat_name.html.haml index ce2fc2098c506..afc3894c23bb6 100644 --- a/app/views/profiles/chat_names/_chat_name.html.haml +++ b/app/views/profiles/chat_names/_chat_name.html.haml @@ -1,20 +1,4 @@ -- integration = chat_name.integration -- project = integration&.project %tr - %td - %strong - - if project.present? && can?(current_user, :read_project, project) - = link_to project.full_name, project_path(project) - - else - .light= _('Not applicable.') - %td - %strong - - if integration.present? && can?(current_user, :admin_project, project) - = link_to integration.title, edit_project_settings_integration_path(project, integration) - - elsif integration.present? - = integration.title - - else - .light= _('Not applicable.') %td = chat_name.team_domain %td diff --git a/app/views/profiles/chat_names/index.html.haml b/app/views/profiles/chat_names/index.html.haml index 41bd81d0250e6..43d7c9bf7c664 100644 --- a/app/views/profiles/chat_names/index.html.haml +++ b/app/views/profiles/chat_names/index.html.haml @@ -14,11 +14,9 @@ - if @chat_names.present? .table-responsive - %table.table.chat-names + %table.table %thead %tr - %th= _('Project') - %th= _('Service') %th= _('Team domain') %th= _('Nickname') %th= _('Last used') diff --git a/ee/spec/lib/slack/block_kit/app_home_opened_spec.rb b/ee/spec/lib/slack/block_kit/app_home_opened_spec.rb index 38483e4f4c622..e62ba35b5f0f8 100644 --- a/ee/spec/lib/slack/block_kit/app_home_opened_spec.rb +++ b/ee/spec/lib/slack/block_kit/app_home_opened_spec.rb @@ -41,8 +41,7 @@ create(:chat_name, user: user, team_id: slack_installation.team_id, - chat_id: slack_installation.user_id, - integration: slack_installation.integration + chat_id: slack_installation.user_id ) end diff --git a/ee/spec/services/integrations/slack_interactions/incident_management/incident_modal_submit_service_spec.rb b/ee/spec/services/integrations/slack_interactions/incident_management/incident_modal_submit_service_spec.rb index 85db41e5e4be1..23de294fb1004 100644 --- a/ee/spec/services/integrations/slack_interactions/incident_management/incident_modal_submit_service_spec.rb +++ b/ee/spec/services/integrations/slack_interactions/incident_management/incident_modal_submit_service_spec.rb @@ -16,8 +16,7 @@ create(:chat_name, user: user, team_id: slack_installation.team_id, - chat_id: slack_installation.user_id, - integration: slack_installation.integration + chat_id: slack_installation.user_id ) end diff --git a/ee/spec/services/integrations/slack_option_service_spec.rb b/ee/spec/services/integrations/slack_option_service_spec.rb index 30c494dbe7a19..2e114b932d2ec 100644 --- a/ee/spec/services/integrations/slack_option_service_spec.rb +++ b/ee/spec/services/integrations/slack_option_service_spec.rb @@ -13,8 +13,7 @@ create(:chat_name, user: user, team_id: slack_installation.team_id, - chat_id: slack_installation.user_id, - integration: slack_installation.integration + chat_id: slack_installation.user_id ) end diff --git a/spec/factories/chat_names.rb b/spec/factories/chat_names.rb index 56567394bf50c..c872694ee6463 100644 --- a/spec/factories/chat_names.rb +++ b/spec/factories/chat_names.rb @@ -3,7 +3,6 @@ FactoryBot.define do factory :chat_name, class: 'ChatName' do user - integration team_id { 'T0001' } team_domain { 'Awesome Team' } diff --git a/spec/features/profiles/chat_names_spec.rb b/spec/features/profiles/chat_names_spec.rb index 299ecdb60321c..9e1bd69a239a2 100644 --- a/spec/features/profiles/chat_names_spec.rb +++ b/spec/features/profiles/chat_names_spec.rb @@ -3,8 +3,7 @@ require 'spec_helper' RSpec.describe 'Profile > Chat', feature_category: :user_profile do - let(:user) { create(:user) } - let(:integration) { create(:integration) } + let_it_be(:user) { create(:user) } before do sign_in(user) @@ -60,7 +59,7 @@ end describe 'visits chat accounts' do - let!(:chat_name) { create(:chat_name, user: user, integration: integration) } + let_it_be(:chat_name) { create(:chat_name, user: user) } before do visit profile_chat_names_path diff --git a/spec/models/chat_name_spec.rb b/spec/models/chat_name_spec.rb index 0838c2328723d..9d6b1a56458b5 100644 --- a/spec/models/chat_name_spec.rb +++ b/spec/models/chat_name_spec.rb @@ -7,7 +7,6 @@ subject { chat_name } - it { is_expected.to belong_to(:integration) } it { is_expected.to belong_to(:user) } it { is_expected.to validate_presence_of(:user) } @@ -16,12 +15,6 @@ it { is_expected.to validate_uniqueness_of(:chat_id).scoped_to(:team_id) } - it 'is not removed when the project is deleted' do - expect { subject.reload.integration.project.delete }.not_to change { ChatName.count } - - expect(ChatName.where(id: subject.id)).to exist - end - describe '#update_last_used_at', :clean_gitlab_redis_shared_state do it 'updates the last_used_at timestamp' do expect(subject.last_used_at).to be_nil diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 7d431de9f0713..d11257cbf8908 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -7326,20 +7326,6 @@ def has_external_wiki end end - describe 'with integrations and chat names' do - subject { create(:project) } - - let(:integration) { create(:integration, project: subject) } - - before do - create_list(:chat_name, 5, integration: integration) - end - - it 'does not remove chat names on removal' do - expect { subject.destroy! }.not_to change { ChatName.count } - end - end - describe 'with_issues_or_mrs_available_for_user' do before do Project.delete_all diff --git a/spec/support/shared_examples/models/integrations/base_slash_commands_shared_examples.rb b/spec/support/shared_examples/models/integrations/base_slash_commands_shared_examples.rb index 7dfdd24177e28..0cf109ce5c5eb 100644 --- a/spec/support/shared_examples/models/integrations/base_slash_commands_shared_examples.rb +++ b/spec/support/shared_examples/models/integrations/base_slash_commands_shared_examples.rb @@ -3,7 +3,6 @@ RSpec.shared_examples Integrations::BaseSlashCommands do describe "Associations" do it { is_expected.to respond_to :token } - it { is_expected.to have_many :chat_names } end describe 'default values' do @@ -85,7 +84,7 @@ end context 'when the user is authenticated' do - let!(:chat_name) { create(:chat_name, integration: subject) } + let!(:chat_name) { create(:chat_name) } let(:params) { { token: 'token', team_id: chat_name.team_id, user_id: chat_name.chat_id } } subject do -- GitLab