Skip to content
代码片段 群组 项目
未验证 提交 089a2af1 编辑于 作者: Tiger Watson's avatar Tiger Watson 提交者: GitLab
浏览文件

Merge branch '522011-backfill-finish-onboarding-saml' into 'master'

Remove existing users from onboarding if they have group saml

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/183559



Merged-by: default avatarTiger Watson <twatson@gitlab.com>
Approved-by: default avatarSurabhi Suman <ssuman@gitlab.com>
Approved-by: default avatarImre Farkas <ifarkas@gitlab.com>
Approved-by: default avatarTetiana Chupryna <tchupryna@gitlab.com>
Approved-by: default avatarTiger Watson <twatson@gitlab.com>
Reviewed-by: default avatarDoug Stull <dstull@gitlab.com>
Reviewed-by: default avatarSurabhi Suman <ssuman@gitlab.com>
Co-authored-by: default avatarDoug Stull <dstull@gitlab.com>
No related branches found
No related tags found
2 合并请求!3031Merge per-main-jh to main-jh by luzhiyuan,!3030Merge per-main-jh to main-jh
---
migration_job_name: BackfillFinishOnboardingForGroupSaml
description: Finishes the onboarding for a user if they are now attached to group saml
feature_category: onboarding
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/183559
milestone: '17.10'
queued_migration_version: 20250305135537
finalized_by: # version of the migration that finalized this BBM
# frozen_string_literal: true
class QueueBackfillFinishOnboardingForGroupSaml < Gitlab::Database::Migration[2.2]
milestone '17.10'
restrict_gitlab_migration gitlab_schema: :gitlab_main
MIGRATION = "BackfillFinishOnboardingForGroupSaml"
DELAY_INTERVAL = 2.minutes
BATCH_SIZE = 3_000
SUB_BATCH_SIZE = 250
MAX_BATCH_SIZE = 10_000
def up
queue_batched_background_migration(
MIGRATION,
:identities,
:id,
job_interval: DELAY_INTERVAL,
batch_size: BATCH_SIZE,
sub_batch_size: SUB_BATCH_SIZE,
max_batch_size: MAX_BATCH_SIZE
)
end
def down
delete_batched_background_migration(MIGRATION, :identities, :id, [])
end
end
ad139258454e70107e8019c35171046e9b788ae272d34c1c68d182d5e1a43006
\ No newline at end of file
# frozen_string_literal: true
module Gitlab
module BackgroundMigration
class BackfillFinishOnboardingForGroupSaml < BatchedMigrationJob
operation_name :backfill_finish_onboarding_for_group_saml # This is used as the key on collecting metrics
scope_to ->(relation) { relation.where(provider: 'group_saml') }
feature_category :onboarding
class User < ApplicationRecord
self.table_name = :users
end
def perform
each_sub_batch do |sub_batch|
# First get the user IDs from the identities query
user_ids = sub_batch
.joins("INNER JOIN users ON users.id = identities.user_id")
.where(provider: 'group_saml', users: { onboarding_in_progress: true })
.pluck(:user_id)
# Then update those users
User.where(id: user_ids).update_all(onboarding_in_progress: false)
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::BackgroundMigration::BackfillFinishOnboardingForGroupSaml, feature_category: :onboarding do
let(:users) { table(:users) }
let(:identities) { table(:identities) }
let(:first_user_with_saml) do
users.create!(email: 'user1@example.com', projects_limit: 0, onboarding_in_progress: true)
end
let!(:first_user_identity) { identities.create!(user_id: first_user_with_saml.id, provider: 'group_saml') }
let!(:user_with_saml_not_in_onboarding) do
record = users.create!(email: 'user2@example.com', projects_limit: 0, onboarding_in_progress: false)
identities.create!(user_id: record.id, provider: 'group_saml')
record
end
let!(:user_with_identity_not_group_saml) do
record = users.create!(email: 'user3@example.com', projects_limit: 0, onboarding_in_progress: true)
identities.create!(user_id: record.id, provider: 'foo')
record
end
let!(:last_user_no_identity) do
users.create!(email: 'user4@example.com', projects_limit: 0, onboarding_in_progress: true)
end
let(:last_user_with_identity) do
users.create!(email: 'user5@example.com', projects_limit: 0, onboarding_in_progress: true)
end
let!(:last_user_not_saml_identity) { identities.create!(user_id: last_user_with_identity.id, provider: 'foo') }
let!(:last_user_identity) { identities.create!(user_id: last_user_with_identity.id, provider: 'group_saml') }
subject(:migration) do
described_class.new(
start_id: first_user_identity.id,
end_id: last_user_identity.id,
batch_table: :identities,
batch_column: :id,
sub_batch_size: 100,
pause_ms: 0,
connection: ApplicationRecord.connection
)
end
describe '#perform' do
it 'updates the correct data' do
migration.perform
expect(first_user_with_saml.reload.onboarding_in_progress).to be(false)
expect(user_with_saml_not_in_onboarding.reload.onboarding_in_progress).to be(false)
expect(user_with_identity_not_group_saml.reload.onboarding_in_progress).to be(true)
expect(last_user_no_identity.reload.onboarding_in_progress).to be(true)
expect(last_user_with_identity.reload.onboarding_in_progress).to be(false)
end
end
end
# frozen_string_literal: true
require 'spec_helper'
require_migration!
RSpec.describe QueueBackfillFinishOnboardingForGroupSaml, migration: :gitlab_main_cell, feature_category: :onboarding do
let!(:batched_migration) { described_class::MIGRATION }
it 'schedules a new batched migration' do
reversible_migration do |migration|
migration.before -> {
expect(batched_migration).not_to have_scheduled_batched_migration
}
attributes = {
table_name: :identities,
column_name: :id,
interval: described_class::DELAY_INTERVAL,
batch_size: described_class::BATCH_SIZE,
sub_batch_size: described_class::SUB_BATCH_SIZE,
max_batch_size: described_class::MAX_BATCH_SIZE
}
migration.after -> {
expect(batched_migration).to have_scheduled_batched_migration(attributes)
}
end
end
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册