Skip to content

Commit e615a29

Browse files
committed
feat: Report email with LTI exercise path
To act on spam reports the teacher needs to sign in through the exercise path of the LTI consumer to authenticate as a teacher for the exercise.
1 parent dc156e4 commit e615a29

File tree

7 files changed

+19
-1
lines changed

7 files changed

+19
-1
lines changed

app/mailers/report_mailer.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# frozen_string_literal: true
22

33
class ReportMailer < ApplicationMailer
4-
default to: CodeOcean::Config.new(:code_ocean).read.dig(:content_moderation, :report_emails)
4+
SETTINGS = CodeOcean::Config.new(:code_ocean).read.fetch(:content_moderation, {})
5+
default to: SETTINGS[:report_emails]
56

67
def report_content
78
@reported_content = params.fetch(:reported_content)
9+
@exercise_url = "#{SETTINGS[:exercises_base_url]}/#{@reported_content.exercise.uuid}"
810

911
mail(subject: I18n.t('report_mailer.report_content.subject', content_name: @reported_content.model_name.human))
1012
end

app/views/report_mailer/report_content.html.slim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ h3 = t('.prolog')
22
blockquote style="white-space: pre-wrap;" = @reported_content.question
33
p = t('.take_action')
44
p = link_to(request_for_comment_url(@reported_content), request_for_comment_url(@reported_content))
5+
- if @exercise_url.present?
6+
p = link_to(t('.authentication'), @exercise_url)

app/views/report_mailer/report_content.text.slim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@
55
== t('.take_action')
66
== "\n\n"
77
== request_for_comment_url(@reported_content)
8+
== "\n\n"
9+
- if @exercise_url.present?
10+
== t('.authentication')
11+
== @exercise_url

config/code_ocean.yml.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ development:
6969
codeharbor:
7070
enabled: true
7171
content_moderation:
72+
exercises_base_url: 'https://example.com/exercises/'
7273
report_emails:
7374
7475

config/locales/de/report.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ de:
55
prolog: 'Die folgenden Inhalte wurden als unangemessen gemeldet:'
66
subject: 'Spam Report: Ein %{content_name} in CodeOcean wurde als unangemessen markiert.'
77
take_action: Bitte ergreifen Sie gegebenenfalls Maßnahmen.
8+
authentication: Übungs-URL für die LTI-Authentifizierung.

config/locales/en/report.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ en:
55
prolog: 'The following content has been reported as inappropriate:'
66
subject: 'Spam Report: A %{content_name} on CodeOcean has been marked as inappropriate.'
77
take_action: Please take action if required.
8+
authentication: Exercise URL for LTI authentication.

spec/mailers/report_mailer_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
subject(:mail) { described_class.with(reported_content:).report_content }
88

99
context 'when an RfC is reported' do
10+
let(:exercise) { reported_content.exercise }
1011
let(:question) { 'Inappropriate content for RfC.' }
1112
let(:reported_content) { create(:rfc, question:) }
1213

@@ -22,6 +23,12 @@
2223
expect(mail.text_part.body).to include(question)
2324
expect(mail.html_part.body).to include(question)
2425
end
26+
27+
it 'includes the exersice url for the LTI consumer' do
28+
stub_const('ReportMailer::SETTINGS', {exercises_base_url: 'https://a.com/exersices/'})
29+
expect(mail.text_part.body).to include("https://a.com/exersices/#{exercise.uuid}")
30+
expect(mail.html_part.body).to include("https://a.com/exersices/#{exercise.uuid}")
31+
end
2532
end
2633
end
2734
end

0 commit comments

Comments
 (0)