Skip to content

Commit

Permalink
Add task to autoblock users based on each organization configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
entantoencuanto committed Dec 3, 2024
1 parent b5b63e7 commit 11e351a
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions lib/tasks/decidim_awesome_autoblock_users_tasks.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

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"
next
end

puts "\nRunning on #{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)

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"
end
end

on(:invalid) do |messages|
puts "\n✗ Something has failed. Messages:\n"
messages.each do |message|
puts "* #{message}\n"
end
end
end
end
end

def organization_config(organization)
Decidim::DecidimAwesome::AwesomeConfig.find_by(var: :users_autoblocks_config, organization:)
end
end
end

0 comments on commit 11e351a

Please sign in to comment.