2014-02-19 03:14:25 +00:00
|
|
|
|
# encoding: utf-8
|
2014-01-14 11:54:35 +00:00
|
|
|
|
class Panel::Announcement::BackEnd::ApprovalsController < OrbitBackendController
|
|
|
|
|
before_filter :authenticate_user!
|
|
|
|
|
before_filter :is_admin?
|
|
|
|
|
include AdminHelper
|
|
|
|
|
# layout 'admin'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def preview_and_approve
|
2014-02-19 03:14:25 +00:00
|
|
|
|
email_group_data
|
2014-01-14 11:54:35 +00:00
|
|
|
|
@bulletin = Bulletin.find params[:bulletin_id]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def approve
|
|
|
|
|
notice = ""
|
|
|
|
|
@bulletin = Bulletin.find params[:bulletin_id]
|
|
|
|
|
@bulletin.proc_check(params[:bulletin][:is_checked],params[:bulletin][:not_checked_reason])
|
|
|
|
|
@bulletin.de_pending
|
|
|
|
|
if @bulletin.save
|
2014-02-19 03:14:25 +00:00
|
|
|
|
|
|
|
|
|
if @bulletin.email_sent == true && @bulletin.is_checked == true && !@bulletin.is_rejected
|
|
|
|
|
send_email_data(@bulletin)
|
|
|
|
|
|
|
|
|
|
@bulletin.email_sent = false
|
|
|
|
|
@bulletin.save
|
|
|
|
|
end
|
|
|
|
|
|
2014-01-14 11:54:35 +00:00
|
|
|
|
notice = t('announcement.approve_bulletin_success')
|
|
|
|
|
else
|
|
|
|
|
notice = t('announcement.approve_bulletin_fail')
|
|
|
|
|
end
|
|
|
|
|
redirect_to(panel_announcement_back_end_bulletins_url,:notice => notice)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def setting
|
|
|
|
|
@sys_users = User.all(conditions: {admin: false}).includes(:avatar).not_guest_user
|
|
|
|
|
@bulletin_categorys = BulletinCategory.all
|
|
|
|
|
@options_from_collection_for_select_bulletin_categorys = @bulletin_categorys.collect{|bc| [bc.title,bc.id] }
|
|
|
|
|
if params.has_key? :category
|
|
|
|
|
@bulletin_category = BulletinCategory.find params[:category][:id]
|
|
|
|
|
else
|
|
|
|
|
@bulletin_category = @bulletin_categorys.first
|
|
|
|
|
end
|
|
|
|
|
preload_object_auth = @bulletin_category.get_object_auth_by_title('fact_check')
|
|
|
|
|
@users_array = preload_object_auth.privilege_users rescue []
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html
|
|
|
|
|
format.js
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update_setting
|
|
|
|
|
object_auth = update_setting_by_params
|
|
|
|
|
if object_auth.save!
|
|
|
|
|
flash[:notice] = t('update.success_')
|
|
|
|
|
else
|
|
|
|
|
flash[:notice] = t('update.fail')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def user_list
|
|
|
|
|
@bulletin_category = BulletinCategory.find params[:category][:id]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
def update_setting_by_params
|
|
|
|
|
category = BulletinCategory.find params[:category][:id]
|
|
|
|
|
privilege_users = params[:users].collect{|key,value| User.find key } rescue []
|
|
|
|
|
object_auth_ary = category.object_auths.where(title: 'fact_check') || (category.object_auths.create :title=> 'fact_check')
|
|
|
|
|
object_auth = object_auth_ary.first
|
|
|
|
|
object_auth.privilege_users = privilege_users
|
|
|
|
|
object_auth
|
|
|
|
|
end
|
2014-02-19 03:14:25 +00:00
|
|
|
|
|
|
|
|
|
def send_email_data(bulletin)
|
|
|
|
|
|
|
|
|
|
@site = Site.first
|
|
|
|
|
@user = User.find(bulletin.create_user_id)
|
|
|
|
|
@host = request.host_with_port
|
|
|
|
|
|
|
|
|
|
email_group_data
|
|
|
|
|
|
|
|
|
|
@group_mail = Array.new
|
|
|
|
|
|
|
|
|
|
bulletin.email_group.each do |egroup|
|
|
|
|
|
|
|
|
|
|
if @email_group_data.include?(egroup) and (egroup == 'e_0' or egroup == 'e_1' or egroup == 'e_2' or egroup == 'e_3')
|
|
|
|
|
|
|
|
|
|
@group_mail << @email_group_data[egroup]["email"]
|
|
|
|
|
|
|
|
|
|
elsif @email_group_data.include?(egroup) and egroup == 'e_4'
|
|
|
|
|
|
|
|
|
|
@group_mail << bulletin.other_mailaddress
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if !@group_mail.join.blank?
|
|
|
|
|
|
|
|
|
|
@mail_content = {
|
|
|
|
|
"host" => @host,
|
|
|
|
|
"site_title" => @site.title,
|
|
|
|
|
"title" => bulletin.title,
|
|
|
|
|
"template" => 'announcement_mailer/cron_mail',
|
|
|
|
|
"url" => "http://#{@host}#{panel_announcement_front_end_bulletin_path(bulletin, :category_id => bulletin.category.id)}"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@mail_cron = {
|
|
|
|
|
:mail_from_app => 'announcement',
|
|
|
|
|
:mail_from => @user.email,
|
|
|
|
|
:mail_reply_to => @user.email,
|
|
|
|
|
:mail_subject => "#{t("announcement.mail_subject",:site_title => @site.title)}:#{bulletin.title}",
|
|
|
|
|
:mail_to => @group_mail.join(','),
|
|
|
|
|
:mail_content => @mail_content ,
|
|
|
|
|
# :mail_sentdate => bulletin.email_sentdate,
|
|
|
|
|
:mail_sentdate => DateTime.now,
|
|
|
|
|
:create_user_id => bulletin.create_user_id,
|
|
|
|
|
:update_user_id => bulletin.create_user_id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@mail_cron = MailCron.new(@mail_cron)
|
|
|
|
|
|
|
|
|
|
@mail_cron.save
|
|
|
|
|
|
|
|
|
|
MailCron.send_mail_now(@mail_cron.id)
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def email_group_data
|
|
|
|
|
|
|
|
|
|
@email_group_data = Bulletin.email_group_data
|
|
|
|
|
|
|
|
|
|
end
|
2014-01-14 11:54:35 +00:00
|
|
|
|
|
|
|
|
|
end
|