-
Notifications
You must be signed in to change notification settings - Fork 29
feat: Allow users to report comments #3016
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
base: main
Are you sure you want to change the base?
Conversation
@@ -168,7 +168,7 @@ def report | |||
|
|||
ReportMailer.with(reported_content: @request_for_comment).report_content.deliver_later | |||
|
|||
redirect_to @request_for_comment, notice: t('.report.reported'), status: :see_other | |||
redirect_to @request_for_comment, notice: t('.reported'), status: :see_other |
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.
Through unrelated changes in the locals, i18_task asked me to adjust the path. The message localization is unchanged.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3016 +/- ##
==========================================
+ Coverage 70.08% 70.23% +0.14%
==========================================
Files 215 216 +1
Lines 6850 6870 +20
==========================================
+ Hits 4801 4825 +24
+ Misses 2049 2045 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
app/models/spam_report.rb
Outdated
@@ -0,0 +1,51 @@ | |||
# frozen_string_literal: true | |||
|
|||
class SpamReport |
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.
I extracted this object out of the mailer because the mailer logic has become quite complex.
I have done this for the following reasons:
- I wanted to test the delegation between Comment and RfC in isolation (without rendering email).
- The email feature would become too complex with this much logic (single responsibility).
Putting this into the model is a bit debatable. I think in smaller Rails this is a valid strategy.
Another approach could have been to create separate mailers for comments and RfCs. I decided against this because I think this approach keeps more of the business logic out of the mailer.
@@ -116,6 +116,9 @@ $(document).on('turbo-migration:load', function () { | |||
<button class="action-edit btn btn-sm btn-warning">' + I18n.t('shared.edit') + '</button> \ | |||
<button class="action-delete btn btn-sm btn-danger">' + I18n.t('shared.destroy') + '</button> \ | |||
</div> \ | |||
<div class="text-warning' + (comment.reportable ? '' : ' d-none') + '"> \ |
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.
Originally I wanted to add this feature by utilizing the Turbo framework. However, the changes seemed a bit large, and I want to release this soon. Therefore, I thought it was not a good time for the Turbo migration.
0836383
to
1136443
Compare
@@ -1,6 +1,11 @@ | |||
# frozen_string_literal: true | |||
|
|||
json.array!(@comments) do |comment| | |||
json.extract! comment, :id, :user_id, :file_id, :row, :column, :text, :username, :date, :updated, :editable | |||
json.extract! comment, :id, :user_id, :file_id, :row, :column, :text |
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.
Please allow me this small refactor with this PR. I think this view-related field should be set in the template and not in the Controller and Model.
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.
app/models/spam_report.rb
Outdated
@@ -0,0 +1,51 @@ | |||
# frozen_string_literal: true | |||
|
|||
class SpamReport |
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.
I think it's a good idea to extract that logic, but I would propose a different name. SpamReport
sounds very specific and as far as I understand, we not really trying to catch spam here but inappropriate content. Wouldn't Report
be sufficient?
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.
Additionally I'm not sure if models/
is the right folder for this class. AFAIK we don't have this kind of class yet, so we would have to create a new place for this.
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.
I have renamed SpamReport to UserContentReport. I think it makes it more clear that any kind of user is reported not only spam.
Furthermore, I investigated where to put these kind objects. I considered turning it into a form object to stick it into app/forms. But this is not a form and just would make it more difficult. I also considered if this model is a parameter object, but I think it is not because of the business logic.
I think it should remain in models for the following reasons:
- I think extracted objects that are not common patterns like Forms, Parameters, or Policies should remain in
/app/models
. The model folder holds objects with business logic. In my opinion it is not necessary for these objects to have a persistence layer. - For this kind of logic objects we have no meaningful suffix. For other patterns, the suffix like UserPolicy, UserController or SignUpForm tells you where this object is placed. Any object without that should live in
/app/models/
🤔
In this example of extracting a class from a Rails controller the models folder was used as well.
https://thoughtbot.com/ruby-science/extract-class.html
I am not perfectly happy with this as well, but I don't know how to solve this in a better way.
I have only looked at this feature from the users views. I am not sure if a teacher/admin should be able to report content? 🤔 For now I will try to adjust the view. |
Comments can be used to potentially harass users who request comments. A button was added to report a message as spam. Resolves #2715
Co-authored-by: kkoehn <[email protected]>
Co-authored-by: kkoehn <[email protected]>
Not only Spam will be reported. Any user content can be reported. Mailer name was adjusted to fit the naming convention.
3f74f8f
to
def5481
Compare
Comments can be used to potentially harass users who request comments. A button was added to report a message as spam.
Resolves #2715