Skip to content

Commit f17d4bb

Browse files
committed
Allow reporting of malicious content
RfCs and Comments on 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 allow users to report this malicious content. The UI for the RfC comment are part of a separate change. Relates to #2715
1 parent 72195f1 commit f17d4bb

File tree

20 files changed

+238
-12
lines changed

20 files changed

+238
-12
lines changed

Gemfile.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ GEM
140140
bigdecimal
141141
rexml
142142
crass (1.0.6)
143-
csv (3.3.4)
143+
csv (3.3.5)
144144
dachsfisch (1.0.2)
145145
nokogiri (>= 1.14.1, < 2.0.0)
146146
date (3.4.1)
@@ -234,7 +234,7 @@ GEM
234234
js-routes (2.3.5)
235235
railties (>= 5)
236236
sorbet-runtime
237-
json (2.12.0)
237+
json (2.12.2)
238238
json_schemer (2.4.0)
239239
bigdecimal
240240
hana (~> 1.3)
@@ -299,8 +299,8 @@ GEM
299299
nested_form (0.3.2)
300300
net-http (0.6.0)
301301
uri
302-
net-http-persistent (4.0.5)
303-
connection_pool (~> 2.2)
302+
net-http-persistent (4.0.6)
303+
connection_pool (~> 2.2, >= 2.2.4)
304304
net-imap (0.5.8)
305305
date
306306
net-protocol
@@ -472,7 +472,7 @@ GEM
472472
rspec-mocks (~> 3.13)
473473
rspec-support (~> 3.13)
474474
rspec-support (3.13.3)
475-
rubocop (1.75.7)
475+
rubocop (1.75.8)
476476
json (~> 2.3)
477477
language_server-protocol (~> 3.17.0.2)
478478
lint_roller (~> 1.1.0)
@@ -795,7 +795,7 @@ CHECKSUMS
795795
cose (1.3.1) sha256=d5d4dbcd6b035d513edc4e1ab9bc10e9ce13b4011c96e3d1b8fe5e6413fd6de5
796796
crack (1.0.0) sha256=c83aefdb428cdc7b66c7f287e488c796f055c0839e6e545fec2c7047743c4a49
797797
crass (1.0.6) sha256=dc516022a56e7b3b156099abc81b6d2b08ea1ed12676ac7a5657617f012bd45d
798-
csv (3.3.4) sha256=e96ecd5a8c3494aa5b596282249daba5c6033203c199248e6146e36d2a78d8cd
798+
csv (3.3.5) sha256=6e5134ac3383ef728b7f02725d9872934f523cb40b961479f69cf3afa6c8e73f
799799
dachsfisch (1.0.2) sha256=d8002414310cc8dc5d87d61d04d660f59f4cd095981ba20f09439c5e5b8d3c13
800800
date (3.4.1) sha256=bf268e14ef7158009bfeaec40b5fa3c7271906e88b196d958a89d4b408abe64f
801801
debug_inspector (1.2.0) sha256=9bdfa02eebc3da163833e6a89b154084232f5766087e59573b70521c77ea68a2
@@ -844,7 +844,7 @@ CHECKSUMS
844844
irb (1.15.2) sha256=222f32952e278da34b58ffe45e8634bf4afc2dc7aa9da23fed67e581aa50fdba
845845
jbuilder (2.13.0) sha256=7200a38a1c0081aa81b7a9757e7a299db75bc58cf1fd45ca7919a91627d227d6
846846
js-routes (2.3.5) sha256=8279fd3be49916309dfeaee546d659b97986e3edbb47332902e688992b143a4d
847-
json (2.12.0) sha256=b30fce000756de94c756679c7e57ed41f03f8cc8dde2d2dc00a7c44005da0a50
847+
json (2.12.2) sha256=ba94a48ad265605c8fa9a50a5892f3ba6a02661aa010f638211f3cb36f44abf4
848848
json_schemer (2.4.0) sha256=56cb6117bb5748d925b33ad3f415b513d41d25d0bbf57fe63c0a78ff05597c24
849849
jwt (2.10.1) sha256=e6424ae1d813f63e761a04d6284e10e7ec531d6f701917fadcd0d9b2deaf1cc5
850850
kaminari (1.2.2) sha256=c4076ff9adccc6109408333f87b5c4abbda5e39dc464bd4c66d06d9f73442a3e
@@ -874,7 +874,7 @@ CHECKSUMS
874874
multi_xml (0.7.2) sha256=307a96dc48613badb7b2fc174fd4e62d7c7b619bc36ea33bfd0c49f64f5787ce
875875
nested_form (0.3.2) sha256=b1c468d7eac781235861c2f74fc9f675df0c4d915d5724aaf7fd29f7891c0538
876876
net-http (0.6.0) sha256=9621b20c137898af9d890556848c93603716cab516dc2c89b01a38b894e259fb
877-
net-http-persistent (4.0.5) sha256=6e42880b347e650ffeaf679ae59c9d5a6ed8a22cda6e1b959d9c270050aefa8e
877+
net-http-persistent (4.0.6) sha256=2abb3a04438edf6cb9e0e7e505969605f709eda3e3c5211beadd621a2c84dd5d
878878
net-imap (0.5.8) sha256=52aa5fdfc1a8a3df1f793b20a327e95b5a9dfe1d733e1f0d53075d2dbcfcf593
879879
net-pop (0.1.2) sha256=848b4e982013c15b2f0382792268763b748cce91c9e91e36b0f27ed26420dff3
880880
net-protocol (0.2.2) sha256=aa73e0cba6a125369de9837b8d8ef82a61849360eba0521900e2c3713aa162a8
@@ -941,7 +941,7 @@ CHECKSUMS
941941
rspec-mocks (3.13.4) sha256=6bb158a0719c53d522104ed34c0777b884b2c9dc775ce64eaa10207df02ab993
942942
rspec-rails (8.0.0) sha256=977a508cd94d152db2068c6585470db5d0cd47eef56d5410b9531034fb9d97bf
943943
rspec-support (3.13.3) sha256=2a61e393f6e18b7228726e0c6869c5d5a1419d37206116c4d917d145276b3f43
944-
rubocop (1.75.7) sha256=23566ebb25263f26020687f8abb8aec049f3e29b6a00bdf0aa9d1db16b558be9
944+
rubocop (1.75.8) sha256=c80ab4286c5dcfc49d7ad1787cdba5569b63b58c96ee7afde4ec47a9c8a85be9
945945
rubocop-ast (1.44.1) sha256=e3cc04203b2ef04f6d6cf5f85fe6d643f442b18cc3b23e3ada0ce5b6521b8e92
946946
rubocop-capybara (2.22.1) sha256=ced88caef23efea53f46e098ff352f8fc1068c649606ca75cb74650970f51c0c
947947
rubocop-factory_bot (2.27.1) sha256=9d744b5916778c1848e5fe6777cc69855bd96548853554ec239ba9961b8573fe
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
class ReportsController < ApplicationController
4+
def create
5+
authorize(reported_content, policy_class: ReportPolicy)
6+
ReportMailer.with(reported_content:).report_content.deliver_later
7+
redirect_back(fallback_location: :root, notice: t('reports.reported'))
8+
end
9+
10+
private
11+
12+
def reported_content
13+
@reported_content ||= GlobalID::Locator.locate(params.require(:global_content_id))
14+
end
15+
end

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: "Spam Report: A #{@reported_content.class.name} on CodeOcean has been marked as inappropriate.")
10+
end
11+
end

