Skip to content

Commit

Permalink
#333 fixing notifications with attached grades_report to be sent to s…
Browse files Browse the repository at this point in the history
…tudents with more than one enrollment
  • Loading branch information
Carlos-Eduardo-Cabral-da-Cunha committed Sep 30, 2020
1 parent e1f66d2 commit 5edf15e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/controllers/notifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
18 changes: 9 additions & 9 deletions app/models/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,22 +163,22 @@ 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),
:subject => formatter.format(self.subject_template),
: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
Expand Down

0 comments on commit 5edf15e

Please sign in to comment.