-
Notifications
You must be signed in to change notification settings - Fork 30
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5d13130
feat: Allow users to report comments
arkirchner ae590b5
Update config/locales/de/comment.yml
arkirchner 9434361
Update config/locales/en/comment.yml
arkirchner 8a4224b
Update spec/system/report_request_for_comment_comments_system_spec.rb
arkirchner 3b452e8
Update spec/mailers/user_content_report_mailer_spec.rb
arkirchner 5298c9d
Update spec/lib/user_content_report_spec.rb
arkirchner f9dc9e3
Remove single line and attr_reader
arkirchner 38d3c0d
Spec improvments
arkirchner 97fafda
Use subject in user content report spec
arkirchner bdd3f6b
Normalize locals
arkirchner 2afceff
Normalize locals
arkirchner 74ad12d
Update app/views/comments/index.json.jbuilder
arkirchner 26fcacf
applied rubocop changes
arkirchner 992301e
fix typo
arkirchner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class UserContentReportMailer < ApplicationMailer | ||
| default to: CodeOcean::Config.new(:code_ocean).read.dig(:content_moderation, :report_emails) | ||
|
|
||
| def report_content | ||
| @user_content_report = UserContentReport.new(reported_content: params.fetch(:reported_content)) | ||
|
|
||
| mail(subject: I18n.t('user_content_report_mailer.report_content.subject', human_model_name: @user_content_report.human_model_name)) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
|
arkirchner marked this conversation as resolved.
|
||
| json.username comment.user.displayname | ||
| json.date comment.created_at.strftime('%d.%m.%Y %k:%M') | ||
| json.updated(comment.created_at != comment.updated_at) | ||
|
arkirchner marked this conversation as resolved.
|
||
| json.editable policy(comment).edit? | ||
| json.reportable policy(comment).report? | ||
| json.url comment_url(comment, format: :json) | ||
| end | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| /# locals: (request_for_comment:) | ||
|
|
||
| - if policy(request_for_comment).report? | ||
| = button_to(t('.report'), report_request_for_comment_path(request_for_comment), | ||
| = button_to(t('shared.report'), report_request_for_comment_path(request_for_comment), | ||
| data: {confirm: t('.confirm')}, | ||
| class: 'btn btn-light btn-sm', | ||
| form: {class: 'd-inline float-end'}) |
6 changes: 6 additions & 0 deletions
6
app/views/user_content_report_mailer/report_content.html.slim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| h3 = t('.prolog') | ||
| blockquote style="white-space: pre-wrap;" = @user_content_report.reported_message | ||
| p = t('.take_action') | ||
| p = link_to(request_for_comment_url(@user_content_report.related_request_for_comment), request_for_comment_url(@user_content_report.related_request_for_comment)) | ||
| - if @user_content_report.course_url.present? | ||
| p = link_to(t('.authentication'), @user_content_report.course_url) |
12 changes: 12 additions & 0 deletions
12
app/views/user_content_report_mailer/report_content.text.slim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| == t('.prolog') | ||
| == "\n\n" | ||
| == @user_content_report.reported_message.lines.map { "> #{it}" }.join | ||
| == "\n\n" | ||
| == t('.take_action') | ||
| == "\n\n" | ||
| == request_for_comment_url(@user_content_report.related_request_for_comment) | ||
| == "\n\n" | ||
| - if @user_content_report.course_url.present? | ||
| == t('.authentication') | ||
| == "\n\n" | ||
| == @user_content_report.course_url |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,4 +7,5 @@ de: | |
| other: Kommentare | ||
| comments: | ||
| deleted: Gelöscht | ||
| reported: Kommentar wurde gemeldet. | ||
| save_update: Speichern | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
config/locales/de/report.yml → config/locales/de/user_content_report.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| --- | ||
| de: | ||
| report_mailer: | ||
| user_content_report_mailer: | ||
| report_content: | ||
| authentication: Kurs-URL für die LTI-Authentifizierung. | ||
| prolog: 'Die folgenden Inhalte wurden als unangemessen gemeldet:' | ||
| subject: 'Spam Report: Ein %{content_name} in CodeOcean wurde als unangemessen markiert.' | ||
| subject: 'Content Report: Ein %{human_model_name} in CodeOcean wurde als unangemessen markiert.' | ||
| take_action: Bitte ergreifen Sie gegebenenfalls Maßnahmen. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,4 +7,5 @@ en: | |
| other: Comments | ||
| comments: | ||
| deleted: Deleted | ||
| reported: Comment has been reported. | ||
| save_update: Save | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
config/locales/en/report.yml → config/locales/en/user_content_report.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| --- | ||
| en: | ||
| report_mailer: | ||
| user_content_report_mailer: | ||
| report_content: | ||
| authentication: Course URL for LTI authentication. | ||
| prolog: 'The following content has been reported as inappropriate:' | ||
| subject: 'Spam Report: A %{content_name} on CodeOcean has been marked as inappropriate.' | ||
| subject: 'Content Report: A %{human_model_name} on CodeOcean has been marked as inappropriate.' | ||
| take_action: Please take action if required. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class UserContentReport | ||
| def initialize(reported_content:) | ||
| unless [Comment, RequestForComment].include?(reported_content.class) | ||
| raise("#{reported_content.model_name} is not configured for content reports.") | ||
| end | ||
|
|
||
| @reported_content = reported_content | ||
| end | ||
|
|
||
| # NOTE: This implementation assumes the course URL is static and does not vary per user. | ||
| # This is currently valid for a majority of use cases. However, in dynamic scenarios (such as | ||
| # content trees in openHPI used in conjunction with A/B/n testing) this assumption may no | ||
| # longer hold true. | ||
| def course_url = lti_parameters['launch_presentation_return_url'] | ||
|
|
||
| def human_model_name = @reported_content.model_name.human | ||
|
|
||
| def reported_message | ||
| case @reported_content | ||
| when RequestForComment | ||
| @reported_content.question | ||
| when Comment | ||
| @reported_content.text | ||
| end | ||
| end | ||
|
|
||
| def related_request_for_comment | ||
| case @reported_content | ||
| when RequestForComment | ||
| @reported_content | ||
| when Comment | ||
| @reported_content.request_for_comment | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def lti_parameters | ||
| LtiParameter.find_by(study_group:, exercise:)&.lti_parameters || {} | ||
| end | ||
|
|
||
| def study_group | ||
| @reported_content.submission.study_group | ||
| end | ||
|
|
||
| def exercise | ||
| related_request_for_comment.exercise | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.