app/policies/report_policy.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
class ReportPolicy < ApplicationPolicy
4+
def show?
5+
reciever_awalible? && @user
6+
end
7+
8+
def create?
9+
reciever_awalible? && @user && [RequestForComment, Comment].include?(@record.class)
10+
end
11+
12+
private
13+
14+
def reciever_awalible?
15+
ReportMailer.default_params.fetch(:to).present?
16+
end
17+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
The following content has been reported as inappropriate:
2+
3+
<% case @reported_content %>
4+
<% when Comment %>
5+
<%= @reported_content.text %>
6+
<% when RequestForComment %>
7+
<%= @reported_content.question %>
8+
<% else %>
9+
<% raise("Unexpected reported content: #{@reported_content.class.name}") %>
10+
<% end %>
11+
12+
Please take action on the admin page if required.
13+
<%= rails_admin.show_url(
14+
model_name: @reported_content.class.name.underscore,
15+
id: @reported_content.id) %>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- if policy(:report).show?
2+
= button_to t('reports.report'), reports_path,
3+
params: {global_content_id: reported_content.to_global_id},
4+
data: {confirm: t('reports.confirm')},
5+
class: 'btn btn-light btn-sm'

app/views/request_for_comments/show.html.slim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
.text
2929
- question = @request_for_comment.question
3030
= question.presence || t('request_for_comments.no_question')
31+
.text-end
32+
= render('reports/button', reported_content: @request_for_comment)
3133

3234
- if policy(@request_for_comment).mark_as_solved? && !@request_for_comment.solved?
3335
= render('mark_as_solved')

config/code_ocean.yml.ci

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ test:
1414
ca_file: /example/certificates/ca.crt
1515
token: SECRET
1616
unused_runner_expiration_time: 180
17+
content_moderation:
18+
report_emails:
19+

config/code_ocean.yml.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ 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+
# Email address to receive reports about inappropriate content.
60+
report_emails:
61+
5862

5963
development:
6064
<<: *default

config/locales/de/report.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
de:
3+
reports:
4+
confirm: Möchten Sie diesen Inhalt melden?
5+
report: melden
6+
reported: Vielen Dank, dass Sie uns auf dieses Problem aufmerksam gemacht haben. Wir werden uns in Kürze darum kümmern.

0 commit comments

Comments
 (0)