Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for blocking domains so that they don't federate #3221

Merged
merged 3 commits into from
Nov 28, 2024
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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ gem "devise_zxcvbn", "~> 6.0"

gem "ransack", "~> 4.2"
gem "federails", "~> 0.3"
gem "federails-moderation", github: "manyfold3d/federails-moderation"
gem "caber"

gem "nanoid", "~> 2.0"
Expand Down
10 changes: 10 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
GIT
remote: https://github.com/manyfold3d/federails-moderation.git
revision: ab92e0f05c87dbd477cf16765ed49d8ae4356583
specs:
federails-moderation (0.0.1)
federails (~> 0.3)
public_suffix (~> 6.0)
rails (>= 7.2.2)

GIT
remote: https://github.com/manyfold3d/sqlite3_ar_regexp.git
revision: 2fa15db50770e86b7b4872486c2ee8ff282a3e2c
Expand Down Expand Up @@ -765,6 +774,7 @@ DEPENDENCIES
factory_bot
faker (~> 3.5)
federails (~> 0.3)
federails-moderation!
ffi-libarchive (~> 1.1)
get_process_mem (~> 1.0)
guard (~> 2.19)
Expand Down
37 changes: 37 additions & 0 deletions app/controllers/settings/domain_blocks_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class Settings::DomainBlocksController < ApplicationController
respond_to :html

def index
@blocks = policy_scope(Federails::Moderation::DomainBlock).all
render layout: "settings"
end

def new
authorize Federails::Moderation::DomainBlock
@domain_block = Federails::Moderation::DomainBlock.new
render layout: "settings"
end

def create
authorize Federails::Moderation::DomainBlock
@domain_block = Federails::Moderation::DomainBlock.create(domain_block_params)
if @domain_block.valid?
redirect_to settings_domain_blocks_path, notice: t(".success")
else
render "new", layout: "settings", status: :unprocessable_entity
end
end

def destroy
@domain_block = Federails::Moderation::DomainBlock.find(params[:id])
authorize @domain_block
@domain_block.destroy
redirect_to settings_domain_blocks_path, notice: t(".success")
end

private

def domain_block_params
params.require(:domain_block).permit(:domain)
end
end
27 changes: 27 additions & 0 deletions app/policies/federails/moderation/domain_block_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Federails::Moderation::DomainBlockPolicy < ApplicationPolicy
def index?
all_of(
SiteSettings.federation_enabled?,
@user.is_moderator?
)
end

def show?
index?
end

def edit?
index?
end

def update?
index?
end

def destroy?
index?
end

class Scope < ApplicationPolicy::Scope
end
end
5 changes: 5 additions & 0 deletions app/views/layouts/settings.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
<%= link_to t("settings.users.index.title"), settings_users_path, class: "nav-link" %>
</li>
<% end %>
<% if SiteSettings.federation_enabled? %>
<li class="nav-item">
<%= link_to t("settings.domain_blocks.index.title"), settings_domain_blocks_path, class: "nav-link" %>
</li>
<% end %>
<li class="nav-item">
<%= link_to t("settings.reporting.heading"), reporting_settings_path, class: "nav-link" %>
</li>
Expand Down
20 changes: 20 additions & 0 deletions app/views/settings/domain_blocks/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<h3><%= t(".title") %></h3>

<p class="lead"><%= t(".description") %></p>

<table class="table table-striped">
<tr>
<th><%= Federails::Moderation::DomainBlock.human_attribute_name(:domain) %></th>
<th><%= Federails::Moderation::DomainBlock.human_attribute_name(:created_at) %></th>
<th></th>
</tr>
<% @blocks.each do |block| %>
<tr>
<td><%= block.domain %></td>
<td><%= block.created_at %></td>
<td><%= link_to safe_join([icon("trash", t("general.delete")), t("general.delete")], " "), settings_domain_block_path(block), {method: :delete, class: "float-end btn btn-outline-danger", data: {confirm: translate(".confirm_destroy")}} if policy(block).destroy? %></td>
</tr>
<% end %>
</table>

<%= link_to t(".new"), new_settings_domain_block_path, class: "btn btn-primary" if policy(Federails::Moderation::DomainBlock).new? %>
9 changes: 9 additions & 0 deletions app/views/settings/domain_blocks/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h3><%= t(".title") %></h3>

<%= form_with model: [:settings, @domain_block] do |form| %>

<%= text_input_row form, :domain %>

<%= form.submit translate(".submit"), class: "btn btn-primary" %>

<% end %>
13 changes: 13 additions & 0 deletions config/locales/settings/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ en:
manifold:
help: Check for non-manifold meshes (i.e. they have holes or impossible surfaces)
label: Detect mesh errors
domain_blocks:
create:
success: Domain block created successfully.
destroy:
success: Domain block removed.
index:
confirm_destroy: Are you sure you want to remove this domain block and re-enable federation?
description: Domain blocks prevent federation with ActivityPub servers on the specified domains, including any subdomains.
new: New domain block
title: Domain Blocks
new:
submit: Block domain
title: New Domain Block
folder_settings:
details: Folder structure follows a template that you define using tokens. You can also include other text in the template (such as folder separators) and it will be included as-is.
model_path_template:
Expand Down
8 changes: 8 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
post "/follow_remote_actor/:id" => "follows#follow_remote_actor", :as => :follow_remote_actor
end

if SiteSettings.federation_enabled? || Rails.env.test?
authenticate :user, lambda { |u| u.is_moderator? } do
namespace :settings do
resources :domain_blocks if SiteSettings.federation_enabled?
end
end
end

root to: "home#index"

resources :libraries, except: [:index] do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This migration comes from federails_moderation (originally 20241127105043)
class CreateFederailsModerationReports < ActiveRecord::Migration[7.0]
def change
create_table :federails_moderation_reports do |t|
t.string :federated_url
t.references :federails_actor, foreign_key: true
t.string :content
t.references :object, polymorphic: true
t.datetime :resolved_at
t.string :resolution
t.timestamps
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This migration comes from federails_moderation (originally 20241128115659)
class CreateFederailsModerationDomainBlocks < ActiveRecord::Migration[7.0]
def change
create_table :federails_moderation_domain_blocks do |t|
t.string "domain", null: false, index: {unique: true}
t.timestamps
end
end
end
24 changes: 23 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading