From 2205752dad5829acf524da0eb095bc9d69535589 Mon Sep 17 00:00:00 2001
From: fosterfarrell9 <28628554+fosterfarrell9@users.noreply.github.com>
Date: Sat, 17 Aug 2024 19:23:55 +0200
Subject: [PATCH] Add notification mails for teacher change by voucher
redemption
---
app/controllers/concerns/notifier.rb | 14 +++++++++++
app/controllers/vouchers_controller.rb | 9 +++++---
app/mailers/notification_mailer.rb | 23 +++++++++++++++++++
.../new_teacher_email.html.erb | 7 ++++++
.../new_teacher_email.text.erb | 1 +
.../previous_teacher_email.html.erb | 10 ++++++++
.../previous_teacher_email.text.erb | 4 ++++
config/locales/de.yml | 8 +++++++
config/locales/en.yml | 8 +++++++
9 files changed, 81 insertions(+), 3 deletions(-)
create mode 100644 app/views/notification_mailer/new_teacher_email.html.erb
create mode 100644 app/views/notification_mailer/new_teacher_email.text.erb
create mode 100644 app/views/notification_mailer/previous_teacher_email.html.erb
create mode 100644 app/views/notification_mailer/previous_teacher_email.text.erb
diff --git a/app/controllers/concerns/notifier.rb b/app/controllers/concerns/notifier.rb
index 20f24fc16..0f8515646 100644
--- a/app/controllers/concerns/notifier.rb
+++ b/app/controllers/concerns/notifier.rb
@@ -7,4 +7,18 @@ def notify_new_editor_by_mail(editor, lecture)
lecture: lecture)
.new_editor_email.deliver_later
end
+
+ def notify_new_teacher_by_mail(teacher, lecture)
+ NotificationMailer.with(recipient: teacher,
+ locale: teacher.locale,
+ lecture: lecture)
+ .new_teacher_email.deliver_later
+ end
+
+ def notify_previous_teacher_by_mail(previous_teacher, lecture)
+ NotificationMailer.with(recipient: previous_teacher,
+ locale: previous_teacher.locale,
+ lecture: lecture)
+ .previous_teacher_email.deliver_later
+ end
end
diff --git a/app/controllers/vouchers_controller.rb b/app/controllers/vouchers_controller.rb
index 2867f3407..c443b3791 100644
--- a/app/controllers/vouchers_controller.rb
+++ b/app/controllers/vouchers_controller.rb
@@ -49,7 +49,7 @@ def redeem
if voucher
lecture = voucher.lecture
redemption = process_voucher(voucher, lecture)
- redemption.create_notifications!
+ redemption&.create_notifications!
redirect_to edit_profile_path, notice: success_message(voucher)
else
handle_invalid_voucher
@@ -111,9 +111,12 @@ def process_editor_voucher(voucher, lecture)
end
def process_teacher_voucher(voucher, lecture)
+ previous_teacher = lecture.teacher
lecture.update_teacher_status!(current_user)
- # notify_new_teacher_by_mail(current_user, lecture)
- # notify_previous_teacher_by_mail(lecture)
+ if previous_teacher != current_user
+ notify_new_teacher_by_mail(current_user, lecture)
+ notify_previous_teacher_by_mail(previous_teacher, lecture)
+ end
Redemption.create(user: current_user, voucher: voucher)
end
diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb
index ae6a281c1..cdf2a4dfc 100644
--- a/app/mailers/notification_mailer.rb
+++ b/app/mailers/notification_mailer.rb
@@ -62,6 +62,29 @@ def new_editor_email
title: @lecture.title_for_viewers))
end
+ def new_teacher_email
+ @lecture = params[:lecture]
+ @recipient = params[:recipient]
+ @username = @recipient.tutorial_name
+
+ mail(from: @sender,
+ to: @recipient.email,
+ subject: t("mailer.new_teacher_subject",
+ title: @lecture.title_for_viewers))
+ end
+
+ def previous_teacher_email
+ @lecture = params[:lecture]
+ @recipient = params[:recipient]
+ @username = @recipient.tutorial_name
+
+ mail(from: @sender,
+ to: @recipient.email,
+ subject: t("mailer.previous_teacher_subject",
+ title: @lecture.title_for_viewers,
+ new_teacher: @lecture.teacher.tutorial_name))
+ end
+
def submission_invitation_email
@recipient = params[:recipient]
@assignment = params[:assignment]
diff --git a/app/views/notification_mailer/new_teacher_email.html.erb b/app/views/notification_mailer/new_teacher_email.html.erb
new file mode 100644
index 000000000..effab3acf
--- /dev/null
+++ b/app/views/notification_mailer/new_teacher_email.html.erb
@@ -0,0 +1,7 @@
+<%= t('mailer.new_teacher', title: @lecture.title_with_teacher, username: @username) %>
+
+
+ <%= link_to(t('notifications.edit_lecture'), + edit_lecture_url(@lecture), + class: 'btn btn-primary') %> +
diff --git a/app/views/notification_mailer/new_teacher_email.text.erb b/app/views/notification_mailer/new_teacher_email.text.erb new file mode 100644 index 000000000..6236279c3 --- /dev/null +++ b/app/views/notification_mailer/new_teacher_email.text.erb @@ -0,0 +1 @@ +<%= t('mailer.new_teacher', title: @lecture.title_with_teacher, username: @username) %> diff --git a/app/views/notification_mailer/previous_teacher_email.html.erb b/app/views/notification_mailer/previous_teacher_email.html.erb new file mode 100644 index 000000000..620441f57 --- /dev/null +++ b/app/views/notification_mailer/previous_teacher_email.html.erb @@ -0,0 +1,10 @@ +<%= t('mailer.previous_teacher', + title: @lecture.title_with_teacher, + username: @username, + new_teacher: @lecture.teacher.info) %> ++ <%= link_to(t('notifications.edit_lecture'), + edit_lecture_url(@lecture), + class: 'btn btn-primary') %> +
diff --git a/app/views/notification_mailer/previous_teacher_email.text.erb b/app/views/notification_mailer/previous_teacher_email.text.erb new file mode 100644 index 000000000..e27b04ae1 --- /dev/null +++ b/app/views/notification_mailer/previous_teacher_email.text.erb @@ -0,0 +1,4 @@ +<%= t('mailer.previous_teacher', + title: @lecture.title_with_teacher, + username: @username, + new_teacher: @lecture.teacher.info) %> diff --git a/config/locales/de.yml b/config/locales/de.yml index 3113fbd12..516641574 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -3158,6 +3158,14 @@ de: text: 'Text' new_editor_subject: 'EditorInnenrechte für %{title}' new_editor: 'Hallo %{username}, Du hast soeben Bearbeitungsrechte für %{title} erhalten.' + new_teacher_subject: 'DozentInnenstatus für %{title}' + new_teacher: 'Hallo %{username}, Du hast soeben DozentInnenstatus für %{title} erhalten.' + previous_teacher_subject: 'DozentInnenwechsel in %{title}' + previous_teacher: > + Hallo %{username}, in der Veranstaltung %{title} gab es einen + DozentInnenwechsel. %{new_teacher} hat einen DozentInnengutschein eingelöst + und ist jetzt DozentIn. Du bist nicht mehr DozentIn in %{title}, sondern + stattdessen VeranstaltungseditorIn. new_lecture_subject: 'Neue Veranstaltung %{title}' new_lecture: 'Es wurde eine neue Veranstaltung angelegt: %{title}.' subscribe_lecture: > diff --git a/config/locales/en.yml b/config/locales/en.yml index 87ad8f02f..391fb46fa 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2969,6 +2969,14 @@ en: text: 'Text' new_editor_subject: 'Editing Rights for %{title}' new_editor: 'Dear %{username}, you have been given editing rights for %{title}.' + new_teacher_subject: 'Teacher Status for %{title}' + new_teacher: 'Dear %{username}, you have been given teacher status for %{title}.' + previous_teacher_subject: 'Teacher Change for %{title}' + previous_teacher: > + Dear %{username}, ther has been a teacher change for %{title}. + %{new_teacher} has redeemed a teacher voucher and is now the teacher for + this event series. You are no longer teacher for %{title}, but + editor instead. new_lecture_subject: 'New event series %{title}' new_lecture: 'A new event series has been made available: %{title}.' subscribe_lecture: 'You can subscribe to it in your profile settings.'