email to managers on new announcement and email to user if rejected
This commit is contained in:
parent
b7d16f0f15
commit
7042492328
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
<h3>Hello <%= @data["name"] %>,</h3>
|
||||
<p><%= @data["submitter"] %> submitted a new announcement.
|
||||
<a href="<%= @data['url'] %>" > Please click here to view the announcement.</a>
|
|
@ -0,0 +1,3 @@
|
|||
<h3>Hello <%= @data["name"] %>,</h3>
|
||||
<p><%= @data["submitter"] %> updated the announcement.
|
||||
<a href="<%= @data['url'] %>" > Please click here to view the annoucement.</a>
|
|
@ -0,0 +1,3 @@
|
|||
<h3>Hello <%= @data["name"] %>,</h3>
|
||||
<p><%= @data["rejector"] %> has rejected your announcement<%= @data["reason"].nil? || @data["reason"] == "" ? "." : ", because #{@data["reason"]}" %></p>
|
||||
<a href="<%= @data['url'] %>" > Please click here to view the annoucement.</a>
|
Reference in New Issue