diff --git a/app/controllers/settings/domain_blocks_controller.rb b/app/controllers/settings/domain_blocks_controller.rb new file mode 100644 index 000000000..3fb77ce7f --- /dev/null +++ b/app/controllers/settings/domain_blocks_controller.rb @@ -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 diff --git a/app/policies/federails/moderation/domain_block_policy.rb b/app/policies/federails/moderation/domain_block_policy.rb new file mode 100644 index 000000000..693374f4e --- /dev/null +++ b/app/policies/federails/moderation/domain_block_policy.rb @@ -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 diff --git a/app/views/layouts/settings.html.erb b/app/views/layouts/settings.html.erb index cd5801897..ca65558fb 100644 --- a/app/views/layouts/settings.html.erb +++ b/app/views/layouts/settings.html.erb @@ -19,6 +19,11 @@ <%= link_to t("settings.users.index.title"), settings_users_path, class: "nav-link" %> <% end %> + <% if SiteSettings.federation_enabled? %> + + <% end %> diff --git a/app/views/settings/domain_blocks/index.html.erb b/app/views/settings/domain_blocks/index.html.erb new file mode 100644 index 000000000..b213a052b --- /dev/null +++ b/app/views/settings/domain_blocks/index.html.erb @@ -0,0 +1,20 @@ +

<%= t(".title") %>

+ +

<%= t(".description") %>

+ + + + + + + + <% @blocks.each do |block| %> + + + + + + <% end %> +
<%= Federails::Moderation::DomainBlock.human_attribute_name(:domain) %><%= Federails::Moderation::DomainBlock.human_attribute_name(:created_at) %>
<%= block.domain %><%= block.created_at %><%= 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? %>
+ +<%= link_to t(".new"), new_settings_domain_block_path, class: "btn btn-primary" if policy(Federails::Moderation::DomainBlock).new? %> diff --git a/app/views/settings/domain_blocks/new.html.erb b/app/views/settings/domain_blocks/new.html.erb new file mode 100644 index 000000000..9b4725687 --- /dev/null +++ b/app/views/settings/domain_blocks/new.html.erb @@ -0,0 +1,9 @@ +

<%= t(".title") %>

+ +<%= form_with model: [:settings, @domain_block] do |form| %> + + <%= text_input_row form, :domain %> + + <%= form.submit translate(".submit"), class: "btn btn-primary" %> + +<% end %> diff --git a/config/locales/settings/en.yml b/config/locales/settings/en.yml index 54ad7014e..e3f519215 100644 --- a/config/locales/settings/en.yml +++ b/config/locales/settings/en.yml @@ -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: diff --git a/config/routes.rb b/config/routes.rb index 87a2d090d..a76a4c747 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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