Add latest changes from gitlab-org/gitlab@master

This commit is contained in:
GitLab Bot 2022-08-13 03:09:28 +00:00
parent 50a75eed99
commit 0faed4500e
12 changed files with 59 additions and 40 deletions

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
module FormHelper
def form_errors(model, type: 'form', truncate: [], pajamas_alert: false)
def form_errors(model, type: 'form', truncate: [], pajamas_alert: true)
errors = model.errors
return unless errors.any?
@ -25,26 +25,17 @@ module FormHelper
tag.li(message)
end.join.html_safe
if pajamas_alert
render Pajamas::AlertComponent.new(
variant: :danger,
title: headline,
dismissible: false,
alert_options: { id: 'error_explanation', class: 'gl-mb-5' }
) do |c|
c.body do
tag.ul(class: 'gl-pl-5 gl-mb-0') do
messages
end
render Pajamas::AlertComponent.new(
variant: :danger,
title: headline,
dismissible: false,
alert_options: { id: 'error_explanation', class: 'gl-mb-5' }
) do |c|
c.body do
tag.ul(class: 'gl-pl-5 gl-mb-0') do
messages
end
end
else
tag.div(class: 'alert alert-danger', id: 'error_explanation') do
tag.h4(headline) <<
tag.ul do
messages
end
end
end
end

View File

@ -3,7 +3,7 @@
class ChatName < ApplicationRecord
LAST_USED_AT_INTERVAL = 1.hour
belongs_to :integration, foreign_key: :service_id
belongs_to :integration
belongs_to :user
validates :user, presence: true
@ -11,8 +11,8 @@ class ChatName < ApplicationRecord
validates :team_id, presence: true
validates :chat_id, presence: true
validates :user_id, uniqueness: { scope: [:service_id] }
validates :chat_id, uniqueness: { scope: [:service_id, :team_id] }
validates :user_id, uniqueness: { scope: [:integration_id] }
validates :chat_id, uniqueness: { scope: [:integration_id, :team_id] }
# Updates the "last_used_timestamp" but only if it wasn't already updated
# recently.

View File

@ -8,7 +8,7 @@ module Integrations
prop_accessor :token
has_many :chat_names, foreign_key: :service_id, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
has_many :chat_names, foreign_key: :integration_id, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
def valid_token?(token)
self.respond_to?(:token) &&

View File

