Skip to content

Commit a0c1d84

Browse files
committed
Fixing review findings
1 parent 87e553e commit a0c1d84

File tree

14 files changed

+126
-179
lines changed

14 files changed

+126
-179
lines changed

app/controllers/report_controller.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def destroy
3333

3434
def create
3535
report = current_user.reports.new(report_params)
36-
report.originator_diaspora_handle = report.reported_author.diaspora_handle
36+
report.reported_author_id = report.reported_author.id
3737
if report.save
3838
render json: true, status: :ok
3939
else
@@ -55,10 +55,10 @@ def statistics_by_reporter
5555
end
5656

5757
def statistics_by_author
58-
sql = "select count(*), originator_diaspora_handle, guid from reports
59-
left join people on originator_diaspora_handle = people.diaspora_handle
60-
where originator_diaspora_handle is not null
61-
group by originator_diaspora_handle, guid order by 1 desc"
58+
sql = "select count(*), diaspora_handle, guid from reports
59+
left join people on reported_author_id = people.id
60+
where reported_author_id is not null
61+
group by diaspora_handle, guid order by 1 desc"
6262
ActiveRecord::Base.connection.exec_query sql
6363
end
6464
end

app/helpers/notifier_helper.rb

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ def post_message(post, opts={})
1414
end
1515
end
1616

17-
def truncated_post_message(post)
18-
if post.respond_to? :message
19-
plain_text = post.message.try(:plain_text_without_markdown).presence || post_page_title(post)
20-
truncate(plain_text, length: 300)
21-
else
22-
I18n.t "notifier.a_post_you_shared"
23-
end
24-
end
25-
2617
# @param comment [Comment] The comment to process.
2718
# @return [String] The formatted comment.
2819
def comment_message(comment, opts={})
@@ -32,13 +23,4 @@ def comment_message(comment, opts={})
3223
I18n.t "notifier.a_limited_post_comment"
3324
end
3425
end
35-
36-
def truncated_comment_message(comment)
37-
if comment.post.public?
38-
plain_text = comment.message.plain_text_without_markdown
39-
truncate(plain_text, length: 180)
40-
else
41-
I18n.t "notifier.a_limited_post_comment"
42-
end
43-
end
4426
end

