From fcabcf430224c5ce5ec3d23e3577e85f5056b2ab Mon Sep 17 00:00:00 2001
From: ShounakB <65479699+Shounaks@users.noreply.github.com>
Date: Fri, 29 Nov 2024 13:37:34 +1100
Subject: [PATCH] Adding Teacher Comment Mailer
---
app/mailers/teacher_response_mailer.rb | 22 ++++++
app/models/task.rb | 8 ++
.../recieved_notification.html.erb | 73 +++++++++++++++++++
.../recieved_notification.text.erb | 16 ++++
4 files changed, 119 insertions(+)
create mode 100644 app/mailers/teacher_response_mailer.rb
create mode 100644 app/views/teacher_response_mailer/recieved_notification.html.erb
create mode 100644 app/views/teacher_response_mailer/recieved_notification.text.erb
diff --git a/app/mailers/teacher_response_mailer.rb b/app/mailers/teacher_response_mailer.rb
new file mode 100644
index 000000000..b7f33d0be
--- /dev/null
+++ b/app/mailers/teacher_response_mailer.rb
@@ -0,0 +1,22 @@
+class TeacherResponseMailer < ApplicationMailer
+ def add_general
+ @doubtfire_host = Doubtfire::Application.config.institution[:host]
+ @doubtfire_product_name = Doubtfire::Application.config.institution[:product_name]
+ @unsubscribe_url = "#{@doubtfire_host}/#/home?notifications"
+ end
+
+ def recieved_notification(project, task)
+ return nil if project.nil?
+
+ add_general
+
+ @student = project.student
+ @project = project
+ @convenor = project.main_convenor_user
+
+ email_with_name = %("#{@student.name}" <#{@student.email}>)
+ convenor_email = %("#{@convenor.name}" <#{@convenor.email}>)
+ subject = "#{project.unit.name} #{task}: You have recieved comments."
+ mail(to: email_with_name, from: convenor_email, subject: subject)
+ end
+end
diff --git a/app/models/task.rb b/app/models/task.rb
index 46759a522..7015e2ae9 100644
--- a/app/models/task.rb
+++ b/app/models/task.rb
@@ -735,6 +735,14 @@ def add_status_comment(current_user, status)
comment.recipient = current_user == project.student ? project.tutor_for(task_definition) : project.student
comment.save!
+ # send emails...
+ begin
+ logger.info "Sending comment notification email for project #{project.id}"
+ TeacherResponseMailer.recieved_notification(project,self).deliver
+ rescue => e
+ logger.error "Failed to send emails from comment submission. Rescued with error: #{e.message}"
+ end
+
comment
end
diff --git a/app/views/teacher_response_mailer/recieved_notification.html.erb b/app/views/teacher_response_mailer/recieved_notification.html.erb
new file mode 100644
index 000000000..b2adc71a0
--- /dev/null
+++ b/app/views/teacher_response_mailer/recieved_notification.html.erb
@@ -0,0 +1,73 @@
+
+
+
+
+
+
+
+ <%= @doubtfire_product_name %> Notification
+ Hi <%= @student.first_name %>,
+
+ I have checked your tasks and provided some feedback. Login and check the status <%= @hasComments ? 'and comments' : ''%> of the following tasks:
+
+ <% @tasks.each do |task| %>
+
+ <%= task.task_definition.abbreviation %> -
+
+ <%=task.task_definition.name%>
+
+ <%= task.is_last_comment_by?(@tutor) ? ' with comments' : ''%>
+
+ <% end %>
+
+
+
+ Cheers,
+ The <%= @doubtfire_product_name %> Team on behalf of <%= @tutor.name %>
+
+
+
+ Unsubscribe | Generated with <%= @doubtfire_product_name %>
+
+
+
diff --git a/app/views/teacher_response_mailer/recieved_notification.text.erb b/app/views/teacher_response_mailer/recieved_notification.text.erb
new file mode 100644
index 000000000..d40a8c7ce
--- /dev/null
+++ b/app/views/teacher_response_mailer/recieved_notification.text.erb
@@ -0,0 +1,16 @@
+Hi <%= @student.first_name %>,
+
+I have checked your tasks and provided some feedback. Login and check the status<%= @has_comments ? ' and comments' : ''%> of the following tasks:
+
+<% @tasks.each do |task| %>
+ * <%= task.task_definition.abbreviation %> - <%=task.task_definition.name%> <%= task.is_last_comment_by?(@tutor) ? ' - with comments' : ''%>
+<% end %>
+
+Cheers,
+The <%= @doubtfire_product_name %> Team on behalf of <%= @tutor.name %>
+
+---
+
+Visit <%= @unsubscribe_url%> to unsubscribe from these notifications.
+
+Generated with <%= @doubtfire_product_name %>