Skip to content

Commit

Permalink
Perform block in task and include admin email
Browse files Browse the repository at this point in the history
  • Loading branch information
entantoencuanto committed Dec 3, 2024
1 parent 2660f23 commit c116065
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions lib/tasks/decidim_awesome_autoblock_users_tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,29 @@
namespace :decidim_decidim_awesome do
namespace :autoblock_users do
desc "Performs autoblock users task"
task run: :environment do
Decidim::Organization.all.each do |organization|
if (current_config = organization_config(organization)).blank?
puts "\nSkipping #{organization.name}...\n"
task :run_block, [:admin_email] => :environment do |_task, args|
current_user = Decidim::User.where(admin: true).find_by(email: args.admin_email)

raise "A valid admin email is required to run this task" if current_user.blank?

Decidim::Organization.all.each do |current_organization|
if (current_config = organization_config(current_organization)).blank?
puts "\nSkipping #{current_organization.name}...\n"
next
end

puts "\nRunning on #{organization.name}...\n"
puts "\nRunning on #{current_organization.name}...\n"

config_data = OpenStruct.new(current_config.value || {})
config_form = Decidim::DecidimAwesome::Admin::UsersAutoblocksConfigForm.from_model(config_data).with_context(current_organization: organization)
config_form = Decidim::DecidimAwesome::Admin::UsersAutoblocksConfigForm.from_model(config_data).with_context(current_organization:, current_user:)
config_form.perform_block = true

Decidim::DecidimAwesome::Admin::AutoblockUsers.call(config_form) do
on(:ok) do |count, block_performed|
if block_performed
puts "\n✓ Process finished. Total users detected: #{count}. Block not performed.\n"
else
puts "\n✓ Process finished. Total users detected and blocked: #{count}.\n"
else
puts "\n✓ Process finished. Total users detected: #{count}. Block not performed.\n"
end
end

Expand Down

0 comments on commit c116065

Please sign in to comment.