diff --git a/app/controllers/admin/announcements_controller.rb b/app/controllers/admin/announcements_controller.rb index 120a4f8..629942e 100644 --- a/app/controllers/admin/announcements_controller.rb +++ b/app/controllers/admin/announcements_controller.rb @@ -60,8 +60,16 @@ class Admin::AnnouncementsController < OrbitAdminController bulletin.update_user_id = current_user.id if user_can_approve? bulletin.approved = true + bulletin.save + else + bulletin.save + Thread.new do + begin + send_notification_mail_to_managers(bulletin,"approval") + rescue e + end + end end - bulletin.save build_email(bulletin) redirect_to params['referer_url'] end @@ -73,12 +81,14 @@ class Admin::AnnouncementsController < OrbitAdminController bulletin.approved = true bulletin.rejected = false bulletin.reapproval = false + bulletin.save else bulletin.rejected = true bulletin.reapproval = false bulletin.rejection_reason = params["reason"] + bulletin.save + send_rejection_email(bulletin) end - bulletin.save redirect_to admin_announcements_path end @@ -106,9 +116,18 @@ class Admin::AnnouncementsController < OrbitAdminController end bulletin.update_attributes(bulletin_params) - bulletin.reapproval = true if bulletin.rejected - - bulletin.save + if bulletin.rejected + bulletin.reapproval = true + bulletin.save + Thread.new do + begin + send_notification_mail_to_managers(bulletin,"reapproval") + rescue e + end + end + else + bulletin.save + end build_email(bulletin) redirect_to params['referer_url'] end diff --git a/app/helpers/admin/announcements_helper.rb b/app/helpers/admin/announcements_helper.rb index 5521577..022063a 100644 --- a/app/helpers/admin/announcements_helper.rb +++ b/app/helpers/admin/announcements_helper.rb @@ -31,6 +31,39 @@ module Admin::AnnouncementsHelper request.protocol+(request.host_with_port+'/'+ann_page+'/'+'/'+bulletin.to_param).gsub('//','/') rescue "/" end + def send_rejection_email(announcement) + user = User.find(announcement.create_user_id) rescue nil + if !user.nil? + email = user.member_profile.email + if !email.nil? && email != "" + url = page_for_bulletin(announcement) + mail = Email.new(:mail_to => email, :mail_subject => "Announcement rejected : #{announcement.title}.", :template => "email/rejection_email.html.erb", :template_data => {"url" => url, "rejector" => current_user.name, "name" => user.name, "reason" => announcement.rejection_reason}) + mail.deliver + end + end + end + + def send_notification_mail_to_managers(announcement, type) + authorizations = Authorization.where(:module_app_id => @module_app.id) + users = authorizations.collect do |auth| + auth.user + end + users.each do |user| + email = user.member_profile.email + if !email.nil? && email != "" + send_email(user.name, email, announcement, type) + sleep(2) + end + end + end + + def send_email(name, useremail, announcement, type) + url = page_for_bulletin(announcement) + template = (type == "approval" ? "email/new_announcement_email.html.erb" : "email/reapproval_announcement_email.html.erb") + email = Email.new(:mail_to => useremail, :mail_subject => "New announcement : #{announcement.title}.", :template => template, :template_data => {"url" => url, "submitter" => current_user.name, "name" => name}) + email.deliver + end + def load_access_level if current_user.is_admin? @access_level = "admin" diff --git a/app/views/email/new_announcement_email.html.erb b/app/views/email/new_announcement_email.html.erb new file mode 100644 index 0000000..e8e32c8 --- /dev/null +++ b/app/views/email/new_announcement_email.html.erb @@ -0,0 +1,3 @@ +

Hello <%= @data["name"] %>,

+

<%= @data["submitter"] %> submitted a new announcement. + Please click here to view the announcement. \ No newline at end of file diff --git a/app/views/email/reapproval_announcement_email.html.erb b/app/views/email/reapproval_announcement_email.html.erb new file mode 100644 index 0000000..dd1d1c7 --- /dev/null +++ b/app/views/email/reapproval_announcement_email.html.erb @@ -0,0 +1,3 @@ +

Hello <%= @data["name"] %>,

+

<%= @data["submitter"] %> updated the announcement. + Please click here to view the annoucement. \ No newline at end of file diff --git a/app/views/email/rejection_email.html.erb b/app/views/email/rejection_email.html.erb new file mode 100644 index 0000000..8bc9867 --- /dev/null +++ b/app/views/email/rejection_email.html.erb @@ -0,0 +1,3 @@ +

Hello <%= @data["name"] %>,

+

<%= @data["rejector"] %> has rejected your announcement<%= @data["reason"].nil? || @data["reason"] == "" ? "." : ", because #{@data["reason"]}" %>

+ Please click here to view the annoucement. \ No newline at end of file