From c5d1eee49309245423d7b709f2e44510c8d79531 Mon Sep 17 00:00:00 2001 From: Frodo161 <110454463+Frodo161@users.noreply.github.com> Date: Sat, 1 Oct 2022 09:33:47 +0200 Subject: [PATCH 01/16] Update lectures_controller.rb Now, the update-method calls the NotificationMailer which sends a mail to any new editor of the given lecture. --- app/controllers/lectures_controller.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/controllers/lectures_controller.rb b/app/controllers/lectures_controller.rb index 632f2a3f2..ec7b421a5 100644 --- a/app/controllers/lectures_controller.rb +++ b/app/controllers/lectures_controller.rb @@ -26,6 +26,25 @@ def edit end def update + # removes the empty String "" in the NEW array of editor ids + # and converts it into an array of integers + all_ids = lecture_params[:editor_ids].map(&:to_i) - [0] + old_ids = @lecture.editor_ids + new_ids = all_ids - old_ids + + # returns an array of Users that match the given ids + recipients = User.where(id: new_ids) + + I18n.available_locales.each do |l| + local_recipients = recipients.where(locale: l) + if local_recipients.any? + NotificationMailer.with(recipients: local_recipients.pluck(:id), + locale: l, + lecture: @lecture) + .new_editor_email.deliver_later + end + end + @lecture.update(lecture_params) if structure_params.present? structure_ids = structure_params.select { |_k, v| v.to_i == 1 }.keys From fb5410376ef00284fb0d701d765858e24687ad97 Mon Sep 17 00:00:00 2001 From: Frodo161 <110454463+Frodo161@users.noreply.github.com> Date: Sat, 1 Oct 2022 09:36:36 +0200 Subject: [PATCH 02/16] Update notification_mailer.rb Adds the method "new_editor_email" which is called by the lectures_controller. --- app/mailers/notification_mailer.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index 1b591400a..50f2dd4ac 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -2,6 +2,7 @@ class NotificationMailer < ApplicationMailer before_action :set_sender_and_locale before_action :set_recipients, only: [:medium_email, :announcement_email, :new_lecture_email, + :new_editor_email, :submission_deletion_email, :submission_deletion_lecture_email, :submission_destruction_email, @@ -49,9 +50,17 @@ def new_lecture_email mail(from: @sender, bcc: @recipients.pluck(:email), subject: t('mailer.new_lecture_subject', - title: @lecture.title_for_viewers)) + title: @lecture.title_for_viewers)) end - + + def new_editor_email + @lecture = params[:lecture] + mail(from: @sender, + bcc: @recipients.pluck(:email), + subject: t('mailer.new_editor_subject', + title: @lecture.title_for_viewers)) + end + def submission_invitation_email @recipient = params[:recipient] @assignment = params[:assignment] From a3172c2ed86a2f19316395821bda736da072dec2 Mon Sep 17 00:00:00 2001 From: Frodo161 <110454463+Frodo161@users.noreply.github.com> Date: Sat, 1 Oct 2022 09:40:22 +0200 Subject: [PATCH 03/16] Update de.yml Added the lines new_editor_subject and new_editor. --- config/locales/de.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/locales/de.yml b/config/locales/de.yml index 6f5a9768c..e11635433 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -2915,6 +2915,8 @@ de: new_announcement: 'Es gibt eine neue Mitteilung' author: 'VerfasserIn' text: 'Text' + new_editor_subject: '%{title}-Editor' + new_editor: 'Du bist nun ein Editor von %{title}' new_lecture_subject: 'Neue Veranstaltung %{title}' new_lecture: 'Es wurde eine neue Veranstaltung angelegt: %{title}.' subscribe_lecture: > From 948ec760c1de0bb2960777474d8b10eaf015ae9a Mon Sep 17 00:00:00 2001 From: Frodo161 <110454463+Frodo161@users.noreply.github.com> Date: Sat, 1 Oct 2022 09:41:31 +0200 Subject: [PATCH 04/16] Update en.yml Added the lines "new_editor_subject" and "new_editor". --- config/locales/en.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 943f66959..0b21839ff 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2744,6 +2744,8 @@ en: new_announcement: 'There is a new announcement' author: 'Author' text: 'Text' + new_editor_subject: "%{title} editor" + new_editor: "You are now an editor of %{title}" 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.' @@ -3493,4 +3495,4 @@ en: attributes: name: taken: - 'A watchlist with that name already exists.' \ No newline at end of file + 'A watchlist with that name already exists.' From f9f0483771f805a1dfbfab6af43a1c4b88bc6783 Mon Sep 17 00:00:00 2001 From: Frodo161 <110454463+Frodo161@users.noreply.github.com> Date: Sat, 1 Oct 2022 09:44:08 +0200 Subject: [PATCH 05/16] Add files via upload Added the files "new_editor_email.html.erb" and "new_editor_email.text.erb" which contain the view of the new-editor-emails. --- app/views/notification_mailer/new_editor_email.html.erb | 8 ++++++++ app/views/notification_mailer/new_editor_email.text.erb | 1 + 2 files changed, 9 insertions(+) create mode 100644 app/views/notification_mailer/new_editor_email.html.erb create mode 100644 app/views/notification_mailer/new_editor_email.text.erb diff --git a/app/views/notification_mailer/new_editor_email.html.erb b/app/views/notification_mailer/new_editor_email.html.erb new file mode 100644 index 000000000..e8f41a9c0 --- /dev/null +++ b/app/views/notification_mailer/new_editor_email.html.erb @@ -0,0 +1,8 @@ +<%= t('mailer.new_editor', title: @lecture.title_with_teacher) %> +
+ +

