Skip to content

Commit 75b9297

Browse files
arkirchnernenockMrSerth
authored
RfCs: Allow reporting of inappropriate content (#2946)
RfCs are user-generated content that can be reviewed by other users. This feature can be misused. A simple email-based reporting mechanism has been added, to allow users to report malicious content. The UI for the RfC comment are part of a separate change. Relates to #2715 Co-authored-by: Nele Sina Noack <[email protected]> Co-authored-by: Sebastian Serth <[email protected]>
1 parent 6b637be commit 75b9297

21 files changed

+284
-4
lines changed

app/controllers/request_for_comments_controller.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class RequestForCommentsController < ApplicationController
44
include CommonBehavior
5-
before_action :set_request_for_comment, only: %i[show mark_as_solved set_thank_you_note clear_question]
5+
before_action :set_request_for_comment, only: %i[show mark_as_solved set_thank_you_note clear_question report]
66
before_action :set_study_group_grouping,
77
only: %i[index my_comment_requests rfcs_with_my_comments rfcs_for_exercise]
88

@@ -162,6 +162,15 @@ def create
162162
authorize!
163163
end
164164

165+
# POST /request_for_comments/1/report
166+
def report
167+
authorize!
168+
169+
ReportMailer.with(reported_content: @request_for_comment).report_content.deliver_later
170+
171+
redirect_to(@request_for_comment, notice: t('.report.reported'))
172+
end
173+
165174
private
166175

167176
# Use callbacks to share common setup or constraints between actions.

app/mailers/report_mailer.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
class ReportMailer < ApplicationMailer
4+
default to: CodeOcean::Config.new(:code_ocean).read.dig(:content_moderation, :report_emails)
5+
6+
def report_content
7+
@reported_content = params.fetch(:reported_content)
8+
9+
mail(subject: I18n.t('report_mailer.report_content.subject', content_name: @reported_content.model_name.human))
10+
end
11+
end

app/policies/request_for_comment_policy.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# frozen_string_literal: true
22

33
class RequestForCommentPolicy < ApplicationPolicy
4+
REPORT_RECEIVER_CONFIGURED = CodeOcean::Config.new(:code_ocean).read.dig(:content_moderation, :report_emails).present?
5+
46
def create?
57
everyone
68
end
@@ -41,6 +43,12 @@ def rfcs_with_my_comments?
4143
everyone
4244
end
4345

46+
def report?
47+
REPORT_RECEIVER_CONFIGURED && show? && !author?
48+
end
49+
50+
private
51+
4452
def rfc_visibility
4553
# The consumer with the most restricted visibility determines the visibility of the RfC
4654
case [@user.consumer.rfc_visibility, @record.author.consumer.rfc_visibility]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
h3 = t('.prolog')
2+
blockquote style="white-space: pre-wrap;" = @reported_content.question
3+
p = t('.take_action')
4+
p = link_to(request_for_comment_url(@reported_content), request_for_comment_url(@reported_content))
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
== t('.prolog')
2+
== "\n\n"
3+
== @reported_content.question.lines.map { "> #{it}" }.join
4+
== "\n\n"
5+
== t('.take_action')
6+
== "\n\n"
7+
== request_for_comment_url(@reported_content)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/# locals: (request_for_comment:)
2+
3+
- if policy(request_for_comment).report?
4+
= button_to t('.report'), report_request_for_comment_path(request_for_comment),
5+
data: {confirm: t('.confirm')},
6+
class: 'btn btn-light btn-sm',
7+
form: {class: 'd-inline float-end'}

app/views/request_for_comments/show.html.slim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
.question
2626
h5.mt-4
2727
= RequestForComment.human_attribute_name('question')
28+
= render('report', request_for_comment: @request_for_comment)
2829
.text
2930
- question = @request_for_comment.question
3031
= question.presence || t('request_for_comments.no_question')

config/code_ocean.yml.example

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,22 @@ default: &default
5555
# be truly greater than any permitted execution time of an execution environment.
5656
unused_runner_expiration_time: 180
5757

58+
content_moderation:
59+
# Learners can report inappropriate content, such as offensive RfCs or comments.
60+
# For each report, an email is sent to all addresses listed below. If no address is
61+
# configured, learners cannot report user-generated content.
62+
report_emails:
63+
5864

5965
development:
6066
<<: *default
6167
flowr:
6268
enabled: true
6369
codeharbor:
6470
enabled: true
71+
content_moderation:
72+
report_emails:
73+
6574

6675

6776
production:

config/locales/de/report.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
de:
3+
report_mailer:
4+
report_content:
5+
prolog: 'Die folgenden Inhalte wurden als unangemessen gemeldet:'
6+
subject: 'Spam Report: Ein %{content_name} in CodeOcean wurde als unangemessen markiert.'
7+
take_action: Bitte ergreifen Sie gegebenenfalls Maßnahmen.

config/locales/de/request_for_comment.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ de:
4242
no_output: Keine Ausgabe.
4343
no_question: Der/die Autor:in hat keine Frage zu dieser Anfrage gestellt.
4444
passed: Erfolgreich
45+
report:
46+
confirm: Möchten Sie diesen Inhalt melden?
47+
report: Melden
48+
reported: Vielen Dank, dass Sie uns auf dieses Problem aufmerksam gemacht haben. Wir werden uns in Kürze darum kümmern.
4549
runtime_output: Programmausgabe
4650
send_thank_you_note: Senden
4751
show_all: Alle Anfragen anzeigen

0 commit comments

Comments
 (0)