Skip to content

Commit

Permalink
Take first steps in setting up redemption of teacher vouchers
Browse files Browse the repository at this point in the history
  • Loading branch information
fosterfarrell9 committed Aug 17, 2024
1 parent 0e728d4 commit 102bcc2
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
9 changes: 9 additions & 0 deletions app/controllers/vouchers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def process_voucher(voucher, lecture)
process_tutor_voucher(voucher, lecture)
elsif voucher.editor?
process_editor_voucher(voucher, lecture)
elsif voucher.teacher?
process_teacher_voucher(voucher, lecture)
end
end

Expand All @@ -108,6 +110,13 @@ def process_editor_voucher(voucher, lecture)
Redemption.create(user: current_user, voucher: voucher)
end

def process_teacher_voucher(voucher, lecture)
lecture.update_teacher_status!(current_user)
# notify_new_teacher_by_mail(current_user, lecture)
# notify_previous_teacher_by_mail(lecture)
Redemption.create(user: current_user, voucher: voucher)
end

def success_message(voucher)
if voucher.tutor?
I18n.t("controllers.become_tutor_success")
Expand Down
10 changes: 10 additions & 0 deletions app/models/lecture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,16 @@ def update_editor_status!(user)
touch
end

def update_teacher_status!(user)
return if teacher == user

previous_teacher = teacher
self.teacher = user
editors << previous_teacher
# touch to invalidate the cache
touch
end

def voucher_redeemers(voucher_scope)
User.where(id: Redemption.where(voucher: voucher_scope).select(:user_id))
end
Expand Down
9 changes: 9 additions & 0 deletions app/views/vouchers/_redeem_teacher_voucher.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%= t('profile.become_teacher', lecture: voucher.lecture.title) %>

<% if current_user == voucher.lecture.teacher %>
<%= t('profile.already_teacher') %>
<% else %>
<%= redeem_voucher_button(voucher) %>
<% end %>

<%= cancel_voucher_button %>
17 changes: 13 additions & 4 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2195,9 +2195,10 @@ de:
redeem_voucher: Gutschein einlösen
become_tutor: >
Mit diesem Gutschein erhältst Du TutorInnenstatus in der Veranstaltung
%{lecture}. Dadurch können Dir VeranstaltungseditorInnen Tutorien zuweisen.
Ggf. kannst Du an dieser Stelle bereits Tutorien auswählen,
die Du übernehmen möchtest.
%{lecture}. Dadurch können Dir VeranstaltungseditorInnen und die DozentIn
Tutorien zuweisen. Ggf. kannst Du an dieser Stelle bereits Tutorien
auswählen, die Du übernehmen möchtest. Die VeranstaltungseditorInnen
und die DozentIn werden benachrichtigt, wenn Du den Gutschein einlöst.
already_tutor: >
Du bist bereits als TutorIn eingetragen für: %{tutorials}.
new_tutor_select: >
Expand All @@ -2217,10 +2218,18 @@ de:
%{lecture}.
already_editor_by_redemption: >
Du hast bereits einen Gutschein eingelöst, um EditorInnenstatus zu
erhalten.
erhalten. Die anderen VeranstaltungseditorInnen und die DozentIn werden
benachrichtigt, wenn Du den Gutschein einlöst.
teacher_cant_become_editor: >
Du kannst nicht zusätzlich EditorInnenstatus in einer Veranstaltung
erhalten, in der Du bereits DozentIn bist.
become_teacher: >
Mit diesem Gutschein erhältst Du DozentInnenstatus für die Veranstaltung
%{lecture}. Die bisherige DozentIn erhält EditorInnenstatus.
Die VeranstaltungseditorInnen werden benachrichtigt,
wenn Du den Gutschein einlöst.
already_teacher: >
Du bist bereits DozentIn in dieser Veranstaltung.
mampf_news:
title: 'MaMpf-News'
check_notifications: 'Alle erledigen'
Expand Down
11 changes: 10 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2067,7 +2067,8 @@ en:
With this voucher, you can obtain tutor status for %{lecture}.
With that, editors for the event series can assign you tutorials.
If applicable, you can select the tutorials you will be responsible for
right here.
right here. The editors and the teacher will be notified when you have
redeemed the voucher.
already_tutor: >
You are already registered as a tutor for: %{tutorials}.
new_tutor_select: >
Expand All @@ -2086,11 +2087,19 @@ en:
You have already redeemed a tutor voucher for this event series.
become_editor: >
With this voucher, you can obtain editor status for %{lecture}.
The other editors and the teacher will be notified when you have
redeemed the voucher.
already_editor_by_redemption: >
You have already redeemed an editor voucher for this event series.
teacher_cant_become_editor: >
You are already a teacher for this event series. Therefore, you cannot
redeem an editor voucher.
become_teacher: >
With this voucher, you can obtain teacher status for %{lecture}.
The previous teacher will be demoted to editor. The editors will be
notified when you have redeemed the voucher.
already_teacher: >
You are already the teacher for this event series.
mampf_news:
title: 'MaMpf News'
check_notifications: 'Clear all'
Expand Down

0 comments on commit 102bcc2

Please sign in to comment.