diff --git a/app/controllers/vouchers_controller.rb b/app/controllers/vouchers_controller.rb index 4f214eec1..2867f3407 100644 --- a/app/controllers/vouchers_controller.rb +++ b/app/controllers/vouchers_controller.rb @@ -122,6 +122,8 @@ def success_message(voucher) I18n.t("controllers.become_tutor_success") elsif voucher.editor? I18n.t("controllers.become_editor_success") + elsif voucher.teacher? + I18n.t("controllers.become_teacher_success") end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f267191e3..495f7a96e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -327,4 +327,10 @@ def get_class_for_any_path(paths) def get_class_for_any_path_startswith(paths) paths.any? { |path| request.path.starts_with?(path) } ? ACTIVE_CSS_CLASS : "" end + + def truncate_result(result, length = 40) + result.first(length).tap do |truncated| + return truncated.length < length ? truncated : "#{truncated}..." + end + end end diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index bb9654096..6efe5a44e 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -89,63 +89,4 @@ def items_card_size(small, comments_below) "70vh" end - - # create text for lecture announcement in notification card header - def redemption_notification_card_header(redemption) - link_to(redemption.lecture.title_for_viewers, - edit_lecture_path(redemption.lecture, anchor: "people"), - class: "text-dark") - end - - def redemption_notification_item_header(redemption) - t("notifications.redemption_in_lecture", - lecture: redemption.lecture.title_for_viewers) - end - - def redemption_notification_details(redemption) - if redemption.tutor? - tutor_notification_details(redemption) - else - editor_notification_details(redemption) - end - end - - def redemption_notification_item_details(redemption) - result = if redemption.tutor? - tutor_notification_item_details(redemption) - elsif redemption.editor? - editor_notification_item_details(redemption) - end - - truncate_result(result) - end - - private - - def tutor_notification_item_details(redemption) - tutorials = redemption.claimed_tutorials.map(&:title).join(", ") - "#{t("basics.tutor")} #{redemption.user.tutorial_name}: #{tutorials}" - end - - def editor_notification_item_details(redemption) - "#{t("basics.editor")} #{redemption.user.tutorial_name}" - end - - def tutor_notification_details(redemption) - details = I18n.t("notifications.became_tutor", - user: redemption.user.info) - tutorial_titles = redemption.claimed_tutorials.map(&:title).join(", ") - details << I18n.t("notifications.tutorial_details", - tutorials: tutorial_titles) - end - - def editor_notification_details(redemption) - I18n.t("notifications.became_editor", user: redemption.user.info) - end - - def truncate_result(result) - result.first(40).tap do |truncated| - return truncated.length < 40 ? truncated : "#{truncated}..." - end - end end diff --git a/app/helpers/redemptions_helper.rb b/app/helpers/redemptions_helper.rb new file mode 100644 index 000000000..f7a33abd4 --- /dev/null +++ b/app/helpers/redemptions_helper.rb @@ -0,0 +1,66 @@ +# Redemptions Helper +module RedemptionsHelper + def redemption_notification_card_header(redemption) + link_to(redemption.lecture.title_for_viewers, + edit_lecture_path(redemption.lecture, anchor: "people"), + class: "text-dark") + end + + def redemption_notification_item_header(redemption) + t("notifications.redemption_in_lecture", + lecture: redemption.lecture.title_for_viewers) + end + + def redemption_notification_details(redemption) + if redemption.tutor? + tutor_notification_details(redemption) + elsif redemption.editor? + editor_notification_details(redemption) + elsif redemption.teacher? + teacher_notification_details(redemption) + end + end + + def redemption_notification_item_details(redemption) + result = if redemption.tutor? + tutor_notification_item_details(redemption) + elsif redemption.editor? + editor_notification_item_details(redemption) + elsif redemption.teacher? + teacher_notification_item_details(redemption) + end + + truncate_result(result) + end + + private + + def tutor_notification_item_details(redemption) + tutorials = redemption.claimed_tutorials.map(&:title).join(", ") + "#{t("basics.tutor")} #{redemption.user.tutorial_name}: #{tutorials}" + end + + def editor_notification_item_details(redemption) + "#{t("basics.editor")} #{redemption.user.tutorial_name}" + end + + def teacher_notification_item_details(redemption) + "#{t("basics.teacher")} #{redemption.user.tutorial_name}" + end + + def tutor_notification_details(redemption) + details = I18n.t("notifications.became_tutor", + user: redemption.user.info) + tutorial_titles = redemption.claimed_tutorials.map(&:title).join(", ") + details << I18n.t("notifications.tutorial_details", + tutorials: tutorial_titles) + end + + def editor_notification_details(redemption) + I18n.t("notifications.became_editor", user: redemption.user.info) + end + + def teacher_notification_details(redemption) + I18n.t("notifications.became_teacher", user: redemption.user.info) + end +end diff --git a/app/models/lecture.rb b/app/models/lecture.rb index 9550c61b3..c3f070bf8 100644 --- a/app/models/lecture.rb +++ b/app/models/lecture.rb @@ -876,7 +876,7 @@ def update_teacher_status!(user) return if teacher == user previous_teacher = teacher - self.teacher = user + update(teacher: user) editors << previous_teacher # touch to invalidate the cache touch diff --git a/app/models/redemption.rb b/app/models/redemption.rb index 093c3bfe8..c23079397 100644 --- a/app/models/redemption.rb +++ b/app/models/redemption.rb @@ -12,6 +12,7 @@ class Redemption < ApplicationRecord delegate :sort, to: :voucher delegate :tutor?, to: :voucher delegate :editor?, to: :voucher + delegate :teacher?, to: :voucher def create_notifications! lecture.editors_and_teacher.each do |editor| diff --git a/app/views/vouchers/_redeem_teacher_voucher.html.erb b/app/views/vouchers/_redeem_teacher_voucher.html.erb index 759d659d7..656eb12b9 100644 --- a/app/views/vouchers/_redeem_teacher_voucher.html.erb +++ b/app/views/vouchers/_redeem_teacher_voucher.html.erb @@ -1,4 +1,6 @@ -<%= t('profile.become_teacher', lecture: voucher.lecture.title) %> +
+ <%= t('profile.become_teacher', lecture: voucher.lecture.title) %> +
<% if current_user == voucher.lecture.teacher %> <%= t('profile.already_teacher') %> diff --git a/config/locales/de.yml b/config/locales/de.yml index 0277479e8..3113fbd12 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -731,10 +731,15 @@ de: section_needed: Bitte erstelle zuerst einen Abschnitt voucher_for_tutor: > Gutscheine für TutorInnen können von NutzerInnen eingelöst werden, um - TutorIn für diese Veranstaltung zu werden. + TutorInnenstatus für diese Veranstaltung zu erhalten und ggf. direkt + Tutorien zu übernehmen. voucher_for_editor: > Gutscheine für EditorInnen können von NutzerInnen eingelöst werden, um - EditorIn für diese Veranstaltung zu werden. + EditorInnenstatus für diese Veranstaltung zu ehalten. + voucher_for_teacher: > + Gutscheine für DozentInnen können von NutzerInnen eingelöst werden, um + DozentInnenstatus für diese Veranstaltung zu erhalten. Die bisherige + DozentIn wird dann EditorIn. show_media: 'Medien einblenden' workflow: 'Workflow' content_mode: 'Inhaltsermittlung' @@ -2271,6 +2276,9 @@ de: became_editor: > %{user} hat einen EditorInnen-Gutschein eingelöst und ist jetzt EditorIn in der Veranstaltung. + became_teacher: > + %{user} hat einen DozentInnen-Gutschein eingelöst und ist jetzt DozentIn + der Veranstaltung. tutorial_details: > Neu übernommene Tutorien: %{tutorials}. redemption: 'Gutschein eingelöst:' @@ -3755,6 +3763,7 @@ de: voucher_invalid: 'Der Gutschein ist ungültig.' become_tutor_success: 'Dein Tutorenstatus wurde geupdatet.' become_editor_success: 'Dein Editorenstatus wurde geupdatet.' + become_teacher_success: 'Dein DozentInnenstatus wurde geupdatet.' tutorials: destruction_failed: > Das Tutorium konnte nicht gelöscht werden. Das kann z.B. daran liegen, diff --git a/config/locales/en.yml b/config/locales/en.yml index c905a0dce..87ad8f02f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2141,6 +2141,9 @@ en: became_editor: > %{user} has redeemed an editor voucher and has therefore become editor in the event series. + became_teacher: > + %{user} has redeemed a teacher voucher and has therefore become teacher + in the event series. tutorial_details: > Tutorials taken over: %{tutorials}. redemption: 'Voucher redeemed:' @@ -3564,6 +3567,8 @@ en: Your tutor status has been updated. become_editor_success: > Your editor status has been updated. + become_teacher_success: > + Your teacher status has been updated. tutorials: destruction_failed: > The tutorial could not be deleted. That may be because there are already