From 102a4f49ccfadf14d342137ad190221b29b5bbfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Sat, 20 May 2023 23:25:00 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=A1=E7=90=86=E8=80=85=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E9=A1=9E=E5=88=A5=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AF=A9=E6=A0=B8=E8=80=85=E7=B4=80=E9=8C=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E4=BF=AE=E5=BE=A9=E9=8C=AF=E8=AA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admin/asks_controller.rb | 2 +- app/controllers/asks_controller.rb | 38 +++++++++++++-- app/models/ask_admin.rb | 1 + app/models/ask_category_setting.rb | 4 +- app/models/ask_list_setting.rb | 10 ++-- app/models/ask_question.rb | 9 ++-- app/models/ask_setting.rb | 28 +++++++---- .../admin/ask_admins/_ask_admin_form.html.erb | 42 +++++++++++++++++ app/views/admin/ask_admins/edit.html.erb | 16 +------ app/views/admin/ask_admins/index.html.erb | 33 +------------ app/views/admin/asks/_index.html.erb | 6 ++- app/views/asks/email.html.erb | 3 ++ app/views/asks/index.html.erb | 23 ++++----- config/locales/en.yml | 4 +- config/locales/zh_tw.yml | 4 +- lib/ask/engine.rb | 47 +++++++++++++++++++ 16 files changed, 181 insertions(+), 89 deletions(-) create mode 100644 app/views/admin/ask_admins/_ask_admin_form.html.erb diff --git a/app/controllers/admin/asks_controller.rb b/app/controllers/admin/asks_controller.rb index 6a4f6cc..9a90693 100644 --- a/app/controllers/admin/asks_controller.rb +++ b/app/controllers/admin/asks_controller.rb @@ -389,7 +389,7 @@ class Admin::AsksController < OrbitAdminController temp_params['custom_values'][to_save[0]] = [temp_params['custom_values'][to_save[0]].original_filename ,to_save[1].file.url] end end - + temp_params = temp_params.merge({reviewer: current_user.member_profile, review_time: DateTime.now}) @ask_question.update_attributes(temp_params) if @ask_question.send_email build_email(@ask_question) diff --git a/app/controllers/asks_controller.rb b/app/controllers/asks_controller.rb index b7348cd..79833a6 100644 --- a/app/controllers/asks_controller.rb +++ b/app/controllers/asks_controller.rb @@ -255,7 +255,6 @@ class AsksController < ApplicationController end end end - puts "flag", flag flag = !ask_setting.default_setting['recaptcha'] || gotcha_valid? if flag all_to_save.each do |to_save| @@ -291,7 +290,8 @@ class AsksController < ApplicationController email_er.email_id = email.id email_er.save - @group_mail = email_er.email_address + @group_mail = email_er.mail + @manager_emails = email_er.reviewer_emails @mail_sentdate = DateTime.now site = current_site rescue Site.first @@ -300,13 +300,14 @@ class AsksController < ApplicationController if host_url == "http://" host_url = request.protocol + request.host_with_port end + mail_subject = mail_from+" #{t('ask.new_question')}:" email_er.email.update_attributes( :mail_lang=> site.default_locale, :create_user=>(current_user rescue nil), :mail_sentdate=>@mail_sentdate, :module_app=>@module_app, :mail_to=>@group_mail, - :mail_subject=>mail_from+" #{t('ask.new_question')}:", + :mail_subject=>mail_subject, :template=>'asks/email', :template_data=>{ # "title" => email_er.title, @@ -321,8 +322,35 @@ class AsksController < ApplicationController "ask_question_id" => email_er.id.to_s, "site_host" => host_url, "usage_rule" => @usage_rule - } + }, + :mail_reply_to => (@manager_emails.empty? ? nil : @manager_emails) ) + if !@manager_emails.empty? + Email.new( + :mail_lang=> site.default_locale, + :create_user=>(current_user rescue nil), + :mail_sentdate=>@mail_sentdate, + :module_app=>@module_app, + :mail_to=>@group_mail, + :mail_subject=>mail_subject+" #{@group_mail}", + :template=>'asks/email', + :template_data=>{ + # "title" => email_er.title, + "name" => email_er.name, + "identity" => email_er[:identity], + "mail" => email_er.mail, + "phone" => email_er.phone, + # "fax" => email_er.fax, + # "content" => email_er.content + "appointment" => email_er.appointment, + "disp_fields_infos" => @disp_fields_infos, + "ask_question_id" => email_er.id.to_s, + "site_host" => host_url, + "usage_rule" => @usage_rule, + "edit_url" => "#{host_url}/#{site.default_locale}/admin/asks/#{email_er.id}/edit" + } + ).save + end # email_er.email.deliver end @@ -357,7 +385,7 @@ class AsksController < ApplicationController has_ask_category_id = false disp_fields_infos.each do |field, info| if field.start_with?("default@") - k = field[8..-1] + k = is_cat_record ? field : field[8..-1] v = ask_setting.custom_fields[k] if v field_name = info['trans'] diff --git a/app/models/ask_admin.rb b/app/models/ask_admin.rb index eda70d6..b0847dd 100644 --- a/app/models/ask_admin.rb +++ b/app/models/ask_admin.rb @@ -3,4 +3,5 @@ class AskAdmin include Mongoid::Timestamps field :email, type: String + has_and_belongs_to_many :categories end \ No newline at end of file diff --git a/app/models/ask_category_setting.rb b/app/models/ask_category_setting.rb index 3978e31..97dcb10 100644 --- a/app/models/ask_category_setting.rb +++ b/app/models/ask_category_setting.rb @@ -136,10 +136,10 @@ class AskCategorySetting end def get_email_regex(frontend=false) tmp = self.email_regex - if tmp + if tmp && frontend tmp = tmp.gsub("\\A","^").gsub("\\z","$").gsub("\\","\\\\\\\\") end - tmp = nil if !(self.email_regex_enable) || (self.application_form_signup_field_sets.where(:field_name=>'email').pluck(:disabled)[0] rescue false) + tmp = nil if !(self.email_regex_enable) || ((self.default_setting[:mail] == false) rescue false) tmp end field :tmp_sort_number, type: Hash, default: {} # For Frontend diff --git a/app/models/ask_list_setting.rb b/app/models/ask_list_setting.rb index 4c8e1b8..876afae 100644 --- a/app/models/ask_list_setting.rb +++ b/app/models/ask_list_setting.rb @@ -1,15 +1,17 @@ class AskListSetting include Mongoid::Document include Mongoid::Timestamps - DefaultFields = ['serial_number','situation','ask_category_id','title','name','sex','mail','phone','appointment','created_at','ip'] - DefaultEnabled = ['serial_number','situation','ask_category_id','title','name','phone','appointment','created_at','ip'] + DefaultFields = ['serial_number','situation','ask_category_id','title','name','sex','mail','phone','appointment','created_at','ip','reviewer','review_time'] + DefaultEnabled = ['serial_number','situation','ask_category_id','title','name','phone','appointment','created_at','ip','reviewer','review_time'] field :default_fields, type: Array, default: [] field :custom_fields, type: Array, default: [] field :category_id def default_fields tmp = super() - return tmp if tmp.length>0 - self.class::DefaultEnabled + if tmp.empty? + tmp = self.class::DefaultEnabled + end + return tmp end def custom_fields_list locale = I18n.locale diff --git a/app/models/ask_question.rb b/app/models/ask_question.rb index 3530f5e..91fcc2c 100644 --- a/app/models/ask_question.rb +++ b/app/models/ask_question.rb @@ -26,6 +26,10 @@ class AskQuestion field :custom_values, type: Hash,default: {} field :agree_show,type: Boolean,default: false field :agree_usage,type: Boolean,default: false + + field :review_time, type: DateTime + belongs_to :reviewer , :class_name=>"MemberProfile", :foreign_key => :reviewer_id + # validates_presence_of :name, :identity, :mail, :title, :content before_create do last_serial_number = AskSetting.update_last_serial_number @@ -34,8 +38,8 @@ class AskQuestion def email mail = Email.find(self.email_id) rescue nil end - def email_address - email_address = AskAdmin.pluck(:email).select{|s| s.present?}.uniq rescue [] + def reviewer_emails + email_address = AskAdmin.or(:category_ids.in => [self.category_id, [], nil]).pluck(:email).select{|s| s.present?}.uniq rescue [] authorizes = Authorization.where(:module_app_id=>ModuleApp.where(:key=>'ask').first.id).to_a rescue [] authorizes.each do |a| if a.category_id @@ -50,7 +54,6 @@ class AskQuestion a.destroy end end - email_address = email_address +[self.mail] if !self.mail.blank? email_address = email_address.flatten email_address.uniq end diff --git a/app/models/ask_setting.rb b/app/models/ask_setting.rb index 8936df2..bb890ad 100644 --- a/app/models/ask_setting.rb +++ b/app/models/ask_setting.rb @@ -192,7 +192,11 @@ class AskSetting tmp_locales = I18n.available_locales.map{|l| l.to_s} tmp_locales = [locale] + (tmp_locales - [locale]) ask_setting.custom_fields.each do |k,v| - tmp_k = (k.start_with?('default@') ? k : "default@#{k}") + tmp_k = k + if !k.start_with?('default@') + prefix = is_cat_record ? "custom@#{cat.id}@" : 'default@' + tmp_k = "#{prefix}#{k}" + end disp_fields_infos[tmp_k] = sort_number[tmp_k] end ask_category_settings = [] @@ -202,15 +206,15 @@ class AskSetting ask_category_settings = AskCategorySetting.enabled.to_a end ask_category_settings.each do |c| - cat = Category.find(c.category_id) rescue nil - if cat.nil? + category = Category.find(c.category_id) rescue nil + if category.nil? c.destroy next end c.custom_fields.each do |k,v| next if k.start_with?('default@') tmp_k = "custom@#{c.id}@#{k}" - cat_title = cat.title rescue "" + cat_title = category.title rescue "" disp_fields_infos[tmp_k] = sort_number[tmp_k] end end @@ -296,7 +300,11 @@ class AskSetting end end next if trans.class != String - tmp_k = (k.start_with?('default@') ? k : "default@#{k}") + tmp_k = k + if !k.start_with?('default@') + prefix = is_cat_record ? "custom@#{cat.id}@" : 'default@' + tmp_k = "#{prefix}#{k}" + end disp_fields_infos[tmp_k] = {"trans"=>trans,"sort_number"=>sort_number[tmp_k],"key"=>k,"type"=>v["type"],"options"=>v["options"],"instructions"=>v["instructions"]} end ask_category_settings = [] @@ -306,8 +314,8 @@ class AskSetting ask_category_settings = AskCategorySetting.enabled.to_a end ask_category_settings.each do |c| - cat = Category.find(c.category_id) rescue nil - if cat.nil? + category = Category.find(c.category_id) rescue nil + if category.nil? c.destroy next end @@ -322,7 +330,7 @@ class AskSetting next if trans.class != String next if k.start_with?('default@') tmp_k = "custom@#{c.id}@#{k}" - cat_title = cat.title rescue "" + cat_title = category.title rescue "" disp_fields_infos[tmp_k] = {"trans"=>"#{cat_title}-#{trans}","sort_number"=>sort_number[tmp_k],"key"=>k,"type"=>v["type"],"options"=>v["options"],"instructions"=>v["instructions"]} end end @@ -349,10 +357,10 @@ class AskSetting end def get_email_regex(frontend=false) tmp = self.email_regex - if tmp + if tmp && frontend tmp = tmp.gsub("\\A","^").gsub("\\z","$").gsub("\\","\\\\\\\\") end - tmp = nil if !(self.email_regex_enable) || (self.application_form_signup_field_sets.where(:field_name=>'email').pluck(:disabled)[0] rescue false) + tmp = nil if !(self.email_regex_enable) || ((self.default_setting[:mail] == false) rescue false) tmp end end diff --git a/app/views/admin/ask_admins/_ask_admin_form.html.erb b/app/views/admin/ask_admins/_ask_admin_form.html.erb new file mode 100644 index 0000000..ce0b01e --- /dev/null +++ b/app/views/admin/ask_admins/_ask_admin_form.html.erb @@ -0,0 +1,42 @@ +

<%= @ask_admin.new_record? ? t(:add) : t(:edit) %>

+ +
+
+ <%= f.label :email, class: 'control-label' %> +
+ <%= f.text_field :email, class: 'input-xxlarge', data: {"fv-validation" => "required;check_email;", "fv-messages" => "必填欄位;Email不正確;"} %> +
+
+
+ <%= f.label :category, class: 'control-label' %> +
+ + <% @module_app.categories.each do |category| %> + + <% end %> +
+
+
+
+ <%= f.submit t(:submit), class: 'btn btn-primary' %> +
+ + \ No newline at end of file diff --git a/app/views/admin/ask_admins/edit.html.erb b/app/views/admin/ask_admins/edit.html.erb index f5ac3c8..b00bb0d 100644 --- a/app/views/admin/ask_admins/edit.html.erb +++ b/app/views/admin/ask_admins/edit.html.erb @@ -27,20 +27,6 @@ <%= form_for @ask_admin, url: @url, html: { class: 'form-horizontal' } do |f| %> - -

<%= @ask_admin.new_record? ? t(:add) : t(:edit) %>

- -
-
- <%= f.label :email, class: 'control-label' %> -
- <%= f.text_field :email, class: 'input-xxlarge' %> -
-
-
-
- <%= f.submit t(:submit), class: 'btn btn-primary' %> -
- + <%= render :partial => 'ask_admin_form', locals: {f: f} %> <% end %> diff --git a/app/views/admin/ask_admins/index.html.erb b/app/views/admin/ask_admins/index.html.erb index 5763d69..8e67b81 100644 --- a/app/views/admin/ask_admins/index.html.erb +++ b/app/views/admin/ask_admins/index.html.erb @@ -29,34 +29,5 @@ <%= javascript_include_tag 'validator' %> <%= form_for @ask_admin, url: admin_ask_admins_path, html: {class: "form-horizontal main-forms previewable"} do |f| %> -

<%= @ask_admin.new_record? ? t(:add) : t(:edit) %>

- -
-
- <%= f.label :email, class: 'control-label' %> -
- <%= f.text_field :email, class: 'input-xxlarge', data: {"fv-validation" => "required;check_email;", "fv-messages" => "必填欄位;Email不正確;"} %> -
-
-
- -
- <%= f.submit t(:submit), class: 'btn btn-primary' %> -
- -<% end %> - - - + <%= render :partial => 'ask_admin_form', locals: {f: f} %> +<% end %> \ No newline at end of file diff --git a/app/views/admin/asks/_index.html.erb b/app/views/admin/asks/_index.html.erb index 53c9541..507a9b3 100644 --- a/app/views/admin/asks/_index.html.erb +++ b/app/views/admin/asks/_index.html.erb @@ -226,6 +226,10 @@ <%= b.created_at.strftime("%Y-%m-%d %H:%M") rescue nil %> <% when 'ip' %> <%= b.ip %> + <% when 'reviewer' %> + <%= b.reviewer.name rescue "" %> + <% when 'review_time' %> + <%= b.review_time.strftime("%Y-%m-%d %H:%M") rescue nil %> <% end %> <% if edit_box_display_index == i %> <%= render partial: 'edit_box_for_index', :locals => {is_editable: is_editable, b: b} %> @@ -256,4 +260,4 @@ $(this)[0].form.submit(); }) }) - \ No newline at end of file + diff --git a/app/views/asks/email.html.erb b/app/views/asks/email.html.erb index 5444cf0..6d053ea 100644 --- a/app/views/asks/email.html.erb +++ b/app/views/asks/email.html.erb @@ -5,6 +5,9 @@ + <% if @data['edit_url'] %> + <%= link_to t("edit"), @data['edit_url'] %> + <% end %> <% question = AskQuestion.find(@data['ask_question_id']) rescue nil %> <% if question %> diff --git a/app/views/asks/index.html.erb b/app/views/asks/index.html.erb index cc16915..dbded2f 100644 --- a/app/views/asks/index.html.erb +++ b/app/views/asks/index.html.erb @@ -146,21 +146,6 @@ // return false; // }); // }); -$(function(){ - var fv = new FormValidator($("#new_ask_question")); - fv.validate_functions.check_email = function(value){ - reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/; - if (reg.test(value)) { - return true; - }else{ - return false; - } - } - - // fv.validate_functions.test_function = function(value, element){ - - // } -}) $(document).ready(function(){ function scrollIntoView(selector, offset = 0) { window.scroll(0, document.querySelector(selector).offsetTop - offset); @@ -168,6 +153,14 @@ $(document).ready(function(){ var email_regex = "<%=email_regex%>"; if(email_regex.length != 0){ email_regex = new RegExp(email_regex); + var fv = new FormValidator($("#new_ask_question")); + fv.validate_functions.check_email = function(value){ + if (email_regex.test(value)) { + return true; + }else{ + return false; + } + } var submit_flag = false; $(".ask-question-form").each(function(i, form){ var $form = $(form); diff --git a/config/locales/en.yml b/config/locales/en.yml index a9b5f13..2371200 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -147,4 +147,6 @@ en: status: Status send_email: Whether to reply email agree_show: Do you agree on displaying your request and our reply on the webpage without your personal information? - agree_show_explain: Whether to agree on displaying your request and our reply on the webpage without your personal information? \ No newline at end of file + agree_show_explain: Whether to agree on displaying your request and our reply on the webpage without your personal information? + reviewer: Reviewer + review_time: Review Time \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index b9e6d57..bdffe6e 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -157,4 +157,6 @@ zh_tw: status: 狀態 send_email: 是否回信 agree_show: 是否同意您提出之需求及回覆內容以不呈現發問者資訊方式刊載於網站供他人參考? - agree_show_explain: 是否同意刊載於網站給他人參考 \ No newline at end of file + agree_show_explain: 是否同意刊載於網站給他人參考 + reviewer: 審核者 + review_time: 審核時間 \ No newline at end of file diff --git a/lib/ask/engine.rb b/lib/ask/engine.rb index 0130022..84a0ba0 100644 --- a/lib/ask/engine.rb +++ b/lib/ask/engine.rb @@ -41,6 +41,28 @@ module Ask if ask_setting.email_regex_enable AskCategorySetting.all.update_all(email_regex_enable: ask_setting.email_regex_enable,email_regex: ask_setting.email_regex) end + AskCategorySetting.all.each do |ask_category_setting| + sort_number = ask_category_setting.sort_number + have_custom_key = false + sort_number.keys.each do |sort_number_key| + have_default_key ||= sort_number_key.include?("default@default@") + have_custom_key ||= sort_number_key.include?("custom@") + end + if !have_custom_key + new_sort_number = {} + sort_number.keys.each do |sort_number_key| + new_sort_number_key = sort_number_key + if sort_number_key.include?("default@default@") + new_sort_number_key = sort_number_key.sub(/default@/, '') + else + new_sort_number_key = sort_number_key.sub(/default@/, "custom@#{ask_category_setting.id}@") + end + new_sort_number[new_sort_number_key] = sort_number[sort_number_key] + end + ask_category_setting.sort_number = new_sort_number + ask_category_setting.save + end + end end if defined?(AskListSetting) ask_list_setting = AskListSetting.first @@ -64,6 +86,31 @@ module Ask rescue => e puts ['AskSetting not found',e] end + require File.expand_path('../../../app/models/ask_question', __FILE__) + require File.expand_path('app/models/user_action', Rails.root) + def fix_reviewer + ask_question_no_reviewer_len = AskQuestion.where(:id.in => UserAction.where(controller: 'admin/asks', action: 'update').pluck(:request_path).map{|v| v.split('/')[-1]}, :reviewer_id => nil).count + if ask_question_no_reviewer_len==0 + return + end + UserAction.where(controller: 'admin/asks', action: 'update').each do |user_action| + user = user_action.user + askquestion_id = user_action.request_path.split('/')[-1] + askquestion = AskQuestion.where(id: askquestion_id).first + if askquestion && user.member_profile_id + askquestion.update_attributes(reviewer_id: user.member_profile_id, review_time: user_action.created_at) + end + end + if defined?(AskListSetting) + AskListSetting.each do |ask_list_setting| + if ask_list_setting.default_fields.length != AskListSetting::DefaultEnabled.length + ask_list_setting.default_fields += ['reviewer', 'review_time'] + ask_list_setting.save + end + end + end + end + fix_reviewer OrbitApp.registration "Ask", :type => "ModuleApp" do module_label "ask.ask" base_url File.expand_path File.dirname(__FILE__)