From f54ab8be03360e9c429237993454a8870527a637 Mon Sep 17 00:00:00 2001 From: James Smith Date: Fri, 29 Nov 2024 19:13:47 +0000 Subject: [PATCH 1/7] Add reportable concern and submission form --- app/controllers/reports_controller.rb | 29 +++++++++++++++++++++++++++ app/views/reports/new.html.erb | 11 ++++++++++ config/locales/en.yml | 7 +++++++ config/routes.rb | 6 ++++++ 4 files changed, 53 insertions(+) create mode 100644 app/controllers/reports_controller.rb create mode 100644 app/views/reports/new.html.erb diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb new file mode 100644 index 000000000..34eb784c8 --- /dev/null +++ b/app/controllers/reports_controller.rb @@ -0,0 +1,29 @@ +class ReportsController < ApplicationController + before_action :get_reportable + + def new + @report = Federails::Moderation::Report.new + end + + def create + @report = Federails::Moderation::Report.create report_params.merge({ + federails_actor: current_user.actor, + object: @reportable.actor + }) + redirect_to(@reportable, notice: t(".success")) + end + + private + + def report_params + params.require(:report).permit(:content) + end + + def get_reportable + reportable = params[:reportable_class].constantize + reportable_param = params[:reportable_class].parameterize + "_id" + id = params[reportable_param] + @reportable = policy_scope(reportable).find_param(id) + authorize @reportable + end +end diff --git a/app/views/reports/new.html.erb b/app/views/reports/new.html.erb new file mode 100644 index 000000000..e7ec2e233 --- /dev/null +++ b/app/views/reports/new.html.erb @@ -0,0 +1,11 @@ +

<%= t(".title", name: @reportable.name) %>

+ +

<%= t ".description" %>

+ +<%= form_with model: [@reportable, @report] do |form| %> + + <%= text_input_row form, :content %> + + <%= form.submit translate(".submit"), class: "btn btn-primary" %> + +<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 69bf63d27..2570e93fc 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -408,6 +408,13 @@ en: webglrenderer: Could not create renderer! load: Load processing: Reticulating splines... + reports: + create: + success: Report submitted. Thank you! + new: + description: If this item violates any laws or server policies, you can report it to our moderators. Add a comment to let us know why! + submit: Send report + title: Report %{name} security: running_as_root_html: Manyfold is running as root, which is a security risk. Run as a different system user by setting the PUID and PGID environment variables. See the configuration documentation for details. sites: diff --git a/config/routes.rb b/config/routes.rb index 75314466e..d605cf8bd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -83,10 +83,14 @@ concern :commentable do |options| resources :comments, {only: [:show]}.merge(options) end + concern :reportable do |options| + resources :reports, {only: [:new, :create]}.merge(options) if SiteSettings.multiuser_enabled? + end resources :models do concerns :followable, followable_class: "Model" concerns :commentable, commentable_class: "Model" + concerns :reportable, reportable_class: "Model" member do post "merge" post "scan" @@ -105,10 +109,12 @@ resources :creators do concerns :followable, followable_class: "Creator" concerns :commentable, commentable_class: "Creator" + concerns :reportable, reportable_class: "Creator" end resources :collections do concerns :followable, followable_class: "Collection" concerns :commentable, commentable_class: "Collection" + concerns :reportable, reportable_class: "Collection" end resources :problems, only: [:index, :update] do collection do From 88d58ddb31d38bb5a513b009b2fb9361b3972792 Mon Sep 17 00:00:00 2001 From: James Smith Date: Fri, 29 Nov 2024 22:38:15 +0000 Subject: [PATCH 2/7] add report buttons to reportable objects --- app/views/creators/show.html.erb | 1 + app/views/models/_list.html.erb | 1 + app/views/models/show.html.erb | 4 ++++ app/views/reports/new.html.erb | 2 +- app/views/settings/reports/index.html.erb | 8 ++++++-- config/locales/en.yml | 3 ++- 6 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/views/creators/show.html.erb b/app/views/creators/show.html.erb index 2bfdd2c34..d73e868b2 100644 --- a/app/views/creators/show.html.erb +++ b/app/views/creators/show.html.erb @@ -24,6 +24,7 @@ <% content_for :actions do %> <%= link_to safe_join([icon("pencil", t(".edit")), t(".edit")], " "), edit_creator_path(@creator), class: "btn btn-primary" if policy(@creator).edit? %> + <%= link_to safe_join([icon("flag", t("general.report", type: Creator.model_name.human)), t("general.report", type: Creator.model_name.human)], " "), new_creator_report_path(@creator), class: "btn btn-outline-warning" if SiteSettings.multiuser_enabled? %> <% end %> <%= render "models/list" %> diff --git a/app/views/models/_list.html.erb b/app/views/models/_list.html.erb index e52881252..096e51c3b 100644 --- a/app/views/models/_list.html.erb +++ b/app/views/models/_list.html.erb @@ -25,6 +25,7 @@ <% content_for :actions do %> <%= link_to t(".bulk_edit"), edit_models_path(@filters.merge(@additional_filters)), class: "btn btn-secondary" if policy(:model).edit? %> + <%= link_to safe_join([icon("flag", t("general.report", type: Collection.model_name.human)), t("general.report", type: Collection.model_name.human)], " "), new_collection_report_path(@collection), class: "btn btn-outline-warning" if SiteSettings.multiuser_enabled? && @collection %> <% end %> <% content_for :sidebar do %> diff --git a/app/views/models/show.html.erb b/app/views/models/show.html.erb index c2390a4b2..5001c531c 100644 --- a/app/views/models/show.html.erb +++ b/app/views/models/show.html.erb @@ -112,6 +112,10 @@ + <%= card :secondary, t("layouts.card_list_page.actions_heading") do %> + <%= link_to safe_join([icon("flag", t("general.report", type: Model.model_name.human)), t("general.report", type: Model.model_name.human)], " "), new_model_report_path(@model), class: "btn btn-outline-warning" %> + <% end if SiteSettings.multiuser_enabled? %> + <% if !@model.parents.empty? && policy(@model).merge? %> <%= card :danger, t(".merge.heading") do %>

