From 351f553c60fd9d5a48d1b80305c66156943f254b Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Sun, 10 Dec 2017 18:36:24 +0100 Subject: [PATCH] Send email to user associated with exercise collection when anomalies are detected --- app/mailers/user_mailer.rb | 7 +++++ .../exercise_anomaly_detected.html.slim | 13 +++++++++ config/locales/de.yml | 29 +++++++++++++++++++ config/locales/en.yml | 29 +++++++++++++++++++ lib/tasks/detect_exercise_anomalies.rake | 3 +- 5 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 app/views/user_mailer/exercise_anomaly_detected.html.slim diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 8022ee84..2df10be5 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -37,4 +37,11 @@ class UserMailer < ActionMailer::Base @rfc_link = request_for_comment_url(request_for_comments) mail(subject: t('mailers.user_mailer.send_thank_you_note.subject', author: @author), to: receiver.email) end + + def exercise_anomaly_detected(exercise_collection, anomalies) + @receiver_displayname = exercise_collection.user.displayname + @collection = exercise_collection + @anomalies = anomalies + mail(subject: t('mailers.user_mailer.exercise_anomaly_detected.subject', to: exercise_collection.user.email)) + end end diff --git a/app/views/user_mailer/exercise_anomaly_detected.html.slim b/app/views/user_mailer/exercise_anomaly_detected.html.slim new file mode 100644 index 00000000..8c008287 --- /dev/null +++ b/app/views/user_mailer/exercise_anomaly_detected.html.slim @@ -0,0 +1,13 @@ +== t('mailers.user_mailer.exercise_anomaly_detected.body1', + receiver_displayname: @receiver_displayname, + collection_name: @collection.name) + +- @anomalies.keys.each do | key | + =key + =@anomalies[key] + +== t('mailers.user_mailer.exercise_anomaly_detected.body2', + receiver_displayname: @receiver_displayname, + collection_name: @collection.name) + +== t('mailers.user_mailer.exercise_anomaly_detected.body3') diff --git a/config/locales/de.yml b/config/locales/de.yml index a7a2b436..73544027 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -515,6 +515,35 @@ de:
This mail was automatically sent by CodeOcean.
subject: "%{author_displayname} hat einen neuen Kommentar in einer Diskussion veröffentlicht, die Sie abonniert haben." + exercise_anomaly_detected: + subject: "Unregelmäßigkeiten in Aufgaben Ihrer Aufgabensammlung" + body1: | + English version below
+ _________________________
+
+ Hallo %{receiver_displayname},
+
+ eine oder mehrere Aufgaben Ihrer Aufgabensammlung "%{collection_name}" zeigen Unregelmäßigkeiten in der Bearbeitungszeit. Möglicherweise sind sie zu schwer oder zu leicht. +
+ Die Aufgaben sind: + body2: | +
+ Falls Sie beim Klick auf einen Link eine Fehlermeldung erhalten, dass Sie nicht berechtigt wären diese Aktion auszuführen, öffnen Sie bitte eine beliebige Programmieraufgabe aus einem Kurs heraus und klicken den Link danach noch einmal.
+
+ Diese Mail wurde automatisch von CodeOcean verschickt.
+
+ _________________________
+
+ Dear %{receiver_displayname},
+
+ at least one exercise in your exercise collection "%{collection_name}" has a much longer or much shorter average working time than the average. Perhaps they are too difficult or too easy. +
+ The exercises are: + body3: | +
+ If you receive an error that you are not authorized to perform this action when clicking a link, please log-in through any course exercise beforehand and click the link again.
+
+ This mail was automatically sent by CodeOcean.
request_for_comments: click_here: Zum Kommentieren auf die Seitenleiste klicken! comments: Kommentare diff --git a/config/locales/en.yml b/config/locales/en.yml index 7eba1527..410e6759 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -515,6 +515,35 @@ en:
This mail was automatically sent by CodeOcean.
subject: "%{author_displayname} has posted a new comment to a discussion you subscribed to on CodeOcean." + exercise_anomaly_detected: + subject: "Anomalies in exercises of your exercise collection" + body1: | + English version below
+ _________________________
+
+ Hallo %{receiver_displayname},
+
+ eine oder mehrere Aufgaben Ihrer Aufgabensammlung "%{collection_name}" zeigen Unregelmäßigkeiten in der Bearbeitungszeit. Möglicherweise sind sie zu schwer oder zu leicht. +
+ Die Aufgaben sind: + body2: | +
+ Falls Sie beim Klick auf einen Link eine Fehlermeldung erhalten, dass Sie nicht berechtigt wären diese Aktion auszuführen, öffnen Sie bitte eine beliebige Programmieraufgabe aus einem Kurs heraus und klicken den Link danach noch einmal.
+
+ Diese Mail wurde automatisch von CodeOcean verschickt.
+
+ _________________________
+
+ Dear %{receiver_displayname},
+
+ at least one exercise in your exercise collection "%{collection_name}" has a much longer or much shorter average working time than the average. Perhaps they are too difficult or too easy. +
+ The exercises are: + body3: | +
+ If you receive an error that you are not authorized to perform this action when clicking a link, please log-in through any course exercise beforehand and click the link again.
+
+ This mail was automatically sent by CodeOcean.
request_for_comments: click_here: Click on this sidebar to comment! comments: Comments diff --git a/lib/tasks/detect_exercise_anomalies.rake b/lib/tasks/detect_exercise_anomalies.rake index 7cdf6480..e8b216cf 100644 --- a/lib/tasks/detect_exercise_anomalies.rake +++ b/lib/tasks/detect_exercise_anomalies.rake @@ -37,7 +37,8 @@ namespace :detect_exercise_anomalies do anomalies = working_times.select do |exercise_id, working_time| working_time > average * MAX_TIME_FACTOR or working_time < average * MIN_TIME_FACTOR end - puts anomalies + + UserMailer.exercise_anomaly_detected(collection, anomalies).deliver_now end end