Skip to content

Commit f32a3e7

Browse files
committed
Review corrections
1 parent 6e416f5 commit f32a3e7

File tree

11 files changed

+56
-23
lines changed

11 files changed

+56
-23
lines changed

app/mailers/report_mailer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ class ReportMailer < ApplicationMailer
66
def report_content
77
@reported_content = params.fetch(:reported_content)
88

9-
mail(subject: "Spam Report: A #{@reported_content.class.name} on CodeOcean has been marked as inappropriate.")
9+
mail(subject: I18n.t('report_mailer.report_content.subject', content_name: @reported_content.model_name.human))
1010
end
1111
end

app/policies/report_policy.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,24 @@
22

33
class ReportPolicy < ApplicationPolicy
44
def show?
5-
reciever_awalible? && @user
5+
receiver_available? && reportable_content? && reports_other_user?
66
end
77

88
def create?
9-
reciever_awalible? && @user && [RequestForComment, Comment].include?(@record.class)
9+
receiver_available? && reportable_content? && reports_other_user?
1010
end
1111

1212
private
1313

14-
def reciever_awalible?
14+
def reportable_content?
15+
[RequestForComment, Comment].include?(@record.class)
16+
end
17+
18+
def reports_other_user?
19+
@record.user != @user
20+
end
21+
22+
def receiver_available?
1523
ReportMailer.default_params.fetch(:to).present?
1624
end
1725
end

app/views/report_mailer/report_content.text.erb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
The following content has been reported as inappropriate:
1+
<%= t('.prolog') %>
22

33
<% case @reported_content %>
44
<% when Comment %>
55
<%= @reported_content.text %>
6+
7+
<%= t('.take_action') %>
8+
9+
<%= rails_admin.show_url(
10+
model_name: 'comment',
11+
id: @reported_content.id) %>
612
<% when RequestForComment %>
713
<%= @reported_content.question %>
14+
15+
<%= t('.take_action') %>
16+
17+
<%= request_for_comment_url(@reported_content) %>
818
<% else %>
919
<% raise("Unexpected reported content: #{@reported_content.class.name}") %>
1020
<% end %>
1121

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) %>

app/views/reports/_button.html.slim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
- if policy(:report).show?
1+
- if policy(:report, reported_content).show?
22
= button_to t('reports.report'), reports_path,
33
params: {global_content_id: reported_content.to_global_id},
44
data: {confirm: t('reports.confirm')},

config/locales/de/report.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ de:
44
confirm: Möchten Sie diesen Inhalt melden?
55
report: melden
66
reported: Vielen Dank, dass Sie uns auf dieses Problem aufmerksam gemacht haben. Wir werden uns in Kürze darum kümmern.
7+
report_mailer:
8+
report_content:
9+
subject: "Spam Report: A %{content_name} on CodeOcean has been marked as inappropriate."
10+
prolog: "Die folgenden Inhalte wurden als unangemessen gemeldet:"
11+
take_action: Bitte ergreifen Sie gegebenenfalls Maßnahmen.

config/locales/en/report.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ en:
44
confirm: Do you want to report this content?
55
report: report
66
reported: Thank you for letting us know about this issue. We look into the matter shorty.
7+
report_mailer:
8+
report_content:
9+
subject: "Spam Report: A %{content_name} on CodeOcean has been marked as inappropriate."
10+
prolog: "The following content has been reported as inappropriate:"
11+
take_action: Please take action if required.

config/routes.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@
150150

151151
match '/forgot_password', as: 'forgot_password', to: 'internal_users#forgot_password', via: %i[get post]
152152

153+
resources :reports, only: :create
154+
153155
resources :sessions, only: %i[create destroy new]
154156
resources :webauthn_credential_authentication, only: %i[new create]
155157

@@ -196,8 +198,6 @@
196198
get 'service-worker', to: 'rails/pwa#service_worker', as: :pwa_service_worker, defaults: {format: :js}
197199
get 'manifest(.:file_extension)', to: 'rails/pwa#manifest', as: :pwa_manifest, defaults: {format: :webmanifest}, format: false, constraints: {file_extension: %w[json webmanifest]}
198200

199-
resources :reports, only: :create
200-
201201
# Defines the root path route ("/")
202202
root to: 'application#welcome'
203203
end

docs/LOCAL_SETUP.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,6 @@ do
158158
cp config/$f.example config/$f
159159
fi
160160
done
161-
162-
sed -i.bak 's/^# - [email protected]/- [email protected]/' config/code_ocean.yml
163-
rm config/code_ocean.yml.bak
164161
```
165162

166163
Then, you should check all config files manually and adjust settings where necessary for your environment.

spec/mailers/report_mailer_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
let(:reported_content) { create(:rfc, question: 'Inappropriate content for RfC.') }
1313

1414
it 'sets the correct subject' do
15-
expect(mail.subject).to eq('Spam Report: A RequestForComment on CodeOcean has been marked as inappropriate.')
15+
expect(mail.subject).to eq(I18n.t('report_mailer.report_content.subject', content_name: RequestForComment.model_name.human ))
1616
end
1717

1818
it 'includes the reported content' do
@@ -25,7 +25,7 @@
2525
end
2626

2727
it 'sets the correct subject' do
28-
expect(mail.subject).to eq('Spam Report: A Comment on CodeOcean has been marked as inappropriate.')
28+
expect(mail.subject).to eq(I18n.t('report_mailer.report_content.subject', content_name: Comment.model_name.human ))
2929
end
3030

3131
it 'sets the correct receiver' do

spec/policies/report_policy_spec.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919

2020
expect(policy).not_to permit(user, Comment.new)
2121
end
22+
23+
it 'dose not allow reports of your own content' do
24+
user = build_stubbed(:external_user)
25+
26+
expect(policy).not_to permit(user, Comment.new(user: user))
27+
end
2228
end
2329

2430
permissions(:create?) do
@@ -28,6 +34,14 @@
2834
end
2935
end
3036

37+
it 'allows reports on RfCs and Comments' do
38+
user = build_stubbed(:external_user)
39+
40+
expect(policy).to permit(user, Comment.new)
41+
expect(policy).to permit(user, RequestForComment.new)
42+
expect(policy).not_to permit(user, ExternalUser.new)
43+
end
44+
3145
it 'dose not allow reports when no report email is configured' do
3246
user = build_stubbed(:external_user)
3347

@@ -36,12 +50,10 @@
3650
expect(policy).not_to permit(user, Comment.new)
3751
end
3852

39-
it 'allows reports on RfCs and Comments' do
53+
it 'dose not allow reports of your own content' do
4054
user = build_stubbed(:external_user)
4155

42-
expect(policy).to permit(user, Comment.new)
43-
expect(policy).to permit(user, RequestForComment.new)
44-
expect(policy).not_to permit(user, ExternalUser.new)
56+
expect(policy).not_to permit(user, Comment.new(user: user))
4557
end
4658
end
4759
end

0 commit comments

Comments
 (0)