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? %> +
<%= t(".description") %>
+ +<%= 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? %> | +