fix: scope migration trigger to admin toggle and broaden inbox filter
This commit is contained in:
committed by
Tanmay Deep Sharma
parent
2f6da8545f
commit
5bf5c88075
@@ -5,7 +5,7 @@ class Migration::AccountAssignmentPolicyJob < ApplicationJob
|
||||
|
||||
def perform(account)
|
||||
inboxes_with_limit = account.inboxes
|
||||
.where("auto_assignment_config->>'max_assignment_limit' ~ '^[1-9]'")
|
||||
.where("auto_assignment_config->>'max_assignment_limit' ~ '[1-9]'")
|
||||
|
||||
return if inboxes_with_limit.empty?
|
||||
|
||||
|
||||
@@ -5,8 +5,10 @@ module Enterprise::Account
|
||||
|
||||
# Auto-sync advanced_assignment with assignment_v2 when features are bulk-updated via admin UI
|
||||
def selected_feature_flags=(features)
|
||||
was_assignment_v2 = feature_enabled?('assignment_v2')
|
||||
super
|
||||
sync_assignment_features
|
||||
@assignment_v2_just_enabled = !was_assignment_v2 && feature_enabled?('assignment_v2')
|
||||
end
|
||||
|
||||
def mark_for_deletion(reason = 'manual_deletion')
|
||||
|
||||
@@ -26,7 +26,7 @@ module Enterprise::Concerns::Account
|
||||
private
|
||||
|
||||
def assignment_v2_just_enabled?
|
||||
saved_change_to_feature_flags? && feature_enabled?('assignment_v2')
|
||||
!!@assignment_v2_just_enabled
|
||||
end
|
||||
|
||||
def migrate_assignment_policies
|
||||
|
||||
@@ -225,31 +225,33 @@ RSpec.describe Account, type: :model do
|
||||
describe 'after_commit :migrate_assignment_policies' do
|
||||
let(:account) { create(:account) }
|
||||
|
||||
context 'when assignment_v2 is enabled' do
|
||||
context 'when assignment_v2 is toggled on via admin UI' do
|
||||
it 'enqueues Migration::AccountAssignmentPolicyJob after commit' do
|
||||
enabled_flags = account.enabled_features.keys.map { |f| "feature_#{f}".to_sym } + [:feature_assignment_v2]
|
||||
|
||||
expect do
|
||||
account.enable_features!('assignment_v2')
|
||||
account.update!(selected_feature_flags: enabled_flags)
|
||||
end.to have_enqueued_job(Migration::AccountAssignmentPolicyJob).with(account)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when assignment_v2 is disabled' do
|
||||
it 'does not enqueue the job' do
|
||||
account.enable_features!('assignment_v2')
|
||||
|
||||
expect do
|
||||
account.disable_features!('assignment_v2')
|
||||
end.not_to have_enqueued_job(Migration::AccountAssignmentPolicyJob)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when feature_flags column does not change' do
|
||||
context 'when assignment_v2 is already enabled and another flag changes' do
|
||||
it 'does not enqueue the job' do
|
||||
account.enable_features!('assignment_v2')
|
||||
clear_enqueued_jobs
|
||||
|
||||
enabled_flags = account.enabled_features.keys.map { |f| "feature_#{f}".to_sym }
|
||||
|
||||
expect do
|
||||
account.update!(name: 'Updated Name')
|
||||
account.update!(selected_feature_flags: enabled_flags)
|
||||
end.not_to have_enqueued_job(Migration::AccountAssignmentPolicyJob)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when assignment_v2 is enabled via enable_features!' do
|
||||
it 'does not enqueue the job' do
|
||||
expect do
|
||||
account.enable_features!('assignment_v2')
|
||||
end.not_to have_enqueued_job(Migration::AccountAssignmentPolicyJob)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user