Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def is_channel_dashboard?
return false if mastodon_url.nil?

case mastodon_url
when /channel/
when %r{^(https://)?channel\.org(?=/|$)}
true
when /staging\.patchwork\.online/
true
Expand Down
21 changes: 21 additions & 0 deletions app/models/domain_block.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: domain_blocks
#
# id :bigint(8) not null, primary key
# domain :string default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
# severity :integer default("silence")
# reject_media :boolean default(FALSE), not null
# reject_reports :boolean default(FALSE), not null
# private_comment :text
# public_comment :text
# obfuscate :boolean default(FALSE), not null
#

class DomainBlock < ApplicationRecord
enum :severity, { silence: 0, suspend: 1, noop: 2 }, validate: true
end
1 change: 1 addition & 0 deletions app/models/relay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
# follow_activity_id :string
#
class Relay < ApplicationRecord
enum :state, { idle: 0, pending: 1, accepted: 2, rejected: 3 }
end
5 changes: 2 additions & 3 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

Dir[Rails.root.join('db', 'seeds', '*.rb')].each do |seed|
load seed
load 'db/seeds/community_user_role.rb'
end

# Run the insert_server_setting_data rake task
Rake::Task['db:insert_server_setting_data'].invoke
# Run the domain_block import rake task
Rake::Task['domain_block:import'].invoke
File renamed without changes.
42 changes: 42 additions & 0 deletions lib/tasks/domain_block.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# lib/tasks/domain_block.rake
require 'csv'

namespace :domain_block do
desc "Import domain_block.csv into domain_blocks table in chunks of 500"
task import: :environment do
file_path = Rails.root.join("public", "csv", "domain_blocks.csv")

unless File.exist?(file_path)
puts "CSV file not found: #{file_path}"
exit
end

puts "Starting bulk import (500 per batch) from #{file_path}..."

existing_domains = DomainBlock.pluck(:domain).to_set
new_records = []

# Collect all new records first
CSV.foreach(file_path, headers: true) do |row|
domain = row["#domain"]&.strip
next if domain.blank? || existing_domains.include?(domain)

new_records << {
domain: domain,
severity: row.fetch('#severity', :suspend),
reject_media: row.fetch('#reject_media', false),
reject_reports: row.fetch('#reject_reports', false),
public_comment: row["#public_comment"]&.strip,
obfuscate: row.fetch('#obfuscate', false)
}
end

# Insert in batches of 500
new_records.each_slice(500) do |batch|
DomainBlock.insert_all(batch)
puts "Inserted #{batch.size} records..."
end

puts "Bulk import completed. Total new: #{new_records.size}"
end
end
1,158 changes: 1,158 additions & 0 deletions public/csv/domain_blocks.csv

Large diffs are not rendered by default.