Skip to content

Commit 111d5bb

Browse files
authored
feat: Report email with LIT authorization path (#3011)
To act on spam reports, the teacher needs to sign in through the course to authenticate in the study group. The LTI return URL is used to link back to the course. Co-authored-by: Sebastian Serth <[email protected] Relates to #2715
1 parent e4c67d7 commit 111d5bb

File tree

6 files changed

+25
-0
lines changed

6 files changed

+25
-0
lines changed

app/mailers/report_mailer.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ class ReportMailer < ApplicationMailer
55

66
def report_content
77
@reported_content = params.fetch(:reported_content)
8+
study_group = @reported_content.submission.study_group
9+
exercise = @reported_content.exercise
10+
11+
# NOTE: This implementation assumes the course URL is static and does not vary per user.
12+
# This is currently valid for a majority of use cases. However, in dynamic scenarios (such as
13+
# content trees in openHPI used in conjunction with A/B/n testing) this assumption may no longer hold true.
14+
@course_url = LtiParameter.find_by(study_group:, exercise:)&.lti_parameters&.[]('launch_presentation_return_url')
815

916
mail(subject: I18n.t('report_mailer.report_content.subject', content_name: @reported_content.model_name.human))
1017
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 @course_url.present?
6+
p = link_to(t('.authentication'), @course_url)

app/views/report_mailer/report_content.text.slim

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

config/locales/de/report.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
de:
33
report_mailer:
44
report_content:
5+
authentication: Kurs-URL für die LTI-Authentifizierung.
56
prolog: 'Die folgenden Inhalte wurden als unangemessen gemeldet:'
67
subject: 'Spam Report: Ein %{content_name} in CodeOcean wurde als unangemessen markiert.'
78
take_action: Bitte ergreifen Sie gegebenenfalls Maßnahmen.

config/locales/en/report.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
en:
33
report_mailer:
44
report_content:
5+
authentication: Course URL for LTI authentication.
56
prolog: 'The following content has been reported as inappropriate:'
67
subject: 'Spam Report: A %{content_name} on CodeOcean has been marked as inappropriate.'
78
take_action: Please take action if required.

spec/mailers/report_mailer_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@
2222
expect(mail.text_part.body).to include(question)
2323
expect(mail.html_part.body).to include(question)
2424
end
25+
26+
it 'includes the LTI retrun URL for course authentication' do
27+
create(:lti_parameter,
28+
exercise: reported_content.exercise,
29+
study_group: reported_content.submission.study_group)
30+
31+
expect(mail.text_part.body).to match(%r{https.+/courses/})
32+
expect(mail.html_part.body).to match(%r{https.+/courses/})
33+
end
2534
end
2635
end
2736
end

0 commit comments

Comments
 (0)