From 10cb149fc77175131663b5cc945f2e7cfb8308c0 Mon Sep 17 00:00:00 2001 From: bohung Date: Sat, 13 Aug 2022 11:35:29 +0800 Subject: [PATCH] Fix bug. Add email regex feature. Edit defined_by_applicant feature. Add agree and disagree record time and let admin can click in backend page. Edit frontend select email feature. Remove items and enquiry_for_applicants page. --- .../application_form_signups_controller.rb | 10 +- .../admin/application_forms_controller.rb | 1 + .../application_forms_controller.rb | 73 +++++----- app/models/application_form_main.rb | 13 ++ app/models/application_form_signup.rb | 72 ++++++++-- .../application_form_signups/_view.html.erb | 37 +++++ .../application_form_signups/view.html.erb | 57 ++++++++ ...lication_form_signup_render_table.html.erb | 5 +- .../admin/application_forms/_form.html.erb | 34 +++-- .../_get_display_fields.html.erb | 52 ++++--- ...ication_form_signup_admin_setting.html.erb | 2 +- .../_email_selection_box.html.erb | 131 ++++++++++++++++++ .../application_forms/_select_emails.html.erb | 50 +++++++ app/views/application_forms/show.html.erb | 83 ++++++++++- config/locales/en.yml | 11 ++ config/locales/zh_tw.yml | 11 ++ config/routes.rb | 6 +- lib/application_form/engine.rb | 20 +-- 18 files changed, 563 insertions(+), 105 deletions(-) create mode 100644 app/views/admin/application_form_signups/_view.html.erb create mode 100644 app/views/admin/application_form_signups/view.html.erb create mode 100644 app/views/application_forms/_email_selection_box.html.erb create mode 100644 app/views/application_forms/_select_emails.html.erb diff --git a/app/controllers/admin/application_form_signups_controller.rb b/app/controllers/admin/application_form_signups_controller.rb index da2189f..2196886 100644 --- a/app/controllers/admin/application_form_signups_controller.rb +++ b/app/controllers/admin/application_form_signups_controller.rb @@ -18,16 +18,22 @@ class Admin::ApplicationFormSignupsController < OrbitAdminController end end def edit - OrbitHelper.set_params(params,current_user) params[:controller] = "admin/application_forms" @application_form_signup = ApplicationFormSignup.find(params[:id]) @application_form = ApplicationFormMain.find(@application_form_signup.application_form_main_id) - @form_index = 0 + @form_index = 0 end + def view + params[:controller] = "admin/application_forms" + @application_form_signup = ApplicationFormSignup.find(params[:id]) + @application_form = ApplicationFormMain.find(@application_form_signup.application_form_main_id) + + @form_index = 0 + end def update @application_form_signup = ApplicationFormSignup.find(params[:id]) diff --git a/app/controllers/admin/application_forms_controller.rb b/app/controllers/admin/application_forms_controller.rb index a933d9b..15e66dc 100644 --- a/app/controllers/admin/application_forms_controller.rb +++ b/app/controllers/admin/application_forms_controller.rb @@ -666,6 +666,7 @@ class Admin::ApplicationFormsController < OrbitAdminController end @application_form_signups = @application_form.application_form_signups.where(:id.in => unassigned_application_form_signup_ids, :name=>/#{params[:search]}/) end + @application_form_signups = @application_form_signups.order(:id=>-1) OrbitHelper.set_params(params,current_user) @access_level = OrbitHelper.user_access_level? @can_edit = true diff --git a/app/controllers/application_forms_controller.rb b/app/controllers/application_forms_controller.rb index 10a522e..8477575 100644 --- a/app/controllers/application_forms_controller.rb +++ b/app/controllers/application_forms_controller.rb @@ -406,9 +406,10 @@ class ApplicationFormsController < ApplicationController extra_text = "
#{I18n.t('application_form_signup.serial_number')}: #{signup.display_serial_number}" extra_text += render_to_string("application_forms/signup_email_contents",:locals=>{:application_form=>application_form, :application_form_signup=>signup},:layout=>false) + signup.agree_reviewer_ids[stage_num.to_s] = params[:reviewer] + signup.agree_reviewer_times[stage_num.to_s] = Time.now + signup.save if params[:type] == 'agree' - signup.agree_reviewer_ids[stage_num.to_s] = params[:reviewer] - signup.save if stage_num == application_form.get_max_stage signup.update(:review_status => 2) signup.clean_cipher @@ -453,15 +454,37 @@ class ApplicationFormsController < ApplicationController @signup = nil #ApplicationFormSignup.where(email: form_params_email, application_form_main_id: form_params_main_id ).first @application_form = ApplicationFormMain.where(id: form_params_main_id).first + email_regex = @application_form.get_email_regex @application_form_signup = ApplicationFormSignup.new(application_form_signup_params) + @application_form_signup.ip = request.remote_ip @application_form_signup.application_form_main = @application_form if @application_form.application_form_signup_field_sets.count!=0 flag = @application_form.application_form_signup_field_sets.select{|v| v.field_name=='recaptcha'}[0].disabled else flag = false end + verification_success = true + unless flag + if gotcha_valid? + flag = true + else + verification_success = false + end + end + email_valid = true + if email_regex + email_valid = !(::Regexp.new(email_regex).match(form_params_email.to_s).nil?) + unless email_valid + flag = false + end + end + referer_url = params[:referer_url].to_s + org_params = CGI.parse(referer_url.split('?')[1].to_s) + referer_url = referer_url.split("?")[0] + org_params.delete("notice") + notice = '' begin - if gotcha_valid? || flag + if flag if @signup.blank? && @application_form_signup.save # if gotcha_valid? && @application_form_signup.save @@ -502,39 +525,21 @@ class ApplicationFormsController < ApplicationController id_with_email.each do |id, email| send_mail('submission', email , form_params_main_id,extra_text, {'agree_link'=>agree_link + "&reviewer=#{id}"}) end - redirect_to "#{params[:referer_url]}/?method=signup_ok&serial_number=#{@application_form_signup.display_serial_number}" + redirect_to "#{referer_url}/?method=signup_ok&serial_number=#{@application_form_signup.display_serial_number}" and return else if !@signup.blank? - redirect_to "#{params[:referer_url]}", :notice => 'mail已存在' - else - referer_url = params[:referer_url].to_s - if referer_url.split("/").last.include?("?") - uri_query = referer_url.split("?").last.gsub(/notice=[^&]*/,'') - if uri_query == "" - referer_url = referer_url.split("?")[0...-1].join("?") + "?notice=#{t('recaptcha.errors.verification_failed')}" - else - referer_url = referer_url.split("?")[0...-1].join("?") + "¬ice=#{t('recaptcha.errors.verification_failed')}" - end - else - referer_url = referer_url + "?notice=#{t('recaptcha.errors.verification_failed')}" - end - redirect_to referer_url, :notice => t('recaptcha.errors.verification_failed') + notice = I18n.t('application_form.mail_exist') end end - else - referer_url = params[:referer_url].to_s - if referer_url.split("/").last.include?("?") - uri_query = referer_url.split("?").last.gsub(/notice=[^&]*/,'') - if uri_query == "" - referer_url = referer_url.split("?")[0...-1].join("?") + "?notice=#{t('recaptcha.errors.verification_failed')}" - else - referer_url = referer_url.split("?")[0...-1].join("?") + "¬ice=#{t('recaptcha.errors.verification_failed')}" - end - else - referer_url = referer_url + "?notice=#{t('recaptcha.errors.verification_failed')}" - end - redirect_to referer_url, :notice => t('recaptcha.errors.verification_failed') end + if !email_valid + notice = t('application_form.please_check_email_format') + elsif !verification_success + notice = t('recaptcha.errors.verification_failed') + end + org_params['notice'] = notice + referer_url += "?#{org_params.to_query}" + redirect_to referer_url, :notice => notice rescue => e render :html => [e.to_s, e.backtrace].to_s end @@ -797,10 +802,6 @@ class ApplicationFormsController < ApplicationController template_data:{'application_form_id'=>application_form_id,'locale'=>I18n.locale,'extra_text'=> extra_text}.merge(extra_data), mail_lang: I18n.locale) end - begin - mail.deliver - rescue => e - puts ["email can't deliver",e] - end + mail.save end end diff --git a/app/models/application_form_main.rb b/app/models/application_form_main.rb index 416c6cf..51bdf44 100644 --- a/app/models/application_form_main.rb +++ b/app/models/application_form_main.rb @@ -7,6 +7,9 @@ class ApplicationFormMain # encoding: utf-8 include OrbitCategory::Categorizable include Slug + StaticSignupFields = ["application_form_signup.created_at", "application_form_signup.ip"] + DefaultSignupFields = ["created_at", "ip", "serial_number", "review_progress"] + ExceptFieldSetDisplays = ["password", "recaptcha"] ChoiceTypes = ["checkbox","radio","select"] # field :annc_count, :type => Integer, :default => 0 # field :album_count, :type => Integer, :default => 0 @@ -63,6 +66,8 @@ class ApplicationFormMain field :review_end_date, :type => Date field :assign_mode, :type => Integer, :default => 0 # 0 => 用default signup ids來分配 ,1 => 用final_session來分配, 2 => 用final_session來分配(當有preffered session欄位時) field :update_old_flag, :type => Boolean, :default => false + field :email_regex_enable, type: Boolean, default: false + field :email_regex, type: String, default: '\A[^@\s]+@([^@.\s]+\.)+[^@.\s]+\z' belongs_to :application_form_item belongs_to :organizer , :class_name=>"MemberProfile", :foreign_key => :organizer_id has_many :application_form_sessions, :autosave => true, :dependent => :destroy @@ -195,6 +200,14 @@ class ApplicationFormMain end after_initialize do end + def get_email_regex(frontend=false) + tmp = self.email_regex + if frontend && tmp + 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 + end def get_max_stage self.reviewer_enables.rindex(true) || 0 end diff --git a/app/models/application_form_signup.rb b/app/models/application_form_signup.rb index 57c82bf..780697f 100644 --- a/app/models/application_form_signup.rb +++ b/app/models/application_form_signup.rb @@ -3,8 +3,9 @@ class ApplicationFormSignup require 'openssl/cipher' include Mongoid::Document include Mongoid::Timestamps - HiddenFields = ['application_form_signup_id', 'password', 'status', 'reviewer_ids_list','_id', 'created_at', 'updated_at','application_form_main_id',"serial_number","final_session","final_sessions","preferred_sessions",'application_form_session_id',"application_form_session_ids","preferred_session","sort_number","abstract_number","presentation_type", "cipher_stage_num", "process_stage", "review_status", "agree_reviewer_ids"] + HiddenFields = ['ip', 'application_form_signup_id', 'password', 'status', 'reviewer_ids_list','_id', 'created_at', 'updated_at','application_form_main_id',"serial_number","final_session","final_sessions","preferred_sessions",'application_form_session_id',"application_form_session_ids","preferred_session","sort_number","abstract_number","presentation_type", "cipher_stage_num", "process_stage", "review_status", "agree_reviewer_ids", "agree_reviewer_times"] DefaultEnableFields = ['name','tel','phone','email', 'recaptcha'] + field :ip, type: String field :sort_number , type: Integer, default: 10000 field :process_stage, type: Integer, default: 1 field :review_status, type: Integer, default: 0 # 0 => 審核中, 1 => 不通過, 2=> 申請通過 @@ -12,7 +13,7 @@ class ApplicationFormSignup field :status field :name # become Last Name for TICC field :tel, type: String # become First Name for TICC - field :unit, localize: true + field :unit, localize: true #Only localize for preserving old record field :phone, type: String field :fax, type: String field :email, type: String @@ -25,6 +26,7 @@ class ApplicationFormSignup field :preferred_sessions, type: Array, default: [] field :reviewer_ids_list, type: Array, default: [] field :agree_reviewer_ids, type: Hash, default: {} + field :agree_reviewer_times, type: Hash, default: {} def reviewer_ids_list main = self.application_form_main main.reviewer_enables.each_with_index.collect do |e,k| @@ -51,7 +53,12 @@ class ApplicationFormSignup before_create do unit = self.unit_translations.values.select{|v| v.present?}.first - self.unit_translations = I18n.available_locales.map{|l| [l.to_s,unit]}.to_h + tmp_unit_translations = self.unit_translations + self.unit_translations = I18n.available_locales.map do |l| + l = l.to_s + tmp = tmp_unit_translations[l] + [l, (tmp ? tmp : unit)] + end.to_h self.random_cipher(false) if self.application_form_main enable_idx = self.application_form_main.reviewer_enables.index(true) @@ -107,7 +114,41 @@ class ApplicationFormSignup self.process_stage = new_stage self.save end - def review_progress(with_details=true) + def procedure(agree_link=nil) + stage_trans = I18n.t('application_form.stage') + text = "" + main = self.application_form_main + tmp_process_idx = self.process_stage - 1 + if main + main.reviewer_enables.each_with_index do |t, i| + if t + text += "#{I18n.t("application_form.num.#{i + 1}")}#{stage_trans}: " + if main.reviewer_type_list[i]=='fixed' + member_ids = main.reviewer_ids_list[i] + is_fixed = true + else + member_ids = self[:reviewer_ids_list][i] rescue [] + is_fixed = false + end + if member_ids.present? + text += member_ids.map{|id| MemberProfile.find(id).name rescue nil}.compact.join(', ') + if is_fixed + text += " (#{I18n.t('application_form.fixed')})" + else + text += " (#{I18n.t('application_form.defined_by_applicant')})" + end + end + if i == tmp_process_idx && self.review_status == 0 && agree_link + text += "#{I18n.t('application_form.link_choice.agree')}" + text += "#{I18n.t('application_form.link_choice.disagree')}" + end + text += "
" + end + end + end + text + end + def review_progress(with_details=true, include_time=false) stage_trans = I18n.t('application_form.stage') max_stage = @max_stage if max_stage.nil? @@ -117,17 +158,29 @@ class ApplicationFormSignup text = "#{I18n.t('application_form.num.'+self.process_stage.to_s)}#{stage_trans} / #{I18n.t('application_form.num.'+max_stage.to_s)}#{stage_trans} : #{I18n.t('application_form.status.'+review_status.to_s)}" if with_details text += "
" - text += review_details + text += review_details(include_time) end text end - def review_details + def review_details(include_time=true) text = "" stage_trans = I18n.t('application_form.stage') + last_is_disagree = (self.review_status == 1) + last_idx = (self.process_stage - 1).to_s self.agree_reviewer_ids.each do |i, member_id| m = MemberProfile.find(member_id) rescue nil + t = agree_reviewer_times[i] if m - text += "#{I18n.t('application_form.num.'+(i.to_i+1).to_s)}#{stage_trans}: #{m.tmp_name}
" + text += "#{I18n.t('application_form.num.'+(i.to_i+1).to_s)}#{stage_trans}: #{m.tmp_name} " + if i == last_idx && last_is_disagree + text += I18n.t('application_form.link_choice.disagree') + else + text += I18n.t('application_form.link_choice.agree') + end + if include_time && t + text += " (#{t.to_time.strftime("%Y/%m/%d %H:%M")})" + end + text += "
" end end text @@ -173,10 +226,11 @@ class ApplicationFormSignup field_name = set.field_name next if set.disabled || except_fields.include?(field_name) value = self.send(field_name) rescue nil - next if value.nil? + localize = self.fields[field_name].options[:localize] + next if value.nil? && !localize if field_name == "status" value = I18n.t("application_form.registration_status_#{value}") - elsif self.fields[field_name].options[:localize] + elsif localize && field_name != "unit" values = self.send("#{field_name}_translations").select{|k,v| v.present?} value = "" if values.count == 0 diff --git a/app/views/admin/application_form_signups/_view.html.erb b/app/views/admin/application_form_signups/_view.html.erb new file mode 100644 index 0000000..915dfbc --- /dev/null +++ b/app/views/admin/application_form_signups/_view.html.erb @@ -0,0 +1,37 @@ +
+
<%= t('application_form_signup.procedure') %>
+
+ <% host_url = Site.first.root_url + if host_url == "http://" + host_url = request.protocol + request.host_with_port + end + agree_link = host_url + Rails.application.routes.url_helpers.xhr_application_forms_agree_link_path(:locale=>I18n.locale, :id=>@application_form_signup.id.to_s, :cipher=>@application_form_signup.get_cipher_stage(@application_form_signup.process_stage)) + agree_link += "&reviewer=#{current_user.member_profile_id}" + agree_link = nil unless OrbitHelper.user_can_edit?(@application_form_signup) || @application_form.organizer_id == current_user.member_profile_id + %> + <%= @application_form_signup.procedure(agree_link).html_safe %> + +
+
+
+
<%= t('application_form_signup.records') %>
+
+ <%= @application_form_signup.review_progress(true, true).html_safe %> +
+
\ No newline at end of file diff --git a/app/views/admin/application_form_signups/view.html.erb b/app/views/admin/application_form_signups/view.html.erb new file mode 100644 index 0000000..8229aea --- /dev/null +++ b/app/views/admin/application_form_signups/view.html.erb @@ -0,0 +1,57 @@ +
+ <% content_for :page_specific_css do %> + <%= stylesheet_link_tag "lib/main-forms" %> + <%= stylesheet_link_tag "lib/fileupload" %> + <%= stylesheet_link_tag "lib/main-list" %> + <% end %> + <% content_for :page_specific_javascript do %> + <%= javascript_include_tag "lib/bootstrap-fileupload" %> + <%= javascript_include_tag "lib/bootstrap-datetimepicker" %> + <%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %> + <%= javascript_include_tag "lib/datetimepicker/date.time.picker.js" %> + <%= javascript_include_tag "lib/file-type" %> + <%= javascript_include_tag "lib/module-area" %> + <% end %> + + +
+ + +
+ + + +
+
<%= t('application_form.title') %>
+
+ <%= @application_form.title %> +
+
+
+
<%= t('application_form_signup.created_at') %>
+
+ <%= @application_form_signup.created_at.strftime("%Y/%m/%d %H:%M") %><%= @application_form_signup.ip.present? ? " (#{@application_form_signup.ip})" : "" %> +
+
+ <%= render :partial => 'view' %> + <% fields_info = @application_form_signup.get_display_fields %> + <% fields_info.each do |info| %> +
+
<%= info['title'] %>
+
+ <%= info['value'] %> +
+
+ <% end %> + +
+ +
+
+ <%= link_to t('application_form.go_back'), "/admin/application_forms/#{@application_form.id}/application_form_signup", :class=>"btn" %> +
+
\ No newline at end of file diff --git a/app/views/admin/application_forms/_application_form_signup_render_table.html.erb b/app/views/admin/application_forms/_application_form_signup_render_table.html.erb index acac01b..01bec58 100644 --- a/app/views/admin/application_forms/_application_form_signup_render_table.html.erb +++ b/app/views/admin/application_forms/_application_form_signup_render_table.html.erb @@ -51,7 +51,7 @@ val += "