Skip to content

Commit

Permalink
Add notification mails for teacher change by voucher redemption
Browse files Browse the repository at this point in the history
  • Loading branch information
fosterfarrell9 committed Aug 17, 2024
1 parent 09f47c2 commit 2205752
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 3 deletions.
14 changes: 14 additions & 0 deletions app/controllers/concerns/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 6 additions & 3 deletions app/controllers/vouchers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
23 changes: 23 additions & 0 deletions app/mailers/notification_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 7 additions & 0 deletions app/views/notification_mailer/new_teacher_email.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<%= t('mailer.new_teacher', title: @lecture.title_with_teacher, username: @username) %>
<br>
<p class="pt-2">
<%= link_to(t('notifications.edit_lecture'),
edit_lecture_url(@lecture),
class: 'btn btn-primary') %>
</p>
1 change: 1 addition & 0 deletions app/views/notification_mailer/new_teacher_email.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= t('mailer.new_teacher', title: @lecture.title_with_teacher, username: @username) %>
10 changes: 10 additions & 0 deletions app/views/notification_mailer/previous_teacher_email.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<%= t('mailer.previous_teacher',
title: @lecture.title_with_teacher,
username: @username,
new_teacher: @lecture.teacher.info) %>
<br>
<p class="pt-2">
<%= link_to(t('notifications.edit_lecture'),
edit_lecture_url(@lecture),
class: 'btn btn-primary') %>
</p>
4 changes: 4 additions & 0 deletions app/views/notification_mailer/previous_teacher_email.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%= t('mailer.previous_teacher',
title: @lecture.title_with_teacher,
username: @username,
new_teacher: @lecture.teacher.info) %>
8 changes: 8 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: >
Expand Down
8 changes: 8 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down

0 comments on commit 2205752

Please sign in to comment.