89 lines
2.6 KiB
Ruby
89 lines
2.6 KiB
Ruby
module Admin::NewsHelper
|
|
def page_for_news_bulletin(news_bulletin)
|
|
ann_page = nil
|
|
pages = Page.where(:module=>'news')
|
|
|
|
pages.each do |page|
|
|
if page.categories.count ==1
|
|
if page.categories.include?(news_bulletin.category.id.to_s)
|
|
ann_page = page
|
|
end
|
|
end
|
|
break if !ann_page.nil?
|
|
end
|
|
|
|
if ann_page.nil?
|
|
pages.each do |page|
|
|
if page.categories.include?(news_bulletin.category.id.to_s)
|
|
ann_page = page
|
|
end
|
|
break if !ann_page.nil?
|
|
end
|
|
end
|
|
|
|
ann_page = pages.first if ann_page.nil?
|
|
request.protocol+(request.host_with_port+ann_page.url+'/'+news_bulletin.to_param).gsub('//','/') rescue "/"
|
|
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
|
|
users = Workgroup.where(:key => "admin").first.users rescue []
|
|
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 => "校園新聞請審核通知", :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"
|
|
elsif current_user.is_manager?(@module_app)
|
|
@access_level = "manager"
|
|
end
|
|
end
|
|
|
|
def user_can_approve?
|
|
case @access_level
|
|
when "admin"
|
|
return true
|
|
when "manager"
|
|
return true
|
|
else
|
|
return false
|
|
end
|
|
end
|
|
|
|
end
|