2020-10-15 12:09:06 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class DisallowTwoFactorForSubgroupsWorker
|
|
|
|
include ApplicationWorker
|
2021-04-30 18:10:09 +00:00
|
|
|
|
2021-07-21 12:09:35 +00:00
|
|
|
data_consistency :always
|
|
|
|
|
2021-04-30 18:10:09 +00:00
|
|
|
sidekiq_options retry: 3
|
2020-10-15 12:09:06 +00:00
|
|
|
include ExceptionBacktrace
|
|
|
|
|
|
|
|
INTERVAL = 2.seconds.to_i
|
|
|
|
|
|
|
|
feature_category :subgroups
|
|
|
|
idempotent!
|
|
|
|
|
|
|
|
def perform(group_id)
|
|
|
|
begin
|
|
|
|
group = Group.find(group_id)
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
|
|
|
subgroups = group.descendants.where(require_two_factor_authentication: true) # rubocop: disable CodeReuse/ActiveRecord
|
|
|
|
subgroups.find_each(batch_size: 100).with_index do |subgroup, index|
|
|
|
|
delay = index * INTERVAL
|
|
|
|
|
|
|
|
with_context(namespace: subgroup) do
|
|
|
|
DisallowTwoFactorForGroupWorker.perform_in(delay, subgroup.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
|
|
|
end
|
|
|
|
end
|