emails to managers and user if rejected

This commit is contained in:
Harry Bomrah 2015-10-27 20:16:14 +08:00
parent 8d9e335dec
commit 25bd56e8ce
5 changed files with 66 additions and 3 deletions

View File

@ -62,8 +62,16 @@ class Admin::NewsController < OrbitAdminController
news_bulletin.update_user_id = current_user.id news_bulletin.update_user_id = current_user.id
if user_can_approve? if user_can_approve?
news_bulletin.approved = true news_bulletin.approved = true
news_bulletin.save
else
news_bulletin.save
Thread.new do
begin
send_notification_mail_to_managers(news_bulletin,"approval")
rescue e
end
end
end end
news_bulletin.save
build_email(news_bulletin) build_email(news_bulletin)
redirect_to params['referer_url'] redirect_to params['referer_url']
end end
@ -75,12 +83,14 @@ class Admin::NewsController < OrbitAdminController
news_bulletin.approved = true news_bulletin.approved = true
news_bulletin.rejected = false news_bulletin.rejected = false
news_bulletin.reapproval = false news_bulletin.reapproval = false
news_bulletin.save
else else
news_bulletin.rejected = true news_bulletin.rejected = true
news_bulletin.reapproval = false news_bulletin.reapproval = false
news_bulletin.rejection_reason = params["reason"] news_bulletin.rejection_reason = params["reason"]
news_bulletin.save
send_rejection_email(news_bulletin)
end end
news_bulletin.save
redirect_to "/admin/news" redirect_to "/admin/news"
end end
@ -112,7 +122,18 @@ class Admin::NewsController < OrbitAdminController
end end
news_bulletin.update_attributes(news_bulletin_params) news_bulletin.update_attributes(news_bulletin_params)
news_bulletin.reapproval = true if news_bulletin.rejected if news_bulletin.rejected
news_bulletin.reapproval = true
news_bulletin.save
Thread.new do
begin
send_notification_mail_to_managers(news_bulletin, "reapproval")
rescue e
end
end
else
bulletin.save
end
news_bulletin.save news_bulletin.save
build_email(news_bulletin) build_email(news_bulletin)
redirect_to params['referer_url'] redirect_to params['referer_url']

View File

@ -25,6 +25,39 @@ module Admin::NewsHelper
request.protocol+(request.host_with_port+ann_page.url+'/'+news_bulletin.to_param).gsub('//','/') rescue "/" request.protocol+(request.host_with_port+ann_page.url+'/'+news_bulletin.to_param).gsub('//','/') rescue "/"
end end
def send_rejection_email(news)
user = User.find(news.create_user_id) rescue nil
if !user.nil?
email = user.member_profile.email
if !email.nil? && email != ""
url = page_for_news_bulletin(news)
mail = Email.new(:mail_to => email, :mail_subject => "News rejected : #{news.title}.", :template => "email/rejection_email.html.erb", :template_data => {"url" => url, "rejector" => current_user.name, "name" => user.name, "reason" => news.rejection_reason})
mail.deliver
end
end
end
def send_notification_mail_to_managers(news, 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, news, type)
sleep(2)
end
end
end
def send_email(name, useremail, news, type)
url = page_for_news_bulletin(news)
template = (type == "approval" ? "email/new_news_email.html.erb" : "email/reapproval_news_email.html.erb")
email = Email.new(:mail_to => useremail, :mail_subject => "New news : #{news.title}.", :template => template, :template_data => {"url" => url, "submitter" => current_user.name, "name" => name})
email.deliver
end
def load_access_level def load_access_level
if current_user.is_admin? if current_user.is_admin?
@access_level = "admin" @access_level = "admin"

View File

@ -0,0 +1,3 @@
<h3>Hello <%= @data["name"] %>,</h3>
<p><%= @data["submitter"] %> submitted a new news.
<a href="<%= @data['url'] %>" > Please click here to view the news.</a>

View File

@ -0,0 +1,3 @@
<h3>Hello <%= @data["name"] %>,</h3>
<p><%= @data["submitter"] %> updated the news.
<a href="<%= @data['url'] %>" > Please click here to view the news.</a>

View File

@ -0,0 +1,3 @@
<h3>Hello <%= @data["name"] %>,</h3>
<p><%= @data["rejector"] %> has rejected your news<%= @data["reason"].nil? || @data["reason"] == "" ? "." : ", because #{@data["reason"]}" %></p>
<a href="<%= @data['url'] %>" > Please click here to view the news.</a>