From 5edf15eb016ce0b933239e7ff80b904cbea735ca Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Cabral da Cunha Date: Wed, 30 Sep 2020 03:31:09 -0300 Subject: [PATCH] #333 fixing notifications with attached grades_report to be sent to students with more than one enrollment --- app/controllers/notifications_controller.rb | 2 +- app/models/notification.rb | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index edab0463..5955f9e1 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -80,7 +80,7 @@ def execute_now message_attachments = notification_execute[:notifications_attachments][message] if message_attachments if message_attachments[:grades_report_pdf] - enrollments_id = message_attachments[:grades_report_pdf][:file_contents] + enrollments_id = message[:enrollments_id] enrollment = Enrollment.find(enrollments_id) class_enrollments = enrollment.class_enrollments.where(:situation => I18n.translate("activerecord.attributes.class_enrollment.situations.aproved")).joins(:course_class).order("course_classes.year", "course_classes.semester") diff --git a/app/models/notification.rb b/app/models/notification.rb index 8c289c2f..e81722e1 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -163,15 +163,6 @@ def execute(options={}) formatter = ERBFormatter.new(bindings) - attachments = {} - - #add grades_report_pdf attachment if required - if self.has_grades_report_pdf_attachment - attachment_file_name = "#{I18n.t('pdf_content.enrollment.grades_report.title')} - #{Enrollment.find(bindings["enrollments_id"]).student.name}.pdf" - attachment_file_contents = bindings["enrollments_id"] - attachments[:grades_report_pdf] = {:file_name => attachment_file_name, :file_contents => attachment_file_contents} - end - notification = { :notification_id => self.id, :to => formatter.format(self.to_template), @@ -179,6 +170,15 @@ def execute(options={}) :body => formatter.format(self.body_template) } + attachments = {} + + #add grades_report_pdf attachment if required + if self.has_grades_report_pdf_attachment + notification[:enrollments_id] = bindings["enrollments_id"] + attachment_file_name = "#{I18n.t('pdf_content.enrollment.grades_report.title')} - #{Enrollment.find(bindings["enrollments_id"]).student.name}.pdf" + attachments[:grades_report_pdf] = {:file_name => attachment_file_name} + end + notifications << notification notifications_attachments[notification] = attachments end