diff --git a/app/views/reports/new.html.erb b/app/views/reports/new.html.erb index e7ec2e233..b61366ec8 100644 --- a/app/views/reports/new.html.erb +++ b/app/views/reports/new.html.erb @@ -1,4 +1,4 @@ -

<%= t(".title", name: @reportable.name) %>

+

<%= t(".title", type: @reportable.model_name.human, name: @reportable.name) %>

<%= t ".description" %>

diff --git a/app/views/settings/reports/index.html.erb b/app/views/settings/reports/index.html.erb index bae46293b..fa4695619 100644 --- a/app/views/settings/reports/index.html.erb +++ b/app/views/settings/reports/index.html.erb @@ -4,14 +4,18 @@ - - + + <% @reports.each do |report| %> + + diff --git a/config/locales/en.yml b/config/locales/en.yml index 2570e93fc..4b7917324 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -313,6 +313,7 @@ en: edit: Edit expand: Expand new: New + report: Report %{type} save: Save view: View home: @@ -414,7 +415,7 @@ en: new: description: If this item violates any laws or server policies, you can report it to our moderators. Add a comment to let us know why! submit: Send report - title: Report %{name} + title: 'Report %{type}: "%{name}"' security: running_as_root_html: Manyfold is running as root, which is a security risk. Run as a different system user by setting the PUID and PGID environment variables. See the configuration documentation for details. sites: From daf928513c814ab4bc509dd16fb69ba583d21802 Mon Sep 17 00:00:00 2001 From: James Smith Date: Fri, 29 Nov 2024 22:42:21 +0000 Subject: [PATCH 3/7] fix missing preview message translation --- app/components/model_component.html.erb | 4 ++-- app/views/collections/_collection.html.erb | 4 ++-- config/locales/collections/en.yml | 2 +- config/locales/en.yml | 1 + 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/components/model_component.html.erb b/app/components/model_component.html.erb index eef810a53..83871610c 100644 --- a/app/components/model_component.html.erb +++ b/app/components/model_component.html.erb @@ -9,8 +9,8 @@ <%= render partial: "object_preview", locals: {model: @model, file: file} %> <% end %> - <% else %> -

no preview availiable

+ <% else %> +

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

<% end %>
diff --git a/app/views/collections/_collection.html.erb b/app/views/collections/_collection.html.erb index 6143ea7c7..aed9b9859 100644 --- a/app/views/collections/_collection.html.erb +++ b/app/views/collections/_collection.html.erb @@ -11,8 +11,8 @@ <%= render partial: "object_preview", locals: {model: model, file: file} %>
<% end %> - <% else %> -

<%= t ".no_preview" %>

+ <% else %> +

<%= t ".no_preview" %>

