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
20 changes: 19 additions & 1 deletion app/controllers/api/v1/communities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class CommunitiesController < ApiController

skip_before_action :verify_key!
before_action :check_authorization_header
before_action :set_community, only: %i[show update set_visibility manage_additional_information]
before_action :set_community, only: %i[show update set_visibility manage_additional_information remove_avatar remove_banner]
before_action :validate_patchwork_community_id, only: %i[contributor_list mute_contributor_list hashtag_list]
before_action :set_content_and_channel_type, only: %i[index create update]

Expand Down Expand Up @@ -143,6 +143,24 @@ def fetch_ip_address
end
end

def remove_avatar
if @community.avatar_image.present?
@community.update(avatar_image: nil)
render_success({}, 'api.messages.success', :ok)
else
render_errors('api.community.errors.no_image_to_remove', :unprocessable_entity)
end
end

def remove_banner
if @community.banner_image.present?
@community.update(banner_image: nil)
render_success({}, 'api.messages.success', :ok)
else
render_errors('api.community.errors.no_image_to_remove', :unprocessable_entity)
end
end

private

def community_params
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ def render_custom_emojis(text)

def is_channel_dashboard?
if Rails.env.development?
return false
return true
end

mastodon_url = ENV['MASTODON_INSTANCE_URL']
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
4 changes: 1 addition & 3 deletions config/locales/cy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Welsh translations for Patchwork Dashboard
# Cyfieithiadau Cymraeg ar gyfer Patchwork Dashboard

cy:
# Locale information
locale:
Expand Down Expand Up @@ -38,6 +35,7 @@ cy:
missing_additional_information: "Mae gwybodaeth ychwanegol ar goll."
duplicate_link_url: "Nid yw URL cyswllt dyblyg ar gyfer y gymuned hon yn cael ei ganiatáu."
search_params_required: "Mae angen paramedrau ymholiad, URL a thocyn."
no_image_to_remove: "Dim delwedd i'w thynnu."

messages:
created: "Crëwyd y gymuned yn llwyddiannus."
Expand Down
4 changes: 1 addition & 3 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# German translations for Patchwork Dashboard
# Deutsche Übersetzungen für das Patchwork Dashboard

de:
# Locale information
locale:
Expand Down Expand Up @@ -38,6 +35,7 @@ de:
missing_additional_information: "Zusätzliche Informationen fehlen."
duplicate_link_url: "Doppelte Link-URL für diese Community ist nicht erlaubt."
search_params_required: "Abfrage-, URL- und Token-Parameter sind erforderlich."
no_image_to_remove: "Kein Bild zum Entfernen."

messages:
created: "Community erfolgreich erstellt."
Expand Down
4 changes: 1 addition & 3 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# English translations for Patchwork Dashboard
# This file contains all English translations for the application

en:
# Locale information
locale:
Expand Down Expand Up @@ -38,6 +35,7 @@ en:
missing_additional_information: "Missing additional information."
duplicate_link_url: "Duplicate link URL for this community is not allowed."
search_params_required: "Query, URL, and token parameters are required."
no_image_to_remove: "No image to remove."

messages:
created: "Community created successfully."
Expand Down
4 changes: 1 addition & 3 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Spanish translations for Patchwork Dashboard
# This file contains all Spanish translations for the application

es:
# Locale information
locale:
Expand Down Expand Up @@ -38,6 +35,7 @@ es:
missing_additional_information: "Falta información adicional."
duplicate_link_url: "No se permite una URL de enlace duplicada para esta comunidad."
search_params_required: "Se requieren los parámetros de consulta, URL y token."
no_image_to_remove: "No hay imagen para eliminar."

messages:
created: "Comunidad creada con éxito."
Expand Down
6 changes: 2 additions & 4 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# French translations for Patchwork Dashboard
# Traductions françaises pour le tableau de bord Patchwork

