Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/new-editor-email' into mampf-next
Browse files Browse the repository at this point in the history
  • Loading branch information
zebleck committed Jan 18, 2023
2 parents 55b5add + 3792ed8 commit 35b1e80
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 2 deletions.
19 changes: 19 additions & 0 deletions app/controllers/lectures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@ def edit
end

def update
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)
if structure_params.present?
structure_ids = structure_params.select { |_k, v| v.to_i == 1 }.keys
Expand Down
14 changes: 13 additions & 1 deletion app/mailers/notification_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -49,9 +50,20 @@ 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]
@recipient = params[:recipient]
@username = @recipient.tutorial_name

mail(from: @sender,
to: @recipient.email,
subject: t('mailer.new_editor_subject',
title: @lecture.title_for_viewers))
end

def submission_invitation_email
@recipient = params[:recipient]
@assignment = params[:assignment]
Expand Down
7 changes: 7 additions & 0 deletions app/views/notification_mailer/new_editor_email.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<%= t('mailer.new_editor', 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_editor_email.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= t('mailer.new_editor', title: @lecture.title_with_teacher, username: @username) %>
3 changes: 3 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2073,6 +2073,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: >
Expand Down Expand Up @@ -2948,6 +2949,8 @@ de:
new_announcement: 'Es gibt eine neue Mitteilung'
author: 'VerfasserIn'
text: 'Text'
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: >
Expand Down
5 changes: 4 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1947,6 +1947,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: >
Expand Down Expand Up @@ -2772,6 +2773,8 @@ en:
new_announcement: 'There is a new announcement'
author: 'Author'
text: 'Text'
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.'
Expand Down Expand Up @@ -3529,4 +3532,4 @@ en:
attributes:
name:
taken:
'A watchlist with that name already exists.'
'A watchlist with that name already exists.'

0 comments on commit 35b1e80

Please sign in to comment.