Orbit/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/approvals_controller.rb

147 lines
4.3 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# encoding: utf-8
class Panel::Announcement::BackEnd::ApprovalsController < OrbitBackendController
before_filter :authenticate_user!
before_filter :is_admin?
include AdminHelper
# layout 'admin'
def preview_and_approve
email_group_data
@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
if @bulletin.email_sent == true && @bulletin.is_checked == true && !@bulletin.is_rejected
send_email_data(@bulletin)
@bulletin.email_sent = false
@bulletin.save
end
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
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 == '0' or egroup == '1' or egroup == '2' or egroup == '3')
@group_mail << @email_group_data[egroup]["email"]
elsif @email_group_data.include?(egroup) and egroup == '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.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
# def get_categorys(id = nil)
# @bulletin_categorys = []
# if(is_manager? || is_admin?)
# @bulletin_categorys = (id ? BulletinCategory.find(id).to_a : BulletinCategory.all)
# elsif is_sub_manager?
# @bulletin_categorys = BulletinCategory.authed_for_user(current_user,'submit_new')
# end
# end
end