+ <%= link_to(t('notifications.goto_profile'), + edit_profile_url, + class: 'btn btn-primary') %> +

diff --git a/app/views/notification_mailer/new_editor_email.text.erb b/app/views/notification_mailer/new_editor_email.text.erb new file mode 100644 index 000000000..f5cf0a46d --- /dev/null +++ b/app/views/notification_mailer/new_editor_email.text.erb @@ -0,0 +1 @@ +<%= t('mailer.new_editor', title: @lecture.title_with_teacher) %> From 80618ac87bedf0dd3db50ab858209f7c77e0f127 Mon Sep 17 00:00:00 2001 From: Frodo161 <110454463+Frodo161@users.noreply.github.com> Date: Fri, 4 Nov 2022 09:42:48 +0100 Subject: [PATCH 06/16] Update lectures_controller.rb The NotificationMailer is now called for every single recipient. --- app/controllers/lectures_controller.rb | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/app/controllers/lectures_controller.rb b/app/controllers/lectures_controller.rb index ec7b421a5..2b202be05 100644 --- a/app/controllers/lectures_controller.rb +++ b/app/controllers/lectures_controller.rb @@ -35,16 +35,23 @@ def update # returns an array of Users that match the given ids recipients = User.where(id: new_ids) - I18n.available_locales.each do |l| - local_recipients = recipients.where(locale: l) - if local_recipients.any? - NotificationMailer.with(recipients: local_recipients.pluck(:id), - locale: l, - lecture: @lecture) - .new_editor_email.deliver_later - end + recipients.each do |r| + NotificationMailer.with(recipient: r, + locale: r.locale, + lecture: @lecture) + .new_editor_email.deliver_later end + #I18n.available_locales.each do |l| + # local_recipients = recipients.where(locale: l) + # if local_recipients.any? + # NotificationMailer.with(recipients: local_recipients.pluck(:id), + # locale: l, + # lecture: @lecture) + # .new_editor_email.deliver_later + # end + #end + @lecture.update(lecture_params) if structure_params.present? structure_ids = structure_params.select { |_k, v| v.to_i == 1 }.keys From 22d1e61bf09ccdb298ce60df7dffb0c34653f1d6 Mon Sep 17 00:00:00 2001 From: Frodo161 <110454463+Frodo161@users.noreply.github.com> Date: Fri, 4 Nov 2022 09:45:03 +0100 Subject: [PATCH 07/16] Update notification_mailer.rb Changed the new_editor_email method as it is now called for every single recipient. Added the local variable @username to get access to the recipient's name in the view. --- app/mailers/notification_mailer.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index b3b99da44..3f8d6eab4 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -55,8 +55,11 @@ def new_lecture_email def new_editor_email @lecture = params[:lecture] + @recipient = params[:recipient] + @username = @recipient.tutorial_name + mail(from: @sender, - bcc: @recipients.pluck(:email), + to: @recipient.email, subject: t('mailer.new_editor_subject', title: @lecture.title_for_viewers)) end From a3dabf0b2cdcdd665d98192a9b279d3e5d0054c9 Mon Sep 17 00:00:00 2001 From: Frodo161 <110454463+Frodo161@users.noreply.github.com> Date: Fri, 4 Nov 2022 09:46:42 +0100 Subject: [PATCH 08/16] Update new_editor_email.text.erb Added the variable "username" which is needed in the locales. --- app/views/notification_mailer/new_editor_email.text.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/notification_mailer/new_editor_email.text.erb b/app/views/notification_mailer/new_editor_email.text.erb index f5cf0a46d..5766bf559 100644 --- a/app/views/notification_mailer/new_editor_email.text.erb +++ b/app/views/notification_mailer/new_editor_email.text.erb @@ -1 +1 @@ -<%= t('mailer.new_editor', title: @lecture.title_with_teacher) %> +<%= t('mailer.new_editor', title: @lecture.title_with_teacher, username: @username) %> From b8ad9a3adc25ac21ff6288fb58118ca7b143d57b Mon Sep 17 00:00:00 2001 From: Frodo161 <110454463+Frodo161@users.noreply.github.com> Date: Fri, 4 Nov 2022 09:49:33 +0100 Subject: [PATCH 09/16] Update new_editor_email.html.erb Added the variable "username" which is needed in the locales. Changed the link at the bottom of the mail (now one gets to the lecture edit page). --- app/views/notification_mailer/new_editor_email.html.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/notification_mailer/new_editor_email.html.erb b/app/views/notification_mailer/new_editor_email.html.erb index e8f41a9c0..bdbb75195 100644 --- a/app/views/notification_mailer/new_editor_email.html.erb +++ b/app/views/notification_mailer/new_editor_email.html.erb @@ -1,8 +1,8 @@ -<%= t('mailer.new_editor', title: @lecture.title_with_teacher) %> +<%= t('mailer.new_editor', title: @lecture.title_with_teacher, username: @username) %>