fr:
# Locale information
locale:
Expand Down Expand Up @@ -38,7 +35,8 @@ fr:
missing_additional_information: "Informations supplémentaires manquantes."
duplicate_link_url: "L'URL de lien en double pour cette communauté n'est pas autorisée."
search_params_required: "Les paramètres de requête, d'URL et de jeton sont requis."

no_image_to_remove: "Aucune image à supprimer."

messages:
created: "Communauté créée avec succès."
updated: "Communauté mise à jour avec succès."
Expand Down
4 changes: 1 addition & 3 deletions config/locales/it.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Italian translations for Patchwork Dashboard
# Traduzioni italiane per il Patchwork Dashboard

it:
# Locale information
locale:
Expand Down Expand Up @@ -38,6 +35,7 @@ it:
missing_additional_information: "Informazioni aggiuntive mancanti."
duplicate_link_url: "URL di collegamento duplicato per questa comunità non è consentito."
search_params_required: "Sono richiesti i parametri di query, URL e token."
no_image_to_remove: "Nessuna immagine da rimuovere."

messages:
created: "Comunità creata con successo."
Expand Down
4 changes: 1 addition & 3 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Japanese translations for Patchwork Dashboard
# パッチワークダッシュボードの日本語翻訳

ja:
# Locale information
locale:
Expand Down Expand Up @@ -38,6 +35,7 @@ ja:
missing_additional_information: "追加情報が不足しています。"
duplicate_link_url: "このコミュニティでは重複したリンクURLは許可されていません。"
search_params_required: "クエリ、URL、およびトークンのパラメータが必要です。"
no_image_to_remove: "削除する画像がありません。"

messages:
created: "コミュニティが正常に作成されました。"
Expand Down
4 changes: 1 addition & 3 deletions config/locales/pt.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Portuguese translations for Patchwork Dashboard
# Traduções em português para o Patchwork Dashboard

pt:
# Locale information
locale:
Expand Down Expand Up @@ -38,6 +35,7 @@ pt:
missing_additional_information: "Informações adicionais em falta."
duplicate_link_url: "URL de ligação duplicado para esta comunidade não é permitido."
search_params_required: "Parâmetros de consulta, URL e token são necessários."
no_image_to_remove: "Nenhuma imagem para remover."

messages:
created: "Comunidade criada com sucesso."
Expand Down
4 changes: 1 addition & 3 deletions config/locales/pt_BR.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Brazilian Portuguese translations for Patchwork Dashboard
# Traduções em português brasileiro para o Patchwork Dashboard

pt_BR:
# Locale information
locale:
Expand Down Expand Up @@ -38,6 +35,7 @@ pt_BR:
missing_additional_information: "Informações adicionais em falta."
duplicate_link_url: "URL de link duplicado para esta comunidade não é permitido."
search_params_required: "Parâmetros de consulta, URL e token são necessários."
no_image_to_remove: "Nenhuma imagem para remover."

messages:
created: "Comunidade criada com sucesso."
Expand Down
4 changes: 1 addition & 3 deletions config/locales/ru.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Russian translations for Patchwork Dashboard
# Русские переводы для панели управления Patchwork

ru:
# Locale information
locale:
Expand Down Expand Up @@ -38,6 +35,7 @@ ru:
missing_additional_information: "Отсутствует дополнительная информация."
duplicate_link_url: "Дубликат URL ссылки для этого сообщества не разрешён."
search_params_required: "Необходимы параметры запроса, URL и токен."
no_image_to_remove: "Нет изображения для удаления."

messages:
created: "Сообщество успешно создано."
Expand Down
2 changes: 2 additions & 0 deletions config/routes/api_v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
member do
patch :manage_additional_information
put :manage_additional_information
delete :remove_avatar
delete :remove_banner
end
resources :community_filter_keywords, only: %i[index create update destroy]
resources :community_hashtags, only: %i[index create update destroy]
Expand Down
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
Loading