-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance report overview #8239
base: develop
Are you sure you want to change the base?
Enhance report overview #8239
Conversation
This Feature was requested in this discussion: It is also IMHO a pre-work and touches issue #7847 "handling fake accounts / forward to pod". |
app/helpers/report_helper.rb
Outdated
@@ -8,17 +8,36 @@ module ReportHelper | |||
def report_content(report) | |||
case (item = report.item) | |||
when Post | |||
raw t("report.post_label", content: link_to(post_message(item), post_path(item.id))) | |||
raw t("report.post_label", content: link_to(truncated_post_message(item), post_path(item.id))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rails/OutputSafety: Tagging a string as html safe may be a security risk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Flaburgan Here is the old ugly diaspora link-inside-translated text part. I did not care to change anything here
41631c5
to
6bb5180
Compare
6bb5180
to
7c5c7c4
Compare
Hey! This is very needed, thank you for working on this. I'm going to try it and do a review, but two quick remarks:
|
The Images in the first comment are not matching the text.
"Reporter" and "Author" then - I missed this. Do you mean to use the Database' ENUM type? Like the Idea. |
I mean your mockup gave the impression that "No action" was the text stored in the database. This must be avoided, the state (deleted or ignored) has to be stored in the DB, then the UI will display a label depending of the state. |
@Flaburgan Can you make a re-Review? I have abstracted the action - text from database to UI. Wouldn't it be more convenient to open the github "Reviewers" - section? |
I was actually doing it right now 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is GREAT, I love it!
I did some remarks but that's mostly in good shape already. But you would need to also add tests. I started to add them in #8035 but I'm actually not able to navigate to /report in my PR. If you help me fix that PR you should then be able to rebase on me and complete the tests there.
end | ||
|
||
def statistics_by_reporter | ||
sql = "select count(*), diaspora_handle, guid from reports |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't that query be written with ActiveRecord?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, But I don't have an idea how. The trick here is: the group by counts all reports, and adds the diaspora_handle from people's table. If this is possible, I think the sql is more straight-forward.
app/controllers/report_controller.rb
Outdated
end | ||
|
||
def statistics_by_author | ||
sql = "select count(*), originator_diaspora_handle, guid from reports |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, is there any reason why you use SQL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above, it seems SQL is easier to read (and I don't have a clue how to build this in ActiveRecored) If this can be done, make a proposal without changing the returning data. (haml files rely on that)
8706cc2
to
0adc2aa
Compare
@Flaburgan I rebased this on Enhance Report Form |
With undecided / reviewed and statistics page. Already reviewed reports stay visible. Enhances Spam/user control fixes diaspora#8239
f2f5232
to
307053f
Compare
@Flaburgan , @SuperTux88 |
#8035 is adding tests on that part of the code so we said we should merge it first, but it's blocked by some weird Jasmine flickering tests. If you want to help there you're welcome! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is depending on #8035, this isn't a full review yet (I maybe have missed some things between all the changes of the other PR), and you might also want to wait until #8035 is done before working on some of my comments (as there will be conflicts). But there is also already some feedback you can work on without having conflicts, so I already wanted to submit that before the other PR is done.
Also, I couldn't add a comment to that file, as it doesn't have a single line, but you accidentally deleted tmp/pids/.gitkeep
.
|
||
class AddUserFieldsToReports < ActiveRecord::Migration[5.2] | ||
def change | ||
add_column :reports, :originator_diaspora_handle, :string, index: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, please don't use the term "diaspora handle" anymore, it's called "diaspora* ID" now. There are still some really old columns that are called diaspora_handle
but that's just because nobody renamed them yet.
Second, instead of storing the diaspora ID, you should just store the person ID.
I'm also not sure about "originator", I think reported_person_id
or reported_author_id
is clearer, that it's about the reported content not about the reporter (the originator of the report).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With ID you mean the numeric id column or the unique guid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with "person ID" I mean the numeric id
column of the people
table.
With undecided / reviewed and statistics page Already reviewed reports stay visible Enhances Spam/user control fixes diaspora#8239
de58572
to
a0c1d84
Compare
app/assets/javascripts/app/app.js
Outdated
$("#reportModal").modal("hide"); | ||
let textarea = document.getElementById("report-reason-field"); | ||
let report = { | ||
item_id: form.dataset.reportId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Identifier 'item_id' is not in camel case.
app/assets/javascripts/app/app.js
Outdated
let textarea = document.getElementById("report-reason-field"); | ||
let report = { | ||
item_id: form.dataset.reportId, | ||
item_type: form.dataset.reportType, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Identifier 'item_type' is not in camel case.
|
||
def reported_author | ||
item.author if item | ||
return Person.find(reported_author_id) if reported_author_id.present? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.
app/models/report.rb
Outdated
return unless Report.where(item_id: item_id, item_type: item_type).exists?(user_id: user_id) | ||
|
||
errors.add(:base, "You cannot report the same post twice.") | ||
if Report.where(item_id: item_id, item_type: item_type).exists?(user_id: user_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/GuardClause: Use a guard clause (return unless Report.where(item_id: item_id, item_type: item_type).exists?(user_id: user_id)
) instead of wrapping the code inside a conditional expression.
app/models/report.rb
Outdated
return unless Post.find_by(id: item_id).nil? && Comment.find_by(id: item_id).nil? | ||
|
||
errors.add(:base, "Post or comment was already deleted or doesn't exists.") | ||
if Post.find_by(id: item_id).nil? && Comment.find_by(id: item_id).nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/GuardClause: Use a guard clause (return unless Post.find_by(id: item_id).nil? && Comment.find_by(id: item_id).nil?
) instead of wrapping the code inside a conditional expression.
@@ -0,0 +1,20 @@ | |||
class AddActionFieldsToReports < ActiveRecord::Migration[6.1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/FrozenStringLiteralComment: Missing frozen string literal comment.
@@ -0,0 +1,20 @@ | |||
class AddActionFieldsToReports < ActiveRecord::Migration[6.1] | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/EmptyLinesAroundClassBody: Extra empty line detected at class body beginning.
|
||
Report.find_each do |report| | ||
# get reported author id from item before item gets deleted | ||
if report.reported_author.present? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/IfUnlessModifier: Favor modifier if
usage when having a single-line body. Another good alternative is the usage of control flow &&
/||
.
if report.reported_author.present? | ||
report.reported_author_id = report.reported_author.id | ||
end | ||
if report.item.present? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/IfUnlessModifier: Favor modifier if
usage when having a single-line body. Another good alternative is the usage of control flow &&
/||
.
a0c1d84
to
96153c0
Compare
@Flaburgan I rebased this to your #8035 and fixed most of my issues here. |
With undecided / reviewed and statistics page Already reviewed reports stay visible Enhances Spam/user control fixes diaspora#8239
96153c0
to
98d5180
Compare
= t("report.decision") | ||
%th | ||
= t("report.action") | ||
- @reviewed_reports.each do |report| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using instance variables in partials views
@@ -0,0 +1,43 @@ | |||
- @unreviewed_reports.each do |report| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using instance variables in partials views
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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using instance variables in partials views
@@ -0,0 +1,43 @@ | |||
- @unreviewed_reports.each do |report| | |||
.panel.panel-default | |||
- reported_by = report.user.username |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint/UselessAssignment: Useless assignment to variable - reported_by
. Did you mean report
?
!= t("report.reported_label", person: link_to(reported_by, user_profile_path(reported_by))) | ||
.author | ||
%span.reason-label | ||
!= "#{t('report.reported_author')}:" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
= t("report.count") | ||
%th | ||
= t("report.reported_author") | ||
- @statistics_by_author.rows.each do |count, author_diaspora_handle, guid| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using instance variables in partials views
@@ -4,33 +4,44 @@ class Report < ApplicationRecord | |||
validates :user_id, presence: true | |||
validates :item_id, presence: true | |||
validates :item_type, presence: true, inclusion: { | |||
in: %w(Post Comment), message: "Type should match `Post` or `Comment`!"} | |||
in: %w[Post Comment], message: "Type should match `Post` or `Comment`!" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rails/I18nLocaleTexts: Move locale texts to the locale files in the config/locales
directory.
end | ||
|
||
def entry_does_not_exist | ||
return unless Report.where(item_id: item_id, item_type: item_type).exists?(user_id: user_id) | ||
|
||
errors.add(:base, "You cannot report the same post twice.") | ||
errors[:base] << "You cannot report the same post twice." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rails/DeprecatedActiveModelErrorsMethods: Avoid manipulating ActiveModel errors as hash directly.
end | ||
|
||
def post_or_comment_does_exist | ||
return unless Post.find_by(id: item_id).nil? && Comment.find_by(id: item_id).nil? | ||
|
||
errors.add(:base, "Post or comment was already deleted or doesn't exists.") | ||
errors[:base] << "Post or comment was already deleted or doesn't exists." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rails/DeprecatedActiveModelErrorsMethods: Avoid manipulating ActiveModel errors as hash directly.
@@ -50,12 +61,16 @@ def destroy_reported_item | |||
item.destroy | |||
end | |||
end | |||
mark_as_reviewed | |||
mark_as_reviewed(STATUS_DELETED) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/AbcSize: Assignment Branch Condition size for destroy_reported_item is too high. [<0, 32, 7> 32.76/20]
So because the report modal got merged, I rebased this MR, squashed the commits and fixed the front-end pronto problems. There are still a lot of them but I'd like help to resolve those. |
With undecided / reviewed and statistics page Already reviewed reports stay visible Enhances Spam/user control fixes diaspora#8239
98d5180
to
9d89f2a
Compare
@SuperTux88 about the remark you made about the design now that multi lines reports are possible. It looks fine (the design isn't broken) but we are losing the line break: Is there anything else you want me to check on the front-end side? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't a full review, I only had a quick look. But it looks like something went wrong when rebasing this, as at least the migration was dropped (which probably also explains why the tests failed).
It looks fine (the design isn't broken) but we are losing the line break
Well, the reports contain plain newlines, you would need to replace them with html-newlines (but ensure that no other html tags can be injected, so not just mark the string as html-safe)
|
||
def mark_as_reviewed(with_action=STATUS_NO_ACTION) | ||
Report.where(item_id: item_id, item_type: item_type) | ||
.update_all(reviewed: true, action: with_action) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no action
column anymore, did you accidentally drop the migrations?
# @param opts [Hash] Optional hash. Accepts :length parameters. | ||
# @return [String] The formatted post. | ||
def post_message(post, opts={}) | ||
rendered = opts[:html] ? post.message&.markdownified_for_mail : post.message&.plain_text_without_markdown | ||
rendered.presence || post_page_title(post) | ||
if post.respond_to? :message | ||
post.message.try(:plain_text_without_markdown).presence || post_page_title(post) | ||
else | ||
I18n.t "notifier.a_post_you_shared" | ||
end | ||
end | ||
|
||
# @param comment [Comment] The comment to process. | ||
# @param opts [Hash] Optional hash. Accepts :html parameter. | ||
# @return [String] The formatted comment. | ||
def comment_message(comment, opts={}) | ||
if comment.post.public? | ||
opts[:html] ? comment.message.markdownified_for_mail : comment.message.plain_text_without_markdown | ||
comment.message.plain_text_without_markdown | ||
else | ||
I18n.translate "notifier.a_limited_post_comment" | ||
I18n.t "notifier.a_limited_post_comment" | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These helpers also get used for the notification mails (hence the name "NotifierHelper"), you can't just completely change it's functionality and drop html support. But it looks like you aren't even using these helpers anymore, so maybe just revert these changes?
This PR enhances the admin/moderators report overview by
Heads up!
It needs a migration!
Two fields are added: a 'action' textfield that is used to describe what happened to the report. Its free text, but filled based on the action.
The second fields holds the diaspora_handel for the originator. This is needed because after deleting a report this information is gone.
What is the outcome?
A Podmin now has more insights in old reports and in most reporter and most originators. A valuable base for more decisions what to do.
Future
List of reports grows without limits - a paginated view would be nice, but that was currently above my skill level.
Screenshots
(Added date time)
( deleted or reviewed reports)
(statistics with links to the authors / originators)
Comments, Ideas, critics... welcome!