Skip to content

Commit

Permalink
Fixing review findings
Browse files Browse the repository at this point in the history
  • Loading branch information
tclaus committed Oct 30, 2022
1 parent 87e553e commit a0c1d84
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 179 deletions.
10 changes: 5 additions & 5 deletions app/controllers/report_controller.rb
Expand Up @@ -33,7 +33,7 @@ def destroy

def create
report = current_user.reports.new(report_params)
report.originator_diaspora_handle = report.reported_author.diaspora_handle
report.reported_author_id = report.reported_author.id
if report.save
render json: true, status: :ok
else
Expand All @@ -55,10 +55,10 @@ def statistics_by_reporter
end

def statistics_by_author
sql = "select count(*), originator_diaspora_handle, guid from reports
left join people on originator_diaspora_handle = people.diaspora_handle
where originator_diaspora_handle is not null
group by originator_diaspora_handle, guid order by 1 desc"
sql = "select count(*), diaspora_handle, guid from reports
left join people on reported_author_id = people.id
where reported_author_id is not null
group by diaspora_handle, guid order by 1 desc"
ActiveRecord::Base.connection.exec_query sql
end
end
18 changes: 0 additions & 18 deletions app/helpers/notifier_helper.rb
Expand Up @@ -14,15 +14,6 @@ def post_message(post, opts={})
end
end

def truncated_post_message(post)
if post.respond_to? :message
plain_text = post.message.try(:plain_text_without_markdown).presence || post_page_title(post)
truncate(plain_text, length: 300)
else
I18n.t "notifier.a_post_you_shared"
end
end

# @param comment [Comment] The comment to process.
# @return [String] The formatted comment.
def comment_message(comment, opts={})
Expand All @@ -32,13 +23,4 @@ def comment_message(comment, opts={})
I18n.t "notifier.a_limited_post_comment"
end
end

