From 1a9a4d0112d3f8bd41ecf87cef24b88212a4da0b Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 19 Jul 2013 16:03:14 +0800 Subject: [PATCH] Changes for ntue (mail app) --- Gemfile | 2 + app/controllers/sessions_controller.rb | 35 ++ config/environments/development.rb | 18 +- config/routes.rb | 5 + .../back_end/approvals_controller.rb | 73 ++++ .../back_end/bulletins_controller.rb | 85 +++++ .../announcement/app/models/bulletin.rb | 44 +++ .../announcement_mailer/cron_mail.html.erb | 29 ++ .../approvals/_modal_approve.html.erb | 6 + .../back_end/bulletins/_form.html.erb | 49 +++ .../announcement/config/locales/en.yml | 19 +- .../announcement/config/locales/zh_tw.yml | 20 +- vendor/built_in_modules/er_email/.gitignore | 7 + vendor/built_in_modules/er_email/Gemfile | 17 + vendor/built_in_modules/er_email/MIT-LICENSE | 20 ++ vendor/built_in_modules/er_email/README.rdoc | 3 + vendor/built_in_modules/er_email/Rakefile | 40 +++ .../app/assets/images/er_email/.gitkeep | 0 .../app/assets/javascripts/er_email/.gitkeep | 0 .../app/assets/stylesheets/er_email/.gitkeep | 0 .../er_email/app/controllers/.gitkeep | 0 .../app/controllers/application_controller.rb | 23 ++ .../er_email/back_end/approvals_controller.rb | 145 ++++++++ .../back_end/email_er_categorys_controller.rb | 128 +++++++ .../er_email/back_end/email_ers_controller.rb | 318 ++++++++++++++++++ .../er_email/app/helpers/.gitkeep | 0 .../back_end/email_er_categorys_helper.rb | 16 + .../er_email/back_end/email_ers_helper.rb | 58 ++++ .../er_email/app/mailers/.gitkeep | 0 .../er_email/app/models/.gitkeep | 0 .../er_email/app/models/email_er.rb | 123 +++++++ .../er_email/app/models/email_er_category.rb | 47 +++ .../er_email/app/models/email_er_file.rb | 23 ++ .../er_email/app/views/.gitkeep | 0 .../approvals/_modal_approve.html.erb | 68 ++++ .../back_end/approvals/_modal_list.html.erb | 44 +++ .../approvals/preview_and_approve.js.erb | 5 + .../back_end/approvals/setting.html.erb | 53 +++ .../back_end/approvals/setting.js.erb | 2 + .../back_end/approvals/update_setting.js.erb | 1 + .../back_end/approvals/user_list.js.erb | 2 + .../_email_er_category.html.erb | 19 ++ .../email_er_categorys/_form.html.erb | 30 ++ .../back_end/email_er_categorys/create.js.erb | 2 + .../email_er_categorys/destroy.js.erb | 1 + .../back_end/email_er_categorys/edit.js.erb | 1 + .../email_er_categorys/index.html.erb | 23 ++ .../back_end/email_er_categorys/new.js.erb | 1 + .../back_end/email_er_categorys/update.js.erb | 4 + .../email_ers/_clear_filters.html.erb | 3 + .../back_end/email_ers/_email_er.html.erb | 61 ++++ .../back_end/email_ers/_filter.html.erb | 11 + .../back_end/email_ers/_form.html.erb | 115 +++++++ .../back_end/email_ers/_form_file.html.erb | 37 ++ .../back_end/email_ers/_sort_headers.html.erb | 5 + .../back_end/email_ers/destroy.js.erb | 1 + .../er_email/back_end/email_ers/edit.html.erb | 6 + .../back_end/email_ers/index.html.erb | 28 ++ .../er_email/back_end/email_ers/index.js.erb | 4 + .../er_email/back_end/email_ers/new.html.erb | 6 + .../email_ers/realtime_preview.js.erb | 2 + .../er_email/back_end/email_ers/show.html.erb | 1 + .../fact_checks/_privilege_user.html.erb | 25 ++ .../er_email/config/locales/en.yml | 27 ++ .../er_email/config/locales/zh_tw.yml | 27 ++ .../er_email/config/routes.rb | 36 ++ .../er_email/er_email.gemspec | 23 ++ vendor/built_in_modules/er_email/init.rb | 55 +++ .../built_in_modules/er_email/lib/er_email.rb | 4 + .../er_email/lib/er_email/engine.rb | 4 + .../er_email/lib/er_email/version.rb | 3 + .../er_email/lib/tasks/er_email_tasks.rake | 4 + vendor/built_in_modules/er_email/script/rails | 8 + .../er_email/test/dummy/README.rdoc | 261 ++++++++++++++ .../er_email/test/dummy/Rakefile | 7 + .../app/assets/javascripts/application.js | 15 + .../app/assets/stylesheets/application.css | 13 + .../app/controllers/application_controller.rb | 3 + .../dummy/app/helpers/application_helper.rb | 2 + .../er_email/test/dummy/app/mailers/.gitkeep | 0 .../er_email/test/dummy/app/models/.gitkeep | 0 .../app/views/layouts/application.html.erb | 14 + .../er_email/test/dummy/config.ru | 4 + .../er_email/test/dummy/config/application.rb | 59 ++++ .../er_email/test/dummy/config/boot.rb | 10 + .../er_email/test/dummy/config/database.yml | 25 ++ .../er_email/test/dummy/config/environment.rb | 5 + .../dummy/config/environments/development.rb | 37 ++ .../dummy/config/environments/production.rb | 67 ++++ .../test/dummy/config/environments/test.rb | 37 ++ .../initializers/backtrace_silencers.rb | 7 + .../dummy/config/initializers/inflections.rb | 15 + .../dummy/config/initializers/mime_types.rb | 5 + .../dummy/config/initializers/secret_token.rb | 7 + .../config/initializers/session_store.rb | 8 + .../config/initializers/wrap_parameters.rb | 14 + .../er_email/test/dummy/config/locales/en.yml | 5 + .../er_email/test/dummy/config/routes.rb | 58 ++++ .../er_email/test/dummy/lib/assets/.gitkeep | 0 .../er_email/test/dummy/log/.gitkeep | 0 .../er_email/test/dummy/public/404.html | 26 ++ .../er_email/test/dummy/public/422.html | 26 ++ .../er_email/test/dummy/public/500.html | 25 ++ .../er_email/test/dummy/public/favicon.ico | 0 .../er_email/test/dummy/script/rails | 6 + .../er_email/test/er_email_test.rb | 7 + .../test/integration/navigation_test.rb | 10 + .../er_email/test/test_helper.rb | 15 + 108 files changed, 2887 insertions(+), 11 deletions(-) create mode 100644 app/controllers/sessions_controller.rb create mode 100644 vendor/built_in_modules/announcement/app/views/announcement_mailer/cron_mail.html.erb create mode 100644 vendor/built_in_modules/er_email/.gitignore create mode 100644 vendor/built_in_modules/er_email/Gemfile create mode 100644 vendor/built_in_modules/er_email/MIT-LICENSE create mode 100644 vendor/built_in_modules/er_email/README.rdoc create mode 100644 vendor/built_in_modules/er_email/Rakefile create mode 100644 vendor/built_in_modules/er_email/app/assets/images/er_email/.gitkeep create mode 100644 vendor/built_in_modules/er_email/app/assets/javascripts/er_email/.gitkeep create mode 100644 vendor/built_in_modules/er_email/app/assets/stylesheets/er_email/.gitkeep create mode 100644 vendor/built_in_modules/er_email/app/controllers/.gitkeep create mode 100644 vendor/built_in_modules/er_email/app/controllers/application_controller.rb create mode 100644 vendor/built_in_modules/er_email/app/controllers/panel/er_email/back_end/approvals_controller.rb create mode 100644 vendor/built_in_modules/er_email/app/controllers/panel/er_email/back_end/email_er_categorys_controller.rb create mode 100644 vendor/built_in_modules/er_email/app/controllers/panel/er_email/back_end/email_ers_controller.rb create mode 100644 vendor/built_in_modules/er_email/app/helpers/.gitkeep create mode 100644 vendor/built_in_modules/er_email/app/helpers/panel/er_email/back_end/email_er_categorys_helper.rb create mode 100644 vendor/built_in_modules/er_email/app/helpers/panel/er_email/back_end/email_ers_helper.rb create mode 100644 vendor/built_in_modules/er_email/app/mailers/.gitkeep create mode 100644 vendor/built_in_modules/er_email/app/models/.gitkeep create mode 100644 vendor/built_in_modules/er_email/app/models/email_er.rb create mode 100644 vendor/built_in_modules/er_email/app/models/email_er_category.rb create mode 100644 vendor/built_in_modules/er_email/app/models/email_er_file.rb create mode 100644 vendor/built_in_modules/er_email/app/views/.gitkeep create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/approvals/_modal_approve.html.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/approvals/_modal_list.html.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/approvals/preview_and_approve.js.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/approvals/setting.html.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/approvals/setting.js.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/approvals/update_setting.js.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/approvals/user_list.js.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/email_er_categorys/_email_er_category.html.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/email_er_categorys/_form.html.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/email_er_categorys/create.js.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/email_er_categorys/destroy.js.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/email_er_categorys/edit.js.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/email_er_categorys/index.html.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/email_er_categorys/new.js.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/email_er_categorys/update.js.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/email_ers/_clear_filters.html.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/email_ers/_email_er.html.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/email_ers/_filter.html.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/email_ers/_form.html.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/email_ers/_form_file.html.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/email_ers/_sort_headers.html.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/email_ers/destroy.js.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/email_ers/edit.html.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/email_ers/index.html.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/email_ers/index.js.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/email_ers/new.html.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/email_ers/realtime_preview.js.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/email_ers/show.html.erb create mode 100644 vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/fact_checks/_privilege_user.html.erb create mode 100644 vendor/built_in_modules/er_email/config/locales/en.yml create mode 100644 vendor/built_in_modules/er_email/config/locales/zh_tw.yml create mode 100644 vendor/built_in_modules/er_email/config/routes.rb create mode 100644 vendor/built_in_modules/er_email/er_email.gemspec create mode 100644 vendor/built_in_modules/er_email/init.rb create mode 100644 vendor/built_in_modules/er_email/lib/er_email.rb create mode 100644 vendor/built_in_modules/er_email/lib/er_email/engine.rb create mode 100644 vendor/built_in_modules/er_email/lib/er_email/version.rb create mode 100644 vendor/built_in_modules/er_email/lib/tasks/er_email_tasks.rake create mode 100755 vendor/built_in_modules/er_email/script/rails create mode 100644 vendor/built_in_modules/er_email/test/dummy/README.rdoc create mode 100644 vendor/built_in_modules/er_email/test/dummy/Rakefile create mode 100644 vendor/built_in_modules/er_email/test/dummy/app/assets/javascripts/application.js create mode 100644 vendor/built_in_modules/er_email/test/dummy/app/assets/stylesheets/application.css create mode 100644 vendor/built_in_modules/er_email/test/dummy/app/controllers/application_controller.rb create mode 100644 vendor/built_in_modules/er_email/test/dummy/app/helpers/application_helper.rb create mode 100644 vendor/built_in_modules/er_email/test/dummy/app/mailers/.gitkeep create mode 100644 vendor/built_in_modules/er_email/test/dummy/app/models/.gitkeep create mode 100644 vendor/built_in_modules/er_email/test/dummy/app/views/layouts/application.html.erb create mode 100644 vendor/built_in_modules/er_email/test/dummy/config.ru create mode 100644 vendor/built_in_modules/er_email/test/dummy/config/application.rb create mode 100644 vendor/built_in_modules/er_email/test/dummy/config/boot.rb create mode 100644 vendor/built_in_modules/er_email/test/dummy/config/database.yml create mode 100644 vendor/built_in_modules/er_email/test/dummy/config/environment.rb create mode 100644 vendor/built_in_modules/er_email/test/dummy/config/environments/development.rb create mode 100644 vendor/built_in_modules/er_email/test/dummy/config/environments/production.rb create mode 100644 vendor/built_in_modules/er_email/test/dummy/config/environments/test.rb create mode 100644 vendor/built_in_modules/er_email/test/dummy/config/initializers/backtrace_silencers.rb create mode 100644 vendor/built_in_modules/er_email/test/dummy/config/initializers/inflections.rb create mode 100644 vendor/built_in_modules/er_email/test/dummy/config/initializers/mime_types.rb create mode 100644 vendor/built_in_modules/er_email/test/dummy/config/initializers/secret_token.rb create mode 100644 vendor/built_in_modules/er_email/test/dummy/config/initializers/session_store.rb create mode 100644 vendor/built_in_modules/er_email/test/dummy/config/initializers/wrap_parameters.rb create mode 100644 vendor/built_in_modules/er_email/test/dummy/config/locales/en.yml create mode 100644 vendor/built_in_modules/er_email/test/dummy/config/routes.rb create mode 100644 vendor/built_in_modules/er_email/test/dummy/lib/assets/.gitkeep create mode 100644 vendor/built_in_modules/er_email/test/dummy/log/.gitkeep create mode 100644 vendor/built_in_modules/er_email/test/dummy/public/404.html create mode 100644 vendor/built_in_modules/er_email/test/dummy/public/422.html create mode 100644 vendor/built_in_modules/er_email/test/dummy/public/500.html create mode 100644 vendor/built_in_modules/er_email/test/dummy/public/favicon.ico create mode 100755 vendor/built_in_modules/er_email/test/dummy/script/rails create mode 100644 vendor/built_in_modules/er_email/test/er_email_test.rb create mode 100644 vendor/built_in_modules/er_email/test/integration/navigation_test.rb create mode 100644 vendor/built_in_modules/er_email/test/test_helper.rb diff --git a/Gemfile b/Gemfile index 16c820c9a..b5b5a9912 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,8 @@ source 'http://rubygems.org' gem 'rails', "~> 3.2.9" +gem 'savon', '~> 2.2.0' + gem "brakeman" gem 'mime-types' diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 000000000..c1a027d17 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,35 @@ +# encoding: utf-8 + +class SessionsController < Devise::SessionsController + prepend_before_filter :require_no_authentication, :only => [ :new, :create ] + + require 'savon' + + def create + + @sys_id = params["sys_id"] + + client = Savon.client(wsdl: 'http://sso.ntue.edu.tw/soap/soapserver.php?wsdl') + + client.operations + + response = client.call(:chkidno, message: { sys_id: @sys_id }) + + @id = response.body[:chkidno_response][:return][:id] + + login_uid = @id + + resource = User.first(conditions:{user_id: login_uid}) + + if !resource.blank? + resource_name = resource.class.to_s.downcase + sign_in(resource_name, resource) + redirect_to after_sign_in_path_for(resource) + else + flash[:error] = "很抱歉,您無此權限或帳號登入本站,請洽本站管理員
Sorry, you don't have the account or authority to login. Please contact the website administrator." + redirect_to :root + end + + end + +end \ No newline at end of file diff --git a/config/environments/development.rb b/config/environments/development.rb index 7daa02fc8..ba4f6fd1f 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -34,15 +34,15 @@ Orbit::Application.configure do # :sender_address => %{"notifier" }, # :exception_recipients => %w{chris@rulingcom.com} - config.action_mailer.delivery_method = :smtp - config.action_mailer.smtp_settings = { - :enable_starttls_auto => true, - :address => "smtp.gmail.com", - :port => '587', - :domain => "smtp.gmail.com", - :authentication => "plain", - :user_name => "redmine@rulingcom.com", - :password => "rulingredmine" } + # config.action_mailer.delivery_method = :smtp + # config.action_mailer.smtp_settings = { + # :enable_starttls_auto => true, + # :address => "smtp.gmail.com", + # :port => '587', + # :domain => "smtp.gmail.com", + # :authentication => "plain", + # :user_name => "redmine@rulingcom.com", + # :password => "rulingredmine" } end diff --git a/config/routes.rb b/config/routes.rb index 716918775..25e488432 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,6 +7,11 @@ Orbit::Application.routes.draw do match "/users_passwd" => "desktop/registrations#update", :as => :users_passwd, :via => :put end + devise_scope :user do + get 'soap_login' => 'sessions#create' + end + + mount Resque::Server, :at => "/admin/resque" mount Rack::GridFS::Endpoint.new(:db => Mongoid.database,:lookup=>:path), :at => "gridfs" diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/approvals_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/approvals_controller.rb index cb8da5db1..d2320fb02 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/approvals_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/approvals_controller.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 class Panel::Announcement::BackEnd::ApprovalsController < OrbitBackendController before_filter :authenticate_user! before_filter :is_admin? @@ -6,6 +7,7 @@ class Panel::Announcement::BackEnd::ApprovalsController < OrbitBackendControlle def preview_and_approve + email_group_data @bulletin = Bulletin.find params[:bulletin_id] end @@ -15,6 +17,14 @@ class Panel::Announcement::BackEnd::ApprovalsController < OrbitBackendControlle @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') @@ -61,6 +71,69 @@ class Panel::Announcement::BackEnd::ApprovalsController < OrbitBackendControlle 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 = [] diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb index e45ced1d6..edc7c012b 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController include OrbitControllerLib::DivisionForDisable @@ -77,6 +78,9 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController # GET /bulletins/new # GET /bulletins/new.xml def new + + email_group_data + if(session[:in_validate_object].blank?) @bulletin = Bulletin.new(:postdate => DateTime.now) else @@ -94,6 +98,9 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController # GET /bulletins/1/edit def edit + + email_group_data + @bulletin = Bulletin.find(params[:id]) if !current_user.admin? && (@bulletin.is_rejected? || @bulletin.is_checked?) redirect_to :action => :index @@ -146,6 +153,13 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController respond_to do |format| 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 + format.html { redirect_to(panel_announcement_back_end_bulletins_url, :notice => t('announcement.create_bulletin_success')) } format.xml { render :xml => @bulletin, :status => :created, :location => @bulletin } # format.js @@ -226,6 +240,14 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController @bulletin.is_rejected = false @bulletin.de_pending! end + + # if @bulletin.email_sent == true && @bulletin.is_checked == true && !@bulletin.is_rejected + # send_email_data(@bulletin) + + # @bulletin.email_sent = false + # @bulletin.save + # end + # if (params[:bulletin][:is_checked] == "false") # @bulletin.is_rejected = true # @bulletin.save! @@ -293,6 +315,69 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController protected + 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 delete_out_invalid_date_from_params if((params[:bulletin]["deadline(1i)"] && params[:bulletin]["deadline(1i)"].blank?) or (params[:bulletin]["deadline(2i)"] && params[:bulletin]["deadline(2i)"].blank?) or (params[:bulletin]["deadline(3i)"] && params[:bulletin]["deadline(3i)"].blank?)) params[:bulletin].delete("deadline(1i)") diff --git a/vendor/built_in_modules/announcement/app/models/bulletin.rb b/vendor/built_in_modules/announcement/app/models/bulletin.rb index 1771e2a69..5259a8d2e 100644 --- a/vendor/built_in_modules/announcement/app/models/bulletin.rb +++ b/vendor/built_in_modules/announcement/app/models/bulletin.rb @@ -40,6 +40,12 @@ class Bulletin field :not_checked_reason field :public, :type => Boolean, :default => true + + + field :email_sent, :type => Boolean, :default => false + field :email_sentdate , :type => DateTime + field :email_group, :type => Array + field :other_mailaddress scope :can_display, where(is_checked: true, is_rejected: false, is_pending: false) scope :available_for_lang, ->(locale){ where("available_for_#{locale}".to_sym => true) } @@ -215,8 +221,46 @@ class Bulletin preview_object end + def get_email_group_data(email_group_data) + + group_mail = Array.new + + self.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"]}(#{email_group_data[egroup]["name"]})" + + elsif email_group_data.include?(egroup) and egroup == '4' + + self.other_mailaddress.split(",").each do |otmail| + + group_mail << "#{otmail}(#{email_group_data[egroup]["name"]})" + + end + + end + + end + + group_mail.join("
").html_safe + + end + protected + + def self.email_group_data + + @email_group_data = { + '0'=> {"name"=>I18n.t('announcement.email_group_data_0'), "email"=>"alluser@tea.ntue.edu.tw"}, + '1'=> {"name"=>I18n.t('announcement.email_group_data_1'), "email"=>"allstu@tea.ntue.edu.tw"}, + '2'=> {"name"=>I18n.t('announcement.email_group_data_2'), "email"=>"allgrad@tea.ntue.edu.tw"}, + '3'=> {"name"=>I18n.t('announcement.email_group_data_3'), "email"=>"allad@tea.ntue.edu.tw"}, + '4'=> {"name"=>I18n.t('announcement.email_group_data_4')} + } + + end def check_deadline if(!self.deadline.nil? and (self.deadline < self.postdate )) diff --git a/vendor/built_in_modules/announcement/app/views/announcement_mailer/cron_mail.html.erb b/vendor/built_in_modules/announcement/app/views/announcement_mailer/cron_mail.html.erb new file mode 100644 index 000000000..fbf7e0b1c --- /dev/null +++ b/vendor/built_in_modules/announcement/app/views/announcement_mailer/cron_mail.html.erb @@ -0,0 +1,29 @@ +<% # encoding: utf-8 %> + + + + + + +
+
+ + <%= t('announcement.mail_hi') %>