- <%= link_to(t('notifications.goto_profile'), - edit_profile_url, + <%= link_to(t('notifications.edit_lecture'), + edit_lecture_url(@lecture), class: 'btn btn-primary') %>

From 10b69420be8670c17ebc2ab75f1d7e1dcb45c184 Mon Sep 17 00:00:00 2001 From: Frodo161 <110454463+Frodo161@users.noreply.github.com> Date: Fri, 4 Nov 2022 09:50:43 +0100 Subject: [PATCH 10/16] Update de.yml Changed "new_editor_subject" and "new_editor". --- config/locales/de.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/de.yml b/config/locales/de.yml index cc2d3f90b..b50d99ca9 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -2917,8 +2917,8 @@ de: new_announcement: 'Es gibt eine neue Mitteilung' author: 'VerfasserIn' text: 'Text' - new_editor_subject: '%{title}-Editor' - new_editor: 'Du bist nun ein Editor von %{title}' + new_editor_subject: 'EditorInnenrechte für %{title}' + new_editor: 'Hallo %{username}, Du hast soeben Bearbeitungsrechte für %{title} erhalten.' new_lecture_subject: 'Neue Veranstaltung %{title}' new_lecture: 'Es wurde eine neue Veranstaltung angelegt: %{title}.' subscribe_lecture: > From dd27adcf722c4e8455b38176959b3b9bb29ce176 Mon Sep 17 00:00:00 2001 From: Frodo161 <110454463+Frodo161@users.noreply.github.com> Date: Fri, 4 Nov 2022 09:51:19 +0100 Subject: [PATCH 11/16] Update en.yml --- config/locales/en.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index bd9f395f1..aba01f53a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2746,8 +2746,8 @@ en: new_announcement: 'There is a new announcement' author: 'Author' text: 'Text' - new_editor_subject: "%{title} editor" - new_editor: "You are now an editor of %{title}" + new_editor_subject: 'Editing Rights for %{title}' + new_editor: 'Dear %{username}, you have been given editing rights for %{title}.' 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.' From 7c8b6f5efd1de5b3ceaacc5e09831f95d9145407 Mon Sep 17 00:00:00 2001 From: Frodo161 <110454463+Frodo161@users.noreply.github.com> Date: Thu, 5 Jan 2023 13:57:47 +0100 Subject: [PATCH 12/16] Update en.yml Added the missing entry "edit_lecture". --- config/locales/en.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/config/locales/en.yml b/config/locales/en.yml index aba01f53a..068cedc94 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1941,6 +1941,7 @@ en: mampf_announcement: 'New announcement about MaMpf' lecture_announcement: 'New announcement in %{title}' new_lecture: 'New event series %{title}' + edit_lecture: 'Edit event' subscribe_lecture: 'You can subscribe it via your profile.' subscribe_lecture_html: 'You can subscribe it via your %{profile}.' new_lecture_created_html: > From ffbfd05b1b7c28e4027e303880966b27ee2d1ef8 Mon Sep 17 00:00:00 2001 From: Frodo161 <110454463+Frodo161@users.noreply.github.com> Date: Thu, 5 Jan 2023 13:58:43 +0100 Subject: [PATCH 13/16] Update de.yml Added the missing entry "edit_lecture". --- config/locales/de.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/config/locales/de.yml b/config/locales/de.yml index b50d99ca9..1911bb94d 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -2062,6 +2062,7 @@ de: mampf_announcement: 'Neue Mitteilung über MaMpf' lecture_announcement: 'Neue Mitteilung in %{title}' new_lecture: 'Neue Veranstaltung %{title}' + edit_lecture: 'Veranstaltung bearbeiten' subscribe_lecture: 'Abonniere sie in Deinem Profil.' subscribe_lecture_html: 'Du kannst sie über Deine %{profile} abonnieren.' new_lecture_created_html: > From ecc7e94109ad27f22f0be4cf9a29f949c11d37cc Mon Sep 17 00:00:00 2001 From: Frodo161 <110454463+Frodo161@users.noreply.github.com> Date: Thu, 5 Jan 2023 14:01:33 +0100 Subject: [PATCH 14/16] Update lectures_controller.rb Deleted old, commented out code. --- app/controllers/lectures_controller.rb | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/app/controllers/lectures_controller.rb b/app/controllers/lectures_controller.rb index 2b202be05..eca1c36cb 100644 --- a/app/controllers/lectures_controller.rb +++ b/app/controllers/lectures_controller.rb @@ -42,16 +42,6 @@ def update .new_editor_email.deliver_later end - #I18n.available_locales.each do |l| - # local_recipients = recipients.where(locale: l) - # if local_recipients.any? - # NotificationMailer.with(recipients: local_recipients.pluck(:id), - # locale: l, - # lecture: @lecture) - # .new_editor_email.deliver_later - # end - #end - @lecture.update(lecture_params) if structure_params.present? structure_ids = structure_params.select { |_k, v| v.to_i == 1 }.keys From 0cd16c5b0a8e37cca9f4885c653b8e1312039343 Mon Sep 17 00:00:00 2001 From: Frodo161 <110454463+Frodo161@users.noreply.github.com> Date: Thu, 5 Jan 2023 14:03:46 +0100 Subject: [PATCH 15/16] Update new_editor_email.html.erb Deleted unnecessary comment containing old code. --- app/views/notification_mailer/new_editor_email.html.erb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/views/notification_mailer/new_editor_email.html.erb b/app/views/notification_mailer/new_editor_email.html.erb index bdbb75195..c4b236c5f 100644 --- a/app/views/notification_mailer/new_editor_email.html.erb +++ b/app/views/notification_mailer/new_editor_email.html.erb @@ -1,6 +1,5 @@ <%= t('mailer.new_editor', title: @lecture.title_with_teacher, username: @username) %>
-

<%= link_to(t('notifications.edit_lecture'), edit_lecture_url(@lecture), From 3792ed82f0d2ca152a1113abdacb5e86d32d2764 Mon Sep 17 00:00:00 2001 From: Frodo161 <110454463+Frodo161@users.noreply.github.com> Date: Sun, 15 Jan 2023 13:54:29 +0100 Subject: [PATCH 16/16] Update lectures_controller.rb If a lecture had no editors the old code would perform actions on a nil object causing an error. Now the relevant passage in the update method is surrounded by an if-statement which first checks, if the given array of editor ids is nil and skips the passage in this case. --- app/controllers/lectures_controller.rb | 31 ++++++++++++++------------ 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/app/controllers/lectures_controller.rb b/app/controllers/lectures_controller.rb index eca1c36cb..bf7a63ffb 100644 --- a/app/controllers/lectures_controller.rb +++ b/app/controllers/lectures_controller.rb @@ -26,20 +26,23 @@ def edit end def update - # removes the empty String "" in the NEW array of editor ids - # and converts it into an array of integers - all_ids = lecture_params[:editor_ids].map(&:to_i) - [0] - old_ids = @lecture.editor_ids - new_ids = all_ids - old_ids - - # returns an array of Users that match the given ids - recipients = User.where(id: new_ids) - - recipients.each do |r| - NotificationMailer.with(recipient: r, - locale: r.locale, - lecture: @lecture) - .new_editor_email.deliver_later + editor_ids = lecture_params[:editor_ids] + if editor_ids != nil + # removes the empty String "" in the NEW array of editor ids + # and converts it into an array of integers + all_ids = editor_ids.map(&:to_i) - [0] + old_ids = @lecture.editor_ids + new_ids = all_ids - old_ids + + # returns an array of Users that match the given ids + recipients = User.where(id: new_ids) + + recipients.each do |r| + NotificationMailer.with(recipient: r, + locale: r.locale, + lecture: @lecture) + .new_editor_email.deliver_later + end end @lecture.update(lecture_params)