def truncated_comment_message(comment)
if comment.post.public?
plain_text = comment.message.plain_text_without_markdown
truncate(plain_text, length: 180)
else
I18n.t "notifier.a_limited_post_comment"
end
end
end
10 changes: 5 additions & 5 deletions app/helpers/report_helper.rb
Expand Up @@ -9,29 +9,29 @@ module ReportHelper
def report_content(report)
case (item = report.item)
when Post
raw t("report.post_label", content: link_to(truncated_post_message(item), post_path(item.id)))
raw t("report.post_label", content: link_to(post_page_title(item), post_path(item.id)))
when Comment
raw t("report.comment_label", data: link_to(
h(truncated_comment_message(item)),
raw t("report.comment_label", data: link_to(item.message.title,
post_path(item.post.id, anchor: item.guid)
))
else
t("report.not_found")
end
end

# rubocop:enable Rails/OutputSafety

def link_to_content(report)
case (item = report.item)
when Post
link_to("", post_path(item.id),
{title: "View reported element",
{title: t("report.view_reported_element"),
class: "entypo-eye",
target: "_blank",
rel: "noopener"})
when Comment
link_to("", post_path(item.post.id, anchor: item.guid),
{title: "View reported comment",
{title: t("report.view_reported_element"),
class: "entypo-eye",
target: "_blank",
rel: "noopener"})
Expand Down
27 changes: 7 additions & 20 deletions app/models/report.rb
Expand Up @@ -15,19 +15,19 @@ class Report < ApplicationRecord
belongs_to :post, optional: true
belongs_to :comment, optional: true
belongs_to :item, polymorphic: true
delegate :author, to: :item

STATUS_DELETED = "deleted"
STATUS_NO_ACTION = "no action"
STATUS_NO_ACTION = "no_action"

after_commit :send_report_notification, on: :create

scope :join_originator, -> {
joins("LEFT JOIN people ON originator_diaspora_handle = people.diaspora_handle ")
.select("reports.*, people.guid as originator_guid")
joins("LEFT JOIN people ON reported_author_id = people.id ")
.select("reports.*, people.diaspora_handle as reported_author, people.guid as reported_author_guid")
}

def reported_author
return Person.find(reported_author_id) if reported_author_id.present?
item&.author
end

Expand Down Expand Up @@ -60,30 +60,17 @@ def destroy_reported_item
item.destroy
end
end
mark_as_reviewed_and_deleted
mark_as_reviewed(STATUS_DELETED)
end

# rubocop:disable Rails/SkipsModelValidations

def mark_as_reviewed_and_deleted
def mark_as_reviewed(with_action=STATUS_NO_ACTION)
Report.where(item_id: item_id, item_type: item_type)
.update_all(reviewed: true, action: STATUS_DELETED)
end

def mark_as_reviewed
Report.where(item_id: item_id, item_type: item_type)
.update_all(reviewed: true, action: STATUS_NO_ACTION)
.update_all(reviewed: true, action: with_action)
end
# rubocop:enable Rails/SkipsModelValidations

def action_deleted?
action&.downcase == STATUS_DELETED.downcase
end

def action_no_action?
action&.downcase == STATUS_NO_ACTION.downcase
end

def send_report_notification
Workers::Mail::ReportWorker.perform_async(id)
end
Expand Down
14 changes: 8 additions & 6 deletions app/views/report/_checked.haml
@@ -1,15 +1,15 @@
%table.table
%tr
%th
= t("report.created_at")
= t("report.report_created_at")
%th
= t("report.reported_by")
%th
= t("report.reason")
%th
= t("report.type")
%th
= t("report.author")
= t("report.reported_author")
%th
= t("report.decision")
%th
Expand All @@ -25,11 +25,13 @@
%td
= report.item_type
%td
- unless report.originator_diaspora_handle.nil?
= link_to(report.originator_diaspora_handle, "/people/#{report.originator_guid}")
- if report.reported_author.nil?
= t("report.reported_author_unknown")
- else
= link_to(report.reported_author.diaspora_handle, "/people/#{report.reported_author_guid}")
%td
= t("report.item_deleted") if report.action_deleted?
= t("report.item_no_action") if report.action_no_action?
= t("report.#{report.action}") if report.action.present?
= t("report.decision_unknown") if report.action.nil?
%td
- unless report.item.nil?
= link_to_content(report)
Expand Down
70 changes: 30 additions & 40 deletions app/views/report/_pending.haml
@@ -1,48 +1,38 @@
- @unreviewed_reports.each do |report|
- if report.item
.panel.panel-default
- username = report.user.username
.panel-heading
.reporter.pull-right
!= t("report.reported_label", person: link_to(username, user_profile_path(username)))
.author
%span.reason-label
!= "#{t('report.author')}:"
%span
= report.author.name
.created-at
%span.reason-label
!= "#{t('report.created_at')}:"
%span
= I18n.l(report.created_at, format: :short)
.reason
%span.reason-label
= t("report.reason_label")
%span
= report.text
.panel-body
.content
= report_content(report)
.segment-selection
.panel.panel-default
- reported_by = report.user.username
.panel-heading
.reporter.pull-right
!= t("report.reported_label", person: link_to(reported_by, user_profile_path(reported_by)))
.author
%span.reason-label
!= "#{t('report.reported_author')}:"
%span
= report.reported_author.name if report.item
!= "-" if report.item.nil?
.created-at
%span.reason-label
!= "#{t('report.report_created_at')}:"
%span
= I18n.l(report.created_at, format: :short)
.reason
%span.reason-label
= t("report.reason_label")
%span
= report.text
.panel-body
.content
= report_content(report)
.segment-selection
- if report.item.present?
= button_to t("report.reported_user_details"),
user_search_path(admins_controller_user_search: {guid: report.reported_author.guid}),
class: "btn pull-left btn-info btn-small col-md-3 col-xs-12", method: :post
= button_to t("report.review_link"), report_path(report.id, type: report.item_type),
class: "btn pull-left btn-info btn-small col-md-3 col-xs-12", method: :put
= button_to t("report.delete_link"), report_path(report.id, type: report.item_type),
data: {confirm: t("report.confirm_deletion")},
class: "btn pull-right btn-danger btn-small col-md-3 col-xs-12", method: :delete
- else
.panel.panel-default
- username = report.user.username
.panel-heading
.reporter.pull-right
!= t("report.reported_label", person: link_to(username, user_profile_path(username)))
.title
= report_content(report)
.panel-body
= button_to t("report.review_link"), report_path(report.id, type: report.item_type),
class: "btn pull-left btn-info btn-small", method: :put
class: "btn pull-left btn-info btn-small col-md-3 col-xs-12", method: :put
= button_to t("report.delete_link"), report_path(report.id, type: report.item_type),
data: {confirm: t("report.confirm_deletion")},
class: "btn pull-right btn-danger btn-small col-md-3 col-xs-12", method: :delete
- if @unreviewed_reports.empty?
%h3
= t("report.no_pending_reports")
2 changes: 1 addition & 1 deletion app/views/report/_statistics.haml
Expand Up @@ -19,7 +19,7 @@
%th
= t("report.count")
%th
= t("report.author")
= t("report.reported_author")
- @statistics_by_author.rows.each do |count, author_diaspora_handle, guid|
%tr
%td
Expand Down
11 changes: 7 additions & 4 deletions config/locales/diaspora/en.yml
Expand Up @@ -1057,19 +1057,19 @@ en:
no_pending_reports: "No pending reports"
reported_tab: "Reported"
reviewed_tab: "Reviewed"
author: "Author"
reported_author: "Reported author"
tooltip_incomming: "New incomming reports"
tooltip_reviewed: "Already reviewed reports"
tooltip_statistics: "Statistics about reporter and reporting items"
reported_by: "Reported by"
statistics_tab: "Statistics"
created_at: "Created at"
report_created_at: "Report created at"
reason: "Reason"
type: "Type"
decision: "Decision"
action: "Action"
item_deleted: "Deleted"
item_no_action: "No Action"
deleted: "Deleted"
no_action: "No Action"
count: "Count"
reason_label: "Reason:"
review_link: "Mark as reviewed"
Expand All @@ -1086,6 +1086,9 @@ en:
other: "There are %{count} unreviewed reports."
by_reporter: "By Reporter"
by_author: "By Author"
view_reported_element: "View reported element"
reported_author_unknown: "Unknown"
decision_unknown: "Unknown"
profiles:
edit:
basic: "My basic profile"
Expand Down
11 changes: 0 additions & 11 deletions db/migrate/20210421064041_add_action_to_report.rb

This file was deleted.

19 changes: 0 additions & 19 deletions db/migrate/20210424054604_add_user_fields_to_reports.rb

This file was deleted.

20 changes: 20 additions & 0 deletions db/migrate/20221030224657_add_action_fields_to_reports.rb
@@ -0,0 +1,20 @@
class AddActionFieldsToReports < ActiveRecord::Migration[6.1]

def change
change_table :reports, bulk: true do |t|
t.integer :reported_author_id, index: true
t.string :action
end

Report.find_each do |report|
# get reported author id from item before item gets deleted
if report.reported_author.present?
report.reported_author_id = report.reported_author.id
end
if report.item.present?
report.action = Report::STATUS_NO_ACTION
end
report.save(validate: false, touch: false)
end
end
end

0 comments on commit a0c1d84

Please sign in to comment.