+ <%= t('announcement.mail_url_view') %>

+ " target="_blank"> <%= @data.mail_content["title"] %>

+ + --
+ <%= t('announcement.mail_source') %> :" target="_blank"> <%= @data.mail_content["site_title"] %>
+ <%= t('announcement.mail_time') %> <%= DateTime.now %> +
+ + + + + + + + + + + \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/approvals/_modal_approve.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/approvals/_modal_approve.html.erb index 797757a58..bed04d202 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/approvals/_modal_approve.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/approvals/_modal_approve.html.erb @@ -14,6 +14,12 @@ <%# preview_block_ad_images_helper(bulletin).each do |ad_image| -%> <%#= image_tag ad_image.file,:alt => (ad_image.title[locale] || " "),:time_to_next => bulletin.transition_msec,:link_open=> ad_image.link_open, :link_url =>((ad_image.out_link || bulletin.context || " ")) %> <%# end -%> + + <% if !@bulletin.email_group.blank? %> + <%= label_tag 'group_mail' %> + <%= @bulletin.get_email_group_data(@email_group_data) %> + <% end %> +

+ + +
+
+ +
+

<%= t('announcement.email_eminder')%>

+
+
+ +
+
+ + <%#= f.datetime_picker :email_sentdate, :picker_type => 'separated', :label => t("announcement.email_sentdate") %> + +
+ + <%= f.label :email_group ,t("announcement.email_group")%> +
+ +
+ + + <%= f.label :other_mailaddress ,"#{t("announcement.other_mailaddress")}(#{t("announcement.other_mailaddress_note")})"%> + <%= f.text_area :other_mailaddress, :class=>"span12", :cols=>"25", :rows=>"10" %> + +
+ + + + +
+
+
+ + @@ -300,6 +344,11 @@ $(this).parents('table').append(("<%= escape_javascript(add_attribute 'form_bulletin_file', f, :bulletin_files) %>").replace(old_id, new_id)); }); $('.for_preview').popover({ html : true }); + + $('#remind-check').prop('checked') ? '':$('#content-box').addClass('hide') + $('#remind-check').on('change', function() { + $(this).prop('checked') ? $('#content-box').removeClass('hide'):$('#content-box').addClass('hide') + }) }); <% end %> diff --git a/vendor/built_in_modules/announcement/config/locales/en.yml b/vendor/built_in_modules/announcement/config/locales/en.yml index ce6569678..b6a747a4e 100644 --- a/vendor/built_in_modules/announcement/config/locales/en.yml +++ b/vendor/built_in_modules/announcement/config/locales/en.yml @@ -37,4 +37,21 @@ en: widget: bulletins_and_web_links: Differential Nav. index: Index - search: Search \ No newline at end of file + search: Search + email_eminder: Email Reminder + activate_email_eminder: Activate Email Reminder + email_sentdate: Email Time + email_group: Email Group + email_group_data_0: All Faculty + email_group_data_1: Undergraduates + email_group_data_2: Postgraduates + email_group_data_3: Continuing Ed. Postgraduates + email_group_data_4: Other + mail_subject: this is an announcement reminder from【%{site_title}】 + other_mailaddress: Other Email + other_mailaddress_note: Divide different email accounts with "," + mail_hi: Hi + mail_url_view: This email is the reminder of an announcement, please click the link for the details + mail_source: Source + mail_time: Time + diff --git a/vendor/built_in_modules/announcement/config/locales/zh_tw.yml b/vendor/built_in_modules/announcement/config/locales/zh_tw.yml index b3bf356f9..7c29cab3d 100644 --- a/vendor/built_in_modules/announcement/config/locales/zh_tw.yml +++ b/vendor/built_in_modules/announcement/config/locales/zh_tw.yml @@ -37,4 +37,22 @@ zh_tw: widget: bulletins_and_web_links: 分眾頁籤 index: 索引 - search: 搜尋 \ No newline at end of file + search: 搜尋 + email_eminder: 寄送提醒 + activate_email_eminder: 開啟寄送提醒 + email_sentdate: 寄送時間 + email_group: 寄送群組 + other_mailaddress: 其他Mail + other_mailaddress_note: 輸入多組mail時,請用","逗號隔開 + email_group_data_0: 全校教職員 + email_group_data_1: 大學部學生 + email_group_data_2: 日間部研究生 + email_group_data_3: 進修部研究生 + email_group_data_4: 其他 + mail_subject: 來自【%{site_title}】的公告事件提醒 + mail_hi: 您好 + mail_url_view: 此封信件為公告事件提醒,請點選以下連結詳細觀看 + mail_source: 來源 + mail_time: 時間 + + diff --git a/vendor/built_in_modules/er_email/.gitignore b/vendor/built_in_modules/er_email/.gitignore new file mode 100644 index 000000000..1dfe31e60 --- /dev/null +++ b/vendor/built_in_modules/er_email/.gitignore @@ -0,0 +1,7 @@ +.bundle/ +log/*.log +pkg/ +test/dummy/db/*.sqlite3 +test/dummy/log/*.log +test/dummy/tmp/ +test/dummy/.sass-cache diff --git a/vendor/built_in_modules/er_email/Gemfile b/vendor/built_in_modules/er_email/Gemfile new file mode 100644 index 000000000..e9d2bcf38 --- /dev/null +++ b/vendor/built_in_modules/er_email/Gemfile @@ -0,0 +1,17 @@ +source "http://rubygems.org" + +# Declare your gem's dependencies in er_email.gemspec. +# Bundler will treat runtime dependencies like base dependencies, and +# development dependencies will be added by default to the :development group. +gemspec + +# jquery-rails is used by the dummy application +gem "jquery-rails" + +# Declare any dependencies that are still in development here instead of in +# your gemspec. These might include edge Rails or gems from your path or +# Git. Remember to move these dependencies to your gemspec before releasing +# your gem to rubygems.org. + +# To use debugger +# gem 'debugger' diff --git a/vendor/built_in_modules/er_email/MIT-LICENSE b/vendor/built_in_modules/er_email/MIT-LICENSE new file mode 100644 index 000000000..5146945d9 --- /dev/null +++ b/vendor/built_in_modules/er_email/MIT-LICENSE @@ -0,0 +1,20 @@ +Copyright 2013 YOURNAME + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/built_in_modules/er_email/README.rdoc b/vendor/built_in_modules/er_email/README.rdoc new file mode 100644 index 000000000..5e75970bb --- /dev/null +++ b/vendor/built_in_modules/er_email/README.rdoc @@ -0,0 +1,3 @@ += ErEmail + +This project rocks and uses MIT-LICENSE. \ No newline at end of file diff --git a/vendor/built_in_modules/er_email/Rakefile b/vendor/built_in_modules/er_email/Rakefile new file mode 100644 index 000000000..a021c8b42 --- /dev/null +++ b/vendor/built_in_modules/er_email/Rakefile @@ -0,0 +1,40 @@ +#!/usr/bin/env rake +begin + require 'bundler/setup' +rescue LoadError + puts 'You must `gem install bundler` and `bundle install` to run rake tasks' +end +begin + require 'rdoc/task' +rescue LoadError + require 'rdoc/rdoc' + require 'rake/rdoctask' + RDoc::Task = Rake::RDocTask +end + +RDoc::Task.new(:rdoc) do |rdoc| + rdoc.rdoc_dir = 'rdoc' + rdoc.title = 'ErEmail' + rdoc.options << '--line-numbers' + rdoc.rdoc_files.include('README.rdoc') + rdoc.rdoc_files.include('lib/**/*.rb') +end + +APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__) +load 'rails/tasks/engine.rake' + + + +Bundler::GemHelper.install_tasks + +require 'rake/testtask' + +Rake::TestTask.new(:test) do |t| + t.libs << 'lib' + t.libs << 'test' + t.pattern = 'test/**/*_test.rb' + t.verbose = false +end + + +task :default => :test diff --git a/vendor/built_in_modules/er_email/app/assets/images/er_email/.gitkeep b/vendor/built_in_modules/er_email/app/assets/images/er_email/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/vendor/built_in_modules/er_email/app/assets/javascripts/er_email/.gitkeep b/vendor/built_in_modules/er_email/app/assets/javascripts/er_email/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/vendor/built_in_modules/er_email/app/assets/stylesheets/er_email/.gitkeep b/vendor/built_in_modules/er_email/app/assets/stylesheets/er_email/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/vendor/built_in_modules/er_email/app/controllers/.gitkeep b/vendor/built_in_modules/er_email/app/controllers/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/vendor/built_in_modules/er_email/app/controllers/application_controller.rb b/vendor/built_in_modules/er_email/app/controllers/application_controller.rb new file mode 100644 index 000000000..307a4acd8 --- /dev/null +++ b/vendor/built_in_modules/er_email/app/controllers/application_controller.rb @@ -0,0 +1,23 @@ +class ApplicationController < ActionController::Base + protect_from_forgery + before_filter :set_locale + + # Set I18n.locale + def set_locale + # update session if passed + session[:locale] = params[:locale] if params[:locale] + + # set locale based on session or default + begin + # check if locale is valid for non site pages + if !VALID_LOCALES.include?(session[:locale]) + I18n.locale = I18n.default_locale + else + I18n.locale = session[:locale] + end + rescue + I18n.locale = I18n.default_locale + end + end + +end diff --git a/vendor/built_in_modules/er_email/app/controllers/panel/er_email/back_end/approvals_controller.rb b/vendor/built_in_modules/er_email/app/controllers/panel/er_email/back_end/approvals_controller.rb new file mode 100644 index 000000000..70883ce7f --- /dev/null +++ b/vendor/built_in_modules/er_email/app/controllers/panel/er_email/back_end/approvals_controller.rb @@ -0,0 +1,145 @@ +class Panel::ErEmail::BackEnd::ApprovalsController < OrbitBackendController + before_filter :authenticate_user! + before_filter :is_admin? + include AdminHelper + # layout 'admin' + + + def preview_and_approve + email_group_data + @email_er = EmailEr.find params[:email_er_id] + end + + def approve + notice = "" + @email_er = EmailEr.find params[:email_er_id] + @email_er.proc_check(params[:email_er][:is_checked],params[:email_er][:not_checked_reason]) + @email_er.de_pending + if @email_er.save + + if @email_er.is_checked == true and !@email_er.is_rejected + send_email_data(@email_er) + end + + notice = t('er_email.approve_email_er_success') + else + notice = t('er_email.approve_email_er_fail') + end + redirect_to(panel_er_email_back_end_email_ers_url,:notice => notice) + end + + def setting + @sys_users = User.all(conditions: {admin: false}).includes(:avatar).not_guest_user + @email_er_categorys = EmailErCategory.all + @options_from_collection_for_select_email_er_categorys = @email_er_categorys.collect{|bc| [bc.title,bc.id] } + if params.has_key? :category + @email_er_category = EmailErCategory.find params[:category][:id] + else + @email_er_category = @email_er_categorys.first + end + preload_object_auth = @email_er_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 + @email_er_category = EmailErCategory.find params[:category][:id] + end + + protected + def update_setting_by_params + category = EmailErCategory.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(email_er) + + @user = User.find(email_er.create_user_id) + + email_group_data + + @group_mail = Array.new + + email_er.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 << email_er.other_mailaddress + + end + + end + + if !@group_mail.join.blank? + + @mail_content = { + "text" => email_er.mail_content + } + + @mail_cron = { + :mail_from_app => 'er_email', + :mail_from => @user.email, + :mail_reply_to => @user.email, + :mail_subject => email_er.mail_subject, + :mail_to => @group_mail.join(','), + :mail_content => @mail_content , + # :mail_sentdate => email_er.mail_sentdate, + :mail_sentdate => DateTime.now, + :create_user_id => email_er.create_user_id, + :update_user_id => email_er.create_user_id + } + + @mail_cron = MailCron.new(@mail_cron) + + email_er.email_er_files.each do | mrfile | + + @mcfile = @mail_cron.mail_cron_files.build + + tmp_file = File.new(mrfile.file_identifier, 'w+') + + tmp_file.write(Mongo::GridFileSystem.new(Mongoid.database).open(mrfile.file.url.gsub("/gridfs/", ""), 'r').read.force_encoding("UTF-8")) + + @mcfile.file = tmp_file + + @mcfile.title = mrfile.title + + # delete file + FileUtils.rm_f(tmp_file) + + end + + @mail_cron.save + + MailCron.send_mail_now(@mail_cron.id) + + end + + end + + def email_group_data + + @email_group_data = EmailEr.email_group_data + + end + +end diff --git a/vendor/built_in_modules/er_email/app/controllers/panel/er_email/back_end/email_er_categorys_controller.rb b/vendor/built_in_modules/er_email/app/controllers/panel/er_email/back_end/email_er_categorys_controller.rb new file mode 100644 index 000000000..e1bd71c4f --- /dev/null +++ b/vendor/built_in_modules/er_email/app/controllers/panel/er_email/back_end/email_er_categorys_controller.rb @@ -0,0 +1,128 @@ +class Panel::ErEmail::BackEnd::EmailErCategorysController < OrbitBackendController + include OrbitControllerLib::DivisionForDisable + + before_filter :for_app_manager,:except => [:index,:get_categorys_json] + before_filter :force_order_for_visitor,:only=>[:index,:get_categorys_json] + before_filter :force_order_for_user,:except => [:index,:get_categorys_json] + before_filter :for_app_sub_manager,:except => [:index,:get_categorys_json] + + + def index + @email_er_categorys = get_categories_for_index("EmailErCategory") + @email_er_category = EmailErCategory.new(:display => 'List') + + @url = panel_er_email_back_end_email_er_categorys_path + + respond_to do |format| + format.html # index.html.erb + format.js + end + end + + def get_categorys_json + categorys = EmailErCategory.all + data = Array.new + + categorys.each do |c| + data << { + category: c.title, + link: "#{url_for( :action => "index", + :controller => "panel/er_email/back_end/email_ers", + :format => :rss, + :only_path => false, + :inner=>true, + :category_id => c )}" + } + end + render :json => JSON.pretty_generate(data) + end + + # GET /email_ers/1 + # GET /email_ers/1.xml + def show + @email_er_category = EmailErCategory.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.js + end + end + + # GET /email_ers/new + # GET /email_ers/new.xml + def new + @email_er_category = EmailErCategory.new(:display => 'List') + + respond_to do |format| + format.html # new.html.erb + format.js + end + end + + # GET /email_ers/1/edit + def edit + @email_er_category = EmailErCategory.find(params[:id]) + + @url = panel_er_email_back_end_email_er_category_path(@email_er_category) + + respond_to do |format| + format.html + format.js + end + end + + # POST /email_ers + # POST /email_ers.xml + def create + @email_er_category = EmailErCategory.new(params[:email_er_category]) + + respond_to do |format| + if @email_er_category.save + format.html { redirect_to(panel_er_email_back_end_email_er_categorys_url, :notice => t('email_er_category.create_email_er_category_success')) } + format.js + else + format.html { render :action => "new" } + format.js { render action: "new" } + end + end + end + + # PUT /email_ers/1 + # PUT /email_ers/1.xml + def update + @email_er_category = EmailErCategory.find(params[:id]) + + @url = panel_er_email_back_end_email_er_category_path(@email_er_category) + + respond_to do |format| + if @email_er_category.update_attributes(params[:email_er_category]) + format.html { redirect_to(panel_er_email_back_end_email_er_categorys_url, :notice => t('email_er_category.update_email_er_category_success')) } + # format.xml { head :ok } + format.js + else + format.html { render :action => "edit" } + format.js { render :action => "edit" } + end + end + end + + # DELETE /email_ers/1 + # DELETE /email_ers/1.xml + def destroy + @email_er_category = EmailErCategory.find(params[:id]) + @email_er_category.disable = @email_er_category.disable ? false : true + + if @email_er_category.save! + respond_to do |format| + flash[:notice] = t("update.success_") + # flash[:error] += @email_er_category.disable ? t(:enable) : t(disable) + format.html { redirect_to(panel_er_email_back_end_email_er_categorys_url) } + # format.xml { head :ok } + format.js + end + else + flash[:error] = t("update.fail") + format.html { render :action => "index" } + end + end +end diff --git a/vendor/built_in_modules/er_email/app/controllers/panel/er_email/back_end/email_ers_controller.rb b/vendor/built_in_modules/er_email/app/controllers/panel/er_email/back_end/email_ers_controller.rb new file mode 100644 index 000000000..d2d2fb863 --- /dev/null +++ b/vendor/built_in_modules/er_email/app/controllers/panel/er_email/back_end/email_ers_controller.rb @@ -0,0 +1,318 @@ +class Panel::ErEmail::BackEnd::EmailErsController < OrbitBackendController + # before_filter :for_app_manager,:except => [:index,:show] + include OrbitControllerLib::DivisionForDisable + + + before_filter :force_order_for_user + + + before_filter :only => [ :new,:edit,:update,:create] do |controller| + controller.get_categorys('EmailErCategory') + end + + def preview + email_er = EmailEr.new params + @preview_obj = email_er.to_preview + @preview_obj.save + render '/shared/preview/preview.html.erb',:layout=>false + end + + def index + + get_categorys("EmailErCategory",params[:email_er_category_id]) + + email_group_data + + @filter = params[:filter] + new_filter = params[:new_filter] + + if @filter && params[:clear] + @filter.delete(params[:type]) + elsif @filter && new_filter + if @filter.has_key?(new_filter[:type]) && @filter[new_filter[:type]].include?(new_filter[:id].to_s) + @filter[new_filter[:type]].delete(new_filter[:id].to_s) + elsif @filter.has_key?(new_filter[:type]) + @filter[new_filter[:type]] << new_filter[:id].to_s + else + @filter.merge!({new_filter[:type] => [new_filter[:id].to_s]}) + end + elsif new_filter + @filter = {new_filter[:type] => [new_filter[:id].to_s]} + end + + @email_er_categories = get_categories_for_index("EmailErCategory") + @email_er_category_ids = @email_er_categories.collect{|t| t.id.to_s} + [nil] + + @email_ers = (params[:sort] || @filter) ? get_sorted_and_filtered("email_er",:email_er_category_id.in => @email_er_category_ids) : get_viewable("email_er",:email_er_category_id.in => @email_er_category_ids) + + respond_to do |format| + format.html # index.html.erb + format.xml { render :xml => @email_ers } + format.js + end + end + + # GET /email_ers/1 + # GET /email_ers/1.xml + + def show + + email_group_data + + @item = Page.find(params[:page_id]) rescue nil + if params[:preview] == "true" + preview_content + else + @email_er = EmailEr.all.can_display.where(_id: params[:id]).first + if @email_er and !@email_er.disable? and !@email_er.is_rejected + if @email_er.enabled_for_lang(I18n.locale.to_s) + delayed_impressionist(@email_er) + # get_categorys + else + render :text => "
#{t('sys.can_not_display_due_to_no_context')}
".html_safe + end + else + render :nothing => true, :status => 403 + end + end + + end + + def preview_content + @email_er = EmailEr.find params[:id] rescue nil + @email_er = Preview.find(params[:id]).get_virtual_object if @email_er.nil? + # get_categorys + end + + # GET /email_ers/new + # GET /email_ers/new.xml + def new + + email_group_data + + @email_er = EmailEr.new(:mail_sentdate => DateTime.now) + + respond_to do |format| + format.html # new.html.erb + format.xml { render :xml => @email_er } + end + end + + # GET /email_ers/1/edit + def edit + + email_group_data + + @email_er = EmailEr.find(params[:id]) + + end + + # POST /email_ers + # POST /email_ers.xml + def create + + email_group_data + + @email_er = EmailEr.new(params[:email_er]) + @email_er.create_user_id = current_user.id + @email_er.update_user_id = current_user.id + + if(is_manager? || is_admin?) + @email_er.is_checked = true + @email_er.is_rejected = false + @email_er.de_pending + end + + respond_to do |format| + if @email_er.save + + # if @email_er.is_checked == true and !@email_er.is_rejected + # send_email_data(@email_er) + # end + + format.html { redirect_to(panel_er_email_back_end_email_ers_url) } + format.xml { render :xml => @email_er, :status => :created, :location => @email_er } + # format.js + format.js { + @info = {"success"=>"true","redirect_url"=>panel_er_email_back_end_email_ers_url} + flash[:notice] = t('er_email.create_er_email_success') + render "/shared/preview/after_create.js.erb" + } + else + format.html { render :action => "new" } + format.xml { render :xml => @email_er.errors, :status => :unprocessable_entity } + format.js { + @info = {"success"=>"false","redirect_url"=>new_panel_er_email_back_end_email_er_url(:email_er => @email_er)} + session[:in_validate_object] = @email_er + render "/shared/preview/after_create.js.erb" + } + end + end + end + + # PUT /email_ers/1 + # PUT /email_ers/1.xml + def update + + email_group_data + + @email_er = EmailEr.find(params[:id]) + + @email_er.update_user_id = current_user.id + + respond_to do |format| + if @email_er.update_attributes(params[:email_er]) + + if(is_manager? || is_admin?) + @email_er.is_checked = true + @email_er.is_rejected = false + @email_er.de_pending! + end + + if @email_er.is_checked == true and !@email_er.is_rejected + send_email_data(@email_er) + end + + format.html { redirect_to(panel_er_email_back_end_email_ers_url(:page => params[:page])) } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @email_er.errors, :status => :unprocessable_entity } + end + end + end + + # DELETE /email_ers/1 + # DELETE /email_ers/1.xml + def destroy + @email_er = EmailEr.find(params[:id]) + @email_er.destroy + + respond_to do |format| + format.html { redirect_to(panel_er_email_back_end_email_ers_url) } + # format.xml { head :ok } + format.js + end + end + + def delete + if params[:ids] + # email_ers = EmailEr.any_in(:_id => params[:ids]).destroy_all + end + redirect_to panel_er_email_back_end_email_ers_url(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]) + end + + def email_resend + if params[:id] + @email_er = EmailEr.find(params[:id]) + + @email_er.is_checked = false + @email_er.is_pending = true + + @email_er.save + + end + redirect_to panel_er_email_back_end_email_ers_url(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]) + end + + def test_send_email + if params[:id] + @email_er = EmailEr.find(params[:id]) + + if (@email_er.create_user_id == current_or_guest_user.id) || is_manager? + if current_or_guest_user.admin? || (!@email_er.is_rejected? && !@email_er.is_checked?) + if @email_er.is_pending + send_email_data( @email_er , true ) + end + end + end + end + redirect_to panel_er_email_back_end_email_ers_url(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]) + end + + protected + + def send_email_data(email_er , test_send = false) + + @user = User.find(email_er.create_user_id) + + if !test_send + + email_group_data + + @group_mail = Array.new + + email_er.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 << email_er.other_mailaddress + + end + + end + + else + + # @group_mail = ["spen@rulingcom.com"] + @group_mail = [@user.email] + + end + + if !@group_mail.join.blank? + + @mail_content = { + "text" => email_er.mail_content + } + + @mail_cron = { + :mail_from_app => 'er_email', + :mail_from => @user.email, + :mail_reply_to => @user.email, + :mail_subject => email_er.mail_subject, + :mail_to => @group_mail.join(','), + :mail_content => @mail_content , + # :mail_sentdate => email_er.mail_sentdate, + :mail_sentdate => DateTime.now, + :create_user_id => email_er.create_user_id, + :update_user_id => email_er.create_user_id + } + + @mail_cron = MailCron.new(@mail_cron) + + email_er.email_er_files.each do | mrfile | + + @mcfile = @mail_cron.mail_cron_files.build + + tmp_file = File.new(mrfile.file_identifier, 'w+') + + tmp_file.write(Mongo::GridFileSystem.new(Mongoid.database).open(mrfile.file.url.gsub("/gridfs/", ""), 'r').read.force_encoding("UTF-8")) + + @mcfile.file = tmp_file + + @mcfile.title = mrfile.title + + # delete file + FileUtils.rm_f(tmp_file) + + end + + @mail_cron.save + + MailCron.send_mail_now(@mail_cron.id) + + end + + end + + def email_group_data + + @email_group_data = EmailEr.email_group_data + + end + +end diff --git a/vendor/built_in_modules/er_email/app/helpers/.gitkeep b/vendor/built_in_modules/er_email/app/helpers/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/vendor/built_in_modules/er_email/app/helpers/panel/er_email/back_end/email_er_categorys_helper.rb b/vendor/built_in_modules/er_email/app/helpers/panel/er_email/back_end/email_er_categorys_helper.rb new file mode 100644 index 000000000..ceeaf9cdc --- /dev/null +++ b/vendor/built_in_modules/er_email/app/helpers/panel/er_email/back_end/email_er_categorys_helper.rb @@ -0,0 +1,16 @@ +module Panel::ErEmail::BackEnd::EmailErCategorysHelper +include ActionView::Helpers::UrlHelper + + + def show_anc_cate_permission_link(email_er_category) + type = 'submit' + oa = email_er_category.get_object_auth_by_title(type) + if oa.nil? + email_er_category.object_auths.new(title: type ).save + oa = email_er_category.get_object_auth_by_title(type) + end +# link_to t(:category_auth), edit_admin_object_auth_path(oa) + link_to t(:category_auth),admin_object_auth_ob_auth_path(oa) + end + +end \ No newline at end of file diff --git a/vendor/built_in_modules/er_email/app/helpers/panel/er_email/back_end/email_ers_helper.rb b/vendor/built_in_modules/er_email/app/helpers/panel/er_email/back_end/email_ers_helper.rb new file mode 100644 index 000000000..9b9df0a71 --- /dev/null +++ b/vendor/built_in_modules/er_email/app/helpers/panel/er_email/back_end/email_ers_helper.rb @@ -0,0 +1,58 @@ +module Panel::ErEmail::BackEnd::EmailErsHelper + def show_reject_reason(email_er) + by_email_er = email_er.is_rejected + by_user = (((email_er.create_user_id == current_user.id) rescue nil) or is_manager? or is_admin?) + by_email_er && by_user + end + + def show_form_status_field(email_er) + #by_email_er = (!email_er.is_expired? and email_er.is_pending?) + by_user = ((email_er.email_er_category.authed_users('fact_check').include?(current_user) rescue nil) or is_manager? or is_admin?) + by_user + end + + def show_approval_link(email_er) + by_email_er = (email_er.is_pending?) + by_user = ((email_er.email_er_category.authed_users('fact_check').include?(current_user) rescue nil) or is_manager? or is_admin?) + by_email_er and by_user + end + + def show_delete_link(email_er) + if !current_user.nil? + by_email_er = (email_er.create_user_id == current_user.id ) + by_user = (is_manager? or is_admin?) + by_email_er or by_user + else + false + end + + end + + def show_email_er_title_at_index (email_er) + if email_er.is_checked? + link_to email_er.title, panel_er_email_front_end_email_er_path(email_er, :category_id => email_er.email_er_category.id) rescue '' + else + email_er.title + end + end + + def file_picture_preview_setting(file_path) + ext = File.extname(file_path)[1..-1].downcase + unless file_path.nil? + case ext + when "jpg","jpeg","png","gif" + {"data-content" => "#{image_tag file_path}" } + when "pdf", "zip", "rar" + {"data-content" => "#{image_tag("http://#{request.host_with_port}/assets/ft-icons/#{ext}/#{ext}-64_32.png")}"} + when "doc", "docx" + {"data-content" => "#{image_tag("http://#{request.host_with_port}/assets/ft-icons/docx_mac/docx_mac-64_32.png")}"} + when "xls", "xlsx" + {"data-content" => "#{image_tag("http://#{request.host_with_port}/assets/ft-icons/xlsx_mac/xlsx_mac-64_32.png")}"} + when "ppt", "pptx" + {"data-content" => "#{image_tag("http://#{request.host_with_port}/assets/ft-icons/pptx_mac/pptx_mac-64_32.png")}"} + else + {"data-content" => t("sys.not_previewable") } + end + end + end +end diff --git a/vendor/built_in_modules/er_email/app/mailers/.gitkeep b/vendor/built_in_modules/er_email/app/mailers/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/vendor/built_in_modules/er_email/app/models/.gitkeep b/vendor/built_in_modules/er_email/app/models/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/vendor/built_in_modules/er_email/app/models/email_er.rb b/vendor/built_in_modules/er_email/app/models/email_er.rb new file mode 100644 index 000000000..a3faaa180 --- /dev/null +++ b/vendor/built_in_modules/er_email/app/models/email_er.rb @@ -0,0 +1,123 @@ +# encoding: utf-8 + +class EmailEr + include Mongoid::Document + include Mongoid::Timestamps + include Mongoid::MultiParameterAttributes + + include OrbitCoreLib::Preview + + BelongsToCategory = :email_er_category + include OrbitCoreLib::BelongsToCategoryMayDisable + + PAYMENT_TYPES = @site_valid_locales + + field :mail_subject + field :mail_sentdate , :type => DateTime + field :mail_content + + field :create_user_id + field :update_user_id + + field :is_checked, :type => Boolean, :default => false + field :is_pending, :type => Boolean, :default => true + field :is_rejected, :type => Boolean, :default => false + + field :not_checked_reason + + field :email_group, :type => Array + field :other_mailaddress + + scope :can_display,where(is_hidden: false) + + has_many :email_er_files, :autosave => true, :dependent => :destroy + + accepts_nested_attributes_for :email_er_files, :allow_destroy => true + + validates :mail_subject,presence:{message:'blank is not allowed'} + validates :other_mailaddress, + :length => {:maximum => 1000, :message => I18n.t("er_email.other_mailaddress_note_limit")} + + def proc_check(check,not_pass_info = "") + self.is_checked = true + if check =="true" + self.is_rejected = false + elsif check == "false" + self.is_rejected = true + self.not_checked_reason = not_pass_info + end + end + + def de_pending + self.is_pending = false + end + + def de_pending! + de_pending + self.save! + end + + def is_checked? + !self.is_pending && self.is_checked && (self.is_rejected == false) + end + + def is_pending? + self.is_pending + end + + def is_rejected? + !self.is_pending && self.is_rejected && (self.is_rejected == true) + end + + def get_email_group_data(email_group_data) + + group_mail = Array.new + + self.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"]}(#{email_group_data[egroup]["name"]})" + + elsif email_group_data.include?(egroup) and egroup == '4' + + self.other_mailaddress.split(",").each do |otmail| + + group_mail << "#{otmail}(#{email_group_data[egroup]["name"]})" + + end + + end + + end + + group_mail.join("
").html_safe + + end + + def to_preview + preview_object = Preview.new(:expired_at=>DateTime.now+30.minutes,:preview_at_link=>"panel_er_email_back_end_email_er_path",:object_class_type=>"EmailEr") + + self.email_er["email_er_files_attributes"].each_with_index do |atr,idx| + preview_object.preview_files.build(:file=>self.email_er["email_er_files_attributes"][idx.to_s],:field_name_for_rebuild=>'email_er_files',:file_in_array=>true) + end unless self.email_er["email_er_files_attributes"].nil? + + preview_object.object = self.email_er.except("email_er_files_attributes") + preview_object + end + + protected + + def self.email_group_data + + @email_group_data = { + '0'=> {"name"=>I18n.t('er_email.email_group_data_0'), "email"=>"alluser@tea.ntue.edu.tw"}, + '1'=> {"name"=>I18n.t('er_email.email_group_data_1'), "email"=>"allstu@tea.ntue.edu.tw"}, + '2'=> {"name"=>I18n.t('er_email.email_group_data_2'), "email"=>"allgrad@tea.ntue.edu.tw"}, + '3'=> {"name"=>I18n.t('er_email.email_group_data_3'), "email"=>"allad@tea.ntue.edu.tw"}, + '4'=> {"name"=>I18n.t('er_email.email_group_data_4')} + } + + end + +end \ No newline at end of file diff --git a/vendor/built_in_modules/er_email/app/models/email_er_category.rb b/vendor/built_in_modules/er_email/app/models/email_er_category.rb new file mode 100644 index 000000000..ff392e0e0 --- /dev/null +++ b/vendor/built_in_modules/er_email/app/models/email_er_category.rb @@ -0,0 +1,47 @@ +# encoding: utf-8 + +class EmailErCategory + include Mongoid::Document + include Mongoid::Timestamps + include OrbitCoreLib::ObjectAuthable + include OrbitCoreLib::ObjectDisable + include Sunspot::Mongo + # include Mongoid::MultiParameterAttributes + APP_NAME = 'ErEmail' + ObjectAuthTitlesOptions = %W{submit_new fact_check} + AfterObjectAuthUrl = '/panel/er_email/back_end/email_er_categorys' + + field :disable, type: Boolean, :default => false + field :display + field :key + field :title, localize: true + + has_many :email_ers + + validates :title, :at_least_one => true + + searchable do + text :titles do + title_translations.to_a.collect{|t| t[1]} + end + + boolean :frontend_search do + !disable + end + + text :files do + email_ers.can_display.collect{|t| t.title_translations.to_a.collect{|t| t[1]}} + end + + end + + + def pp_object + title + end + + def self.from_id(id) + EmailErCategory.find(id) rescue nil + end + +end \ No newline at end of file diff --git a/vendor/built_in_modules/er_email/app/models/email_er_file.rb b/vendor/built_in_modules/er_email/app/models/email_er_file.rb new file mode 100644 index 000000000..4e5d176e2 --- /dev/null +++ b/vendor/built_in_modules/er_email/app/models/email_er_file.rb @@ -0,0 +1,23 @@ +class EmailErFile + + include Mongoid::Document + include Mongoid::Timestamps + + mount_uploader :file, AssetUploader + + field :should_destroy, :type => Boolean + field :title + + belongs_to :email_er + + validate :file_size + + private + + def file_size + if file.file.size > 1.megabytes + errors.add( :file, I18n.t("er_email.email_file_limit")) + end + end + +end diff --git a/vendor/built_in_modules/er_email/app/views/.gitkeep b/vendor/built_in_modules/er_email/app/views/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/approvals/_modal_approve.html.erb b/vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/approvals/_modal_approve.html.erb new file mode 100644 index 000000000..29f3610dd --- /dev/null +++ b/vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/approvals/_modal_approve.html.erb @@ -0,0 +1,68 @@ + <% if email_er -%> + + + + + +<% end -%> diff --git a/vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/approvals/_modal_list.html.erb b/vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/approvals/_modal_list.html.erb new file mode 100644 index 000000000..fb84ddeed --- /dev/null +++ b/vendor/built_in_modules/er_email/app/views/panel/er_email/back_end/approvals/_modal_list.html.erb @@ -0,0 +1,44 @@ +<% if email_er_category -%> + +