<% end %>
<%= collection.name.careful_titleize %>
diff --git a/config/locales/collections/en.yml b/config/locales/collections/en.yml index c841997cb..814a1a670 100644 --- a/config/locales/collections/en.yml +++ b/config/locales/collections/en.yml @@ -9,7 +9,7 @@ en: text: Edit models_button: label: Show models in %{name} - no_preview: no preview availiable + no_preview: No preview availiable create: success: New collection details saved. destroy: diff --git a/config/locales/en.yml b/config/locales/en.yml index 4b7917324..9c5973cd8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -399,6 +399,7 @@ en: edit_button: label: Edit model %{name} text: Edit + no_preview: No preview available open_button: label: Open model %{name} text: Open From 0da4438613424411185f63154f6a025b1b382d7a Mon Sep 17 00:00:00 2001 From: James Smith Date: Fri, 29 Nov 2024 23:16:18 +0000 Subject: [PATCH 4/7] remove library detail from model preview card --- app/components/model_component.html.erb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/app/components/model_component.html.erb b/app/components/model_component.html.erb index 83871610c..0d1882aa0 100644 --- a/app/components/model_component.html.erb +++ b/app/components/model_component.html.erb @@ -45,13 +45,6 @@ "aria-label": [@model.collection.model_name.human, @model.collection.name].join(": ") %> <% end %> - <% if @library.nil? && @model.library %> -
  • - <%= helpers.icon "boxes", Library.model_name.human %> - <%= link_to @model.library.name, models_path((@filters || {}).merge(library: @model.library)), - "aria-label": [Library.model_name.human, @model.library.name].join(": ") %> -
  • - <% end %> <% if @model.caption %>

    <%= sanitize @model.caption %>

    From 717b44246d0d2f9b11cc01e03e42e18d1650b64c Mon Sep 17 00:00:00 2001 From: James Smith Date: Fri, 29 Nov 2024 23:16:35 +0000 Subject: [PATCH 5/7] move edit and delete into a drop menu, and add report --- app/components/model_component.html.erb | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/app/components/model_component.html.erb b/app/components/model_component.html.erb index 0d1882aa0..0eeb5b17e 100644 --- a/app/components/model_component.html.erb +++ b/app/components/model_component.html.erb @@ -20,12 +20,6 @@ <%= @model.name %> <%= helpers.icon("explicit", Model.human_attribute_name(:sensitive)) if @model.sensitive %> - <%= helpers.status_badges(@model) %> -
    -
    - <%= link_to t(".open_button.text"), @model, {class: "btn btn-primary btn-sm", "aria-label": translate(".open_button.label", name: @model.name)} %> - <%= link_to helpers.icon("pencil-fill", t(".edit_button.text")), edit_model_path(@model), {class: "btn btn-outline-secondary btn-sm", "aria-label": translate(".edit_button.label", name: @model.name)} if @can_edit %> - <%= link_to helpers.icon("trash", t(".delete_button.text")), model_path(@model), {method: :delete, class: "btn btn-outline-danger btn-sm", "aria-label": translate(".delete_button.label", name: @model.name), data: {confirm: translate("models.destroy.confirm")}} if @can_destroy %>
    @@ -52,6 +46,24 @@
    +
    +
    + <%= link_to t(".open_button.text"), @model, {class: "btn btn-primary btn-sm", "aria-label": translate(".open_button.label", name: @model.name)} %> + <%= helpers.status_badges(@model) %> +
    +
    + + +
    +
    +
    +
    From e35078176c890218dcf82675bc6fe468c2687ca9 Mon Sep 17 00:00:00 2001 From: James Smith Date: Fri, 29 Nov 2024 23:18:28 +0000 Subject: [PATCH 6/7] add menu i18n key --- config/locales/en.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/config/locales/en.yml b/config/locales/en.yml index 9c5973cd8..173a03e0a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -312,6 +312,7 @@ en: download: Download edit: Edit expand: Expand + menu: Menu new: New report: Report %{type} save: Save From 2c2bd6a6c1092c2dff4d49535f1cb1dca32722c2 Mon Sep 17 00:00:00 2001 From: James Smith Date: Fri, 29 Nov 2024 23:27:15 +0000 Subject: [PATCH 7/7] fix translation --- app/components/model_component.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/model_component.html.erb b/app/components/model_component.html.erb index 0eeb5b17e..8e2e32af7 100644 --- a/app/components/model_component.html.erb +++ b/app/components/model_component.html.erb @@ -57,7 +57,7 @@
    <%= Federails::Moderation::Report.human_attribute_name(:object) %><%= Federails::Moderation::Report.human_attribute_name(:federails_actor) %><%= Federails::Moderation::Report.human_attribute_name(:object) %><%= Federails::Moderation::Report.human_attribute_name(:federails_actor) %> <%= Federails::Moderation::Report.human_attribute_name(:created_at) %>
    <%= icon icon_for(report.object.entity.class), "" %> <%= link_to report.object.entity.name, report.object.entity if report.object&.entity %> + <%= icon (report.local? ? "house" : "globe"), "" %> + <%= report.reporter_address %> <%= report.created_at %> <%= link_to safe_join([icon("search", t("general.view")), t("general.view")], " "), settings_report_path(report), {class: "float-end btn btn-primary"} %>