-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3221 from manyfold3d/handle-reports
Add support for blocking domains so that they don't federate
- Loading branch information
Showing
12 changed files
with
176 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
db/migrate/20241128162213_create_federails_moderation_reports.federails_moderation.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
9 changes: 9 additions & 0 deletions
9
db/migrate/20241128162214_create_federails_moderation_domain_blocks.federails_moderation.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.