app/helpers/report_helper.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,29 @@ module ReportHelper
99
def report_content(report)
1010
case (item = report.item)
1111
when Post
12-
raw t("report.post_label", content: link_to(truncated_post_message(item), post_path(item.id)))
12+
raw t("report.post_label", content: link_to(post_page_title(item), post_path(item.id)))
1313
when Comment
14-
raw t("report.comment_label", data: link_to(
15-
h(truncated_comment_message(item)),
14+
raw t("report.comment_label", data: link_to(item.message.title,
1615
post_path(item.post.id, anchor: item.guid)
1716
))
1817
else
1918
t("report.not_found")
2019
end
2120
end
21+
2222
# rubocop:enable Rails/OutputSafety
2323

2424
def link_to_content(report)
2525
case (item = report.item)
2626
when Post
2727
link_to("", post_path(item.id),
28-
{title: "View reported element",
28+
{title: t("report.view_reported_element"),
2929
class: "entypo-eye",
3030
target: "_blank",
3131
rel: "noopener"})
3232
when Comment
3333
link_to("", post_path(item.post.id, anchor: item.guid),
34-
{title: "View reported comment",
34+
{title: t("report.view_reported_element"),
3535
class: "entypo-eye",
3636
target: "_blank",
3737
rel: "noopener"})

app/models/report.rb

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ class Report < ApplicationRecord
1515
belongs_to :post, optional: true
1616
belongs_to :comment, optional: true
1717
belongs_to :item, polymorphic: true
18-
delegate :author, to: :item
1918

2019
STATUS_DELETED = "deleted"
21-
STATUS_NO_ACTION = "no action"
20+
STATUS_NO_ACTION = "no_action"
2221

2322
after_commit :send_report_notification, on: :create
2423

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

3029
def reported_author
30+
return Person.find(reported_author_id) if reported_author_id.present?
3131
item&.author
3232
end
3333

@@ -60,30 +60,17 @@ def destroy_reported_item
6060
item.destroy
6161
end
6262
end
63-
mark_as_reviewed_and_deleted
63+
mark_as_reviewed(STATUS_DELETED)
6464
end
6565

6666
# rubocop:disable Rails/SkipsModelValidations
6767

68-
def mark_as_reviewed_and_deleted
68+
def mark_as_reviewed(with_action=STATUS_NO_ACTION)
6969
Report.where(item_id: item_id, item_type: item_type)
70-
.update_all(reviewed: true, action: STATUS_DELETED)
71-
end
72-
73-
def mark_as_reviewed
74-
Report.where(item_id: item_id, item_type: item_type)
75-
.update_all(reviewed: true, action: STATUS_NO_ACTION)
70+
.update_all(reviewed: true, action: with_action)
7671
end
7772
# rubocop:enable Rails/SkipsModelValidations
7873

79-
def action_deleted?
80-
action&.downcase == STATUS_DELETED.downcase
81-
end
82-
83-
def action_no_action?
84-
action&.downcase == STATUS_NO_ACTION.downcase
85-
end
86-
8774
def send_report_notification
8875
Workers::Mail::ReportWorker.perform_async(id)
8976
end

app/views/report/_checked.haml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
%table.table
22
%tr
33
%th
4-
= t("report.created_at")
4+
= t("report.report_created_at")
55
%th
66
= t("report.reported_by")
77
%th
88
= t("report.reason")
99
%th
1010
= t("report.type")
1111
%th
12-
= t("report.author")
12+
= t("report.reported_author")
1313
%th
1414
= t("report.decision")
1515
%th
@@ -25,11 +25,13 @@
2525
%td
2626
= report.item_type
2727
%td
28-
- unless report.originator_diaspora_handle.nil?
29-
= link_to(report.originator_diaspora_handle, "/people/#{report.originator_guid}")
28+
- if report.reported_author.nil?
29+
= t("report.reported_author_unknown")
30+
- else
31+
= link_to(report.reported_author.diaspora_handle, "/people/#{report.reported_author_guid}")
3032
%td
31-
= t("report.item_deleted") if report.action_deleted?
32-
= t("report.item_no_action") if report.action_no_action?
33+
= t("report.#{report.action}") if report.action.present?
34+
= t("report.decision_unknown") if report.action.nil?
3335
%td
3436
- unless report.item.nil?
3537
= link_to_content(report)

app/views/report/_pending.haml

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,38 @@
11
- @unreviewed_reports.each do |report|
2-
- if report.item
3-
.panel.panel-default
4-
- username = report.user.username
5-
.panel-heading
6-
.reporter.pull-right
7-
!= t("report.reported_label", person: link_to(username, user_profile_path(username)))
8-
.author
9-
%span.reason-label
10-
!= "#{t('report.author')}:"
11-
%span
12-
= report.author.name
13-
.created-at
14-
%span.reason-label
15-
!= "#{t('report.created_at')}:"
16-
%span
17-
= I18n.l(report.created_at, format: :short)
18-
.reason
19-
%span.reason-label
20-
= t("report.reason_label")
21-
%span
22-
= report.text
23-
.panel-body
24-
.content
25-
= report_content(report)
26-
.segment-selection
2+
.panel.panel-default
3+
- reported_by = report.user.username
4+
.panel-heading
5+
.reporter.pull-right
6+
!= t("report.reported_label", person: link_to(reported_by, user_profile_path(reported_by)))
7+
.author
8+
%span.reason-label
9+
!= "#{t('report.reported_author')}:"
10+
%span
11+
= report.reported_author.name if report.item
12+
!= "-" if report.item.nil?
13+
.created-at
14+
%span.reason-label
15+
!= "#{t('report.report_created_at')}:"
16+
%span
17+
= I18n.l(report.created_at, format: :short)
18+
.reason
19+
%span.reason-label
20+
= t("report.reason_label")
21+
%span
22+
= report.text
23+
.panel-body
24+
.content
25+
= report_content(report)
26+
.segment-selection
27+
- if report.item.present?
2728
= button_to t("report.reported_user_details"),
2829
user_search_path(admins_controller_user_search: {guid: report.reported_author.guid}),
2930
class: "btn pull-left btn-info btn-small col-md-3 col-xs-12", method: :post
30-
= button_to t("report.review_link"), report_path(report.id, type: report.item_type),
31-
class: "btn pull-left btn-info btn-small col-md-3 col-xs-12", method: :put
32-
= button_to t("report.delete_link"), report_path(report.id, type: report.item_type),
33-
data: {confirm: t("report.confirm_deletion")},
34-
class: "btn pull-right btn-danger btn-small col-md-3 col-xs-12", method: :delete
35-
- else
36-
.panel.panel-default
37-
- username = report.user.username
38-
.panel-heading
39-
.reporter.pull-right
40-
!= t("report.reported_label", person: link_to(username, user_profile_path(username)))
41-
.title
42-
= report_content(report)
43-
.panel-body
4431
= button_to t("report.review_link"), report_path(report.id, type: report.item_type),
45-
class: "btn pull-left btn-info btn-small", method: :put
32+
class: "btn pull-left btn-info btn-small col-md-3 col-xs-12", method: :put
33+
= button_to t("report.delete_link"), report_path(report.id, type: report.item_type),
34+
data: {confirm: t("report.confirm_deletion")},
35+
class: "btn pull-right btn-danger btn-small col-md-3 col-xs-12", method: :delete
4636
- if @unreviewed_reports.empty?
4737
%h3
4838
= t("report.no_pending_reports")

app/views/report/_statistics.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
%th
2020
= t("report.count")
2121
%th
22-
= t("report.author")
22+
= t("report.reported_author")
2323
- @statistics_by_author.rows.each do |count, author_diaspora_handle, guid|
2424
%tr
2525
%td

config/locales/diaspora/en.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,19 +1057,19 @@ en:
10571057
no_pending_reports: "No pending reports"
10581058
reported_tab: "Reported"
10591059
reviewed_tab: "Reviewed"
1060-
author: "Author"
1060+
reported_author: "Reported author"
10611061
tooltip_incomming: "New incomming reports"
10621062
tooltip_reviewed: "Already reviewed reports"
10631063
tooltip_statistics: "Statistics about reporter and reporting items"
10641064
reported_by: "Reported by"
10651065
statistics_tab: "Statistics"
1066-
created_at: "Created at"
1066+
report_created_at: "Report created at"
10671067
reason: "Reason"
10681068
type: "Type"
10691069
decision: "Decision"
10701070
action: "Action"
1071-
item_deleted: "Deleted"
1072-
item_no_action: "No Action"
1071+
deleted: "Deleted"
1072+
no_action: "No Action"
10731073
count: "Count"
10741074
reason_label: "Reason:"
10751075
review_link: "Mark as reviewed"
@@ -1086,6 +1086,9 @@ en:
10861086
other: "There are %{count} unreviewed reports."
10871087
by_reporter: "By Reporter"
10881088
by_author: "By Author"
1089+
view_reported_element: "View reported element"
1090+
reported_author_unknown: "Unknown"
1091+
decision_unknown: "Unknown"
10891092
profiles:
10901093
edit:
10911094
basic: "My basic profile"

db/migrate/20210421064041_add_action_to_report.rb

Lines changed: 0 additions & 11 deletions
This file was deleted.

db/migrate/20210424054604_add_user_fields_to_reports.rb

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class AddActionFieldsToReports < ActiveRecord::Migration[6.1]
2+
3+
def change
4+
change_table :reports, bulk: true do |t|
5+
t.integer :reported_author_id, index: true
6+
t.string :action
7+
end
8+
9+
Report.find_each do |report|
10+
# get reported author id from item before item gets deleted
11+
if report.reported_author.present?
12+
report.reported_author_id = report.reported_author.id
13+
end
14+
if report.item.present?
15+
report.action = Report::STATUS_NO_ACTION
16+
end
17+
report.save(validate: false, touch: false)
18+
end
19+
end
20+
end

0 commit comments

Comments
 (0)