Commit 0f030f83 authored by Yorick Peterse's avatar Yorick Peterse

Fix cross database transaction when blocking users

When blocking a user, CI related queries are executed after the user's
state transitions to the "blocked" state. This commit ensures those
queries don't run in the same transaction as is used to update the user.

This fixes https://gitlab.com/gitlab-org/gitlab/-/issues/346235

Changelog: fixed
parent d6e94fa6
...@@ -391,9 +391,11 @@ class User < ApplicationRecord ...@@ -391,9 +391,11 @@ class User < ApplicationRecord
# this state transition object in order to do a rollback. # this state transition object in order to do a rollback.
# For this reason the tradeoff is to disable this cop. # For this reason the tradeoff is to disable this cop.
after_transition any => :blocked do |user| after_transition any => :blocked do |user|
user.run_after_commit do
Ci::DropPipelineService.new.execute_async_for_all(user.pipelines, :user_blocked, user) Ci::DropPipelineService.new.execute_async_for_all(user.pipelines, :user_blocked, user)
Ci::DisableUserPipelineSchedulesService.new.execute(user) Ci::DisableUserPipelineSchedulesService.new.execute(user)
end end
end
after_transition any => :deactivated do |user| after_transition any => :deactivated do |user|
next unless Gitlab::CurrentSettings.user_deactivation_emails_enabled next unless Gitlab::CurrentSettings.user_deactivation_emails_enabled
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment