Skip to content

Commit

Permalink
Merge pull request #3259 from manyfold3d/submit-reports
Browse files Browse the repository at this point in the history
Add report buttons on detail pages and model preview cards
  • Loading branch information
Floppy authored Nov 29, 2024
2 parents 0f9a168 + 2c2bd6a commit be9da57
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 20 deletions.
35 changes: 20 additions & 15 deletions app/components/model_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<%= render partial: "object_preview", locals: {model: @model, file: file} %>
</div>
<% end %>
<% else %>
<div class='preview-empty'> <p>no preview availiable</p></div>
<% else %>
<div class='preview-empty'> <p><%= t(".no_preview") %></p></div>
<% end %>
<div class="card-body">
<div class="row ">
Expand All @@ -20,12 +20,6 @@
<%= @model.name %>
</a>
<%= helpers.icon("explicit", Model.human_attribute_name(:sensitive)) if @model.sensitive %>
<span style="float: right"><%= helpers.status_badges(@model) %></span>
</div>
<div class='mt-2'>
<%= 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 %>
</div>
</div>
<div class="col-auto">
Expand All @@ -45,20 +39,31 @@
"aria-label": [@model.collection.model_name.human, @model.collection.name].join(": ") %>
</li>
<% end %>
<% if @library.nil? && @model.library %>
<li>
<%= 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(": ") %>
</li>
<% end %>
</ul>
<% if @model.caption %>
<p class="card-text"><%= sanitize @model.caption %></p>
<% end %>
</small>
</div>
</div>
<div class="row">
<div class="col">
<%= 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) %>
<div class="float-end">
<div class="btn-group">
<a href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<%= helpers.icon "three-dots-vertical", t("general.menu") %>
</a>
<ul class="dropdown-menu dropdown-menu-end">
<li><%= link_to safe_join([helpers.icon("pencil-fill", t(".edit_button.text")), t(".edit_button.text")], " "), edit_model_path(@model), {class: "dropdown-item", "aria-label": translate(".edit_button.label", name: @model.name)} if @can_edit %></li>
<li><%= link_to safe_join([helpers.icon("trash", t(".delete_button.label")), t(".delete_button.text")], " "), model_path(@model), {method: :delete, class: "dropdown-item", data: {confirm: translate("models.destroy.confirm")}} if @can_destroy %></li>
<li><%= link_to safe_join([helpers.icon("flag", t("general.report", type: "")), t("general.report", type: "")], " "), new_model_report_path(@model), class: "dropdown-item" if SiteSettings.multiuser_enabled? %></li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
29 changes: 29 additions & 0 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions app/views/collections/_collection.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<%= render partial: "object_preview", locals: {model: model, file: file} %>
</div>
<% end %>
<% else %>
<div class='preview-empty'> <p><%= t ".no_preview" %></p></div>
<% else %>
<div class='preview-empty'> <p><%= t ".no_preview" %></p></div>
<% end %>
<div class="card-body">
<div class="card-title"><%= collection.name.careful_titleize %></div>
Expand Down
1 change: 1 addition & 0 deletions app/views/creators/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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" %>
1 change: 1 addition & 0 deletions app/views/models/_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
Expand Down
4 changes: 4 additions & 0 deletions app/views/models/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@
</div>
</div>

<%= 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 %>
<p>
Expand Down
11 changes: 11 additions & 0 deletions app/views/reports/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h3><%= t(".title", type: @reportable.model_name.human, name: @reportable.name) %></h3>

<p class="lead"><%= t ".description" %></p>

<%= form_with model: [@reportable, @report] do |form| %>

<%= text_input_row form, :content %>

<%= form.submit translate(".submit"), class: "btn btn-primary" %>

<% end %>
8 changes: 6 additions & 2 deletions app/views/settings/reports/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@

<table class="table table-striped">
<tr>
<th><%= Federails::Moderation::Report.human_attribute_name(:object) %></th>
<th><%= Federails::Moderation::Report.human_attribute_name(:federails_actor) %></th>
<th colspan="2"><%= Federails::Moderation::Report.human_attribute_name(:object) %></th>
<th colspan="2"><%= Federails::Moderation::Report.human_attribute_name(:federails_actor) %></th>
<th><%= Federails::Moderation::Report.human_attribute_name(:created_at) %></th>
<th></th>
</tr>
<% @reports.each do |report| %>
<tr>
<td><%= icon icon_for(report.object.entity.class), "" %></td>
<td><%= link_to report.object.entity.name, report.object.entity if report.object&.entity %></td>
<td>
<%= icon (report.local? ? "house" : "globe"), "" %>
</td>
<td><%= report.reporter_address %></td>
<td><%= report.created_at %></td>
<td><%= link_to safe_join([icon("search", t("general.view")), t("general.view")], " "), settings_report_path(report), {class: "float-end btn btn-primary"} %></td>
Expand Down
2 changes: 1 addition & 1 deletion config/locales/collections/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ en:
download: Download
edit: Edit
expand: Expand
menu: Menu
new: New
report: Report %{type}
save: Save
view: View
home:
Expand Down Expand Up @@ -398,6 +400,7 @@ en:
edit_button:
label: Edit model %{name}
text: Edit
no_preview: No preview available
open_button:
label: Open model %{name}
text: Open
Expand All @@ -408,6 +411,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 %{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 <code>PUID</code> and <code>PGID</code> environment variables. See <a href='https://manyfold.app/sysadmin/configuration.html#required'>the configuration documentation</a> for details.
sites:
Expand Down
6 changes: 6 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down

0 comments on commit be9da57

Please sign in to comment.