@ -4,8 +4,8 @@ module ChatNames
class AuthorizeUserService
include Gitlab::Routing
def initialize(service, params)
@service = service
def initialize(integration, params)
@integration = integration
@params = params
end
@ -29,7 +29,7 @@ module ChatNames
def chat_name_params
{
service_id: @service.id,
integration_id: @integration.id,
team_id: @params[:team_id],
team_domain: @params[:team_domain],
chat_id: @params[:user_id],

View File

@ -0,0 +1,13 @@
# frozen_string_literal: true
class RenameChatNameServiceIdToIntegrationId < Gitlab::Database::Migration[2.0]
disable_ddl_transaction!
def up
rename_column_concurrently :chat_names, :service_id, :integration_id
end
def down
undo_rename_column_concurrently :chat_names, :service_id, :integration_id
end
end

View File

@ -0,0 +1,13 @@
# frozen_string_literal: true
class CleanupChatNameServiceId < Gitlab::Database::Migration[2.0]
disable_ddl_transaction!
def up
cleanup_concurrent_column_rename :chat_names, :service_id, :integration_id
end
def down
undo_cleanup_concurrent_column_rename :chat_names, :service_id, :integration_id
end
end

View File

@ -0,0 +1 @@
2f3dc1952c43a6786f8a66713ac89ca24f828f683a57f7373c91d5e629242909

View File

@ -0,0 +1 @@
82504ed0c287565d9b9eadf929badaa893beaac36224c7c2c7b4e14a663fa9e5

View File

@ -12423,14 +12423,15 @@ ALTER SEQUENCE bulk_imports_id_seq OWNED BY bulk_imports.id;
CREATE TABLE chat_names (
id integer NOT NULL,
user_id integer NOT NULL,
service_id integer NOT NULL,
team_id character varying NOT NULL,
team_domain character varying,
chat_id character varying NOT NULL,
chat_name character varying,
last_used_at timestamp without time zone,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
updated_at timestamp without time zone NOT NULL,
integration_id integer,
CONSTRAINT check_2b0a0d0f0f CHECK ((integration_id IS NOT NULL))
);
CREATE SEQUENCE chat_names_id_seq
@ -27659,9 +27660,9 @@ CREATE INDEX index_bulk_import_failures_on_correlation_id_value ON bulk_import_f
CREATE INDEX index_bulk_imports_on_user_id ON bulk_imports USING btree (user_id);
CREATE UNIQUE INDEX index_chat_names_on_service_id_and_team_id_and_chat_id ON chat_names USING btree (service_id, team_id, chat_id);
CREATE UNIQUE INDEX index_chat_names_on_integration_id_and_team_id_and_chat_id ON chat_names USING btree (integration_id, team_id, chat_id);
CREATE UNIQUE INDEX index_chat_names_on_user_id_and_service_id ON chat_names USING btree (user_id, service_id);
CREATE UNIQUE INDEX index_chat_names_on_user_id_and_integration_id ON chat_names USING btree (user_id, integration_id);
CREATE UNIQUE INDEX index_chat_teams_on_namespace_id ON chat_teams USING btree (namespace_id);
@ -31891,9 +31892,6 @@ CREATE TRIGGER trigger_update_vulnerability_reads_on_vulnerability_update AFTER
CREATE TRIGGER users_loose_fk_trigger AFTER DELETE ON users REFERENCING OLD TABLE AS old_table FOR EACH STATEMENT EXECUTE FUNCTION insert_into_loose_foreign_keys_deleted_records();
ALTER TABLE ONLY chat_names
ADD CONSTRAINT fk_00797a2bf9 FOREIGN KEY (service_id) REFERENCES integrations(id) ON DELETE CASCADE;
ALTER TABLE ONLY deployments
ADD CONSTRAINT fk_009fd21147 FOREIGN KEY (environment_id) REFERENCES environments(id) ON DELETE CASCADE NOT VALID;
@ -32398,6 +32396,9 @@ ALTER TABLE ONLY vulnerability_occurrences
ALTER TABLE ONLY protected_branch_merge_access_levels
ADD CONSTRAINT fk_98f3d044fe FOREIGN KEY (group_id) REFERENCES namespaces(id) ON DELETE CASCADE;
ALTER TABLE ONLY chat_names
ADD CONSTRAINT fk_99a1348daf FOREIGN KEY (integration_id) REFERENCES integrations(id) ON DELETE CASCADE;
ALTER TABLE ONLY notes
ADD CONSTRAINT fk_99e097b079 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;

View File

@ -16,7 +16,9 @@ module Gitlab
def get
Gitlab::Redis::SharedState.with do |redis|
data = redis.get(redis_shared_state_key)
Gitlab::Json.parse(data, symbolize_names: true) if data
params = Gitlab::Json.parse(data, symbolize_names: true) if data
params[:integration_id] ||= params.delete(:service_id) if params && params[:service_id]
params
end
end

View File

@ -89,10 +89,7 @@ RSpec.describe FormHelper do
it 'renders an appropriately styled alert div' do
model = double(errors: errors_stub('Error 1'))
expect(helper.form_errors(model, pajamas_alert: false))
.to include('<div class="alert alert-danger" id="error_explanation">')
expect(helper.form_errors(model, pajamas_alert: true))
expect(helper.form_errors(model))
.to include(
'<div class="gl-alert gl-mb-5 gl-alert-danger gl-alert-not-dismissible" id="error_explanation" role="alert">'
)

View File

@ -15,8 +15,8 @@ RSpec.describe ChatName do
it { is_expected.to validate_presence_of(:team_id) }
it { is_expected.to validate_presence_of(:chat_id) }
it { is_expected.to validate_uniqueness_of(:user_id).scoped_to(:service_id) }
it { is_expected.to validate_uniqueness_of(:chat_id).scoped_to(:service_id, :team_id) }
it { is_expected.to validate_uniqueness_of(:user_id).scoped_to(:integration_id) }
it { is_expected.to validate_uniqueness_of(:chat_id).scoped_to(:integration_id, :team_id) }
it 'is removed when the project is deleted' do
expect { subject.reload.integration.project.delete }.to change { ChatName.count }.by(-1)