-
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?
Changes from all commits
ee65b1f
119b15c
5c17c73
63d4882
702d7f8
def5481
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
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 |
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 spam 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 | ||
RequestForComment.find_by!(file: reported_content.file) | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :reported_content | ||
|
||
def lti_parameters = LtiParameter.find_by(study_group:, exercise:)&.lti_parameters || {} | ||
|
||
def study_group | ||
reported_content.submission.study_group | ||
end | ||
|
||
def exercise | ||
related_request_for_comment.exercise | ||
end | ||
end |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
json.username comment.user.displayname | ||
json.date comment.created_at.strftime('%d.%m.%Y %k:%M') | ||
json.updated(comment.created_at != comment.updated_at) | ||
json.editable policy(comment).edit? | ||
json.reportable policy(comment).report? | ||
json.url comment_url(comment, format: :json) | ||
end |
This file was deleted.
This file was deleted.
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'}) |
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) |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ de: | |
other: Kommentare | ||
comments: | ||
deleted: Gelöscht | ||
reported: Kommentar ist gemeldet. | ||
save_update: Speichern |
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: 'Spam Report: Ein %{human_model_name} in CodeOcean wurde als unangemessen markiert.' | ||
take_action: Bitte ergreifen Sie gegebenenfalls Maßnahmen. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ en: | |
other: Comments | ||
comments: | ||
deleted: Deleted | ||
reported: Comment is reported. | ||
save_update: Save |
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: 'Spam Report: A %{human_model_name} on CodeOcean has been marked as inappropriate.' | ||
take_action: Please take action if required. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class ReportMailerPreview < ActionMailer::Preview | ||
class UserContentReportMailerPreview < ActionMailer::Preview | ||
def report | ||
rfc = FactoryBot.build_stubbed(:rfc) | ||
|
||
ReportMailer.with(reported_content: rfc).report_content | ||
UserContentReportMailer.with(reported_content: rfc).report_content | ||
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.
Through unrelated changes in the locals, i18_task asked me to adjust the path. The message localization is unchanged.