Skip to content

Commit

Permalink
add domain block UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Floppy committed Nov 28, 2024
1 parent 10bfae6 commit 58345f4
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 0 deletions.
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

0 comments on commit 58345f4

Please sign in to comment.