Specify updated_by_id in LDAP deactivation sequencer unit (fixes #2111)
This commit is contained in:
parent
903777588a
commit
c61dd3eab4
2 changed files with 34 additions and 10 deletions
|
@ -10,16 +10,11 @@ class Sequencer
|
||||||
def process
|
def process
|
||||||
return if dry_run
|
return if dry_run
|
||||||
|
|
||||||
# we need to update in slices since some DBs
|
# Why not use `#update_all`?
|
||||||
# have a limit for IN length
|
# It bypasses validations/callbacks
|
||||||
lost_ids.each_slice(5000) do |slice|
|
# (which are used to send notifications to the client)
|
||||||
|
::User.where(id: lost_ids).find_each do |user|
|
||||||
# we need to instanciate every entry and set
|
user.update!(active: false, updated_by_id: 1)
|
||||||
# the active state this way to send notifications
|
|
||||||
# to the client
|
|
||||||
::User.where(id: slice).each do |user|
|
|
||||||
user.update!(active: false)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Sequencer::Unit::Import::Ldap::Users::Lost::Deactivate, sequencer: :unit do
|
||||||
|
let!(:lost_users) { create_list(:user, sample_length, attributes) }
|
||||||
|
let(:sample_length) { 2 }
|
||||||
|
|
||||||
|
context 'when provided ids of active users' do
|
||||||
|
let(:attributes) { { active: true } }
|
||||||
|
|
||||||
|
it 'deactivates them' do
|
||||||
|
expect { process(lost_ids: lost_users.pluck(:id), dry_run: false) }
|
||||||
|
.to change { lost_users.each(&:reload).pluck(:active) }.to(Array.new(sample_length, false))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when provided ids of users with any `updated_by_id`' do
|
||||||
|
# ordinarily, a History log's created_by_id is based on this value (or UserInfo.current_user_id),
|
||||||
|
# but this Sequencer unit is expected to override it
|
||||||
|
let(:attributes) { { updated_by_id: 2 } }
|
||||||
|
|
||||||
|
it 'enforces created_by_id => 1 in newly created History logs' do
|
||||||
|
expect { process(lost_ids: lost_users.pluck(:id), dry_run: false) }
|
||||||
|
.to change { History.count }.by(sample_length)
|
||||||
|
|
||||||
|
expect(History.last(sample_length).pluck(:created_by_id))
|
||||||
|
.to eq(Array.new(sample_length, 1))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue