From d2638689f633b978be37485cf13a6b1b1280787a Mon Sep 17 00:00:00 2001 From: Jeremy Rudman Date: Thu, 11 Feb 2021 01:59:50 -0500 Subject: [PATCH 1/7] fix(questionnaire): directors can update invalid questionnaires directors can now update questionnaires with missing country or agreements fields. This is done a temp fix for bh7 but should be removed later --- app/controllers/manage/questionnaires_controller.rb | 8 ++++++-- app/models/questionnaire.rb | 5 +++++ app/views/manage/questionnaires/_form.html.haml | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/controllers/manage/questionnaires_controller.rb b/app/controllers/manage/questionnaires_controller.rb index f920cd68d..a84ae7edd 100644 --- a/app/controllers/manage/questionnaires_controller.rb +++ b/app/controllers/manage/questionnaires_controller.rb @@ -61,7 +61,11 @@ def update @questionnaire.user.update_attributes(email: email) if email.present? update_params = convert_school_name_to_id(update_params) update_params = convert_boarded_bus_param(update_params, @questionnaire) - @questionnaire.update_attributes(update_params) + if HackathonConfig['brickhack_7'] + @questionnaire.update_with_invalid_attributes(update_params) + else + @questionnaire.update_attributes(update_params) + end respond_with(:manage, @questionnaire) end @@ -157,7 +161,7 @@ def questionnaire_params :portfolio_url, :vcs_url, :bus_captain_interest, :phone, :can_share_info, :travel_not_from_school, :travel_location, :graduation_year, :race_ethnicity, :resume, :delete_resume, :why_attend, - :bus_list_id, :is_bus_captain, :boarded_bus + :bus_list_id, :is_bus_captain, :boarded_bus, :country ) end diff --git a/app/models/questionnaire.rb b/app/models/questionnaire.rb index 31b14dcb0..cd7bdfb34 100644 --- a/app/models/questionnaire.rb +++ b/app/models/questionnaire.rb @@ -430,6 +430,11 @@ def unaccepted_agreements Agreement.all - agreements end + def update_with_invalid_attributes(attributes) + assign_attributes(attributes) + save!(:validate => false) + end + def as_json(options = {}) result = super result['all_agreements_accepted'] = all_agreements_accepted? diff --git a/app/views/manage/questionnaires/_form.html.haml b/app/views/manage/questionnaires/_form.html.haml index 498e9bbee..e130da5a2 100644 --- a/app/views/manage/questionnaires/_form.html.haml +++ b/app/views/manage/questionnaires/_form.html.haml @@ -22,7 +22,7 @@ = f.input :level_of_study, input_html: { "data-validate" => "presence" } = f.input :major, input_html: { "data-validate" => "presence" } = f.input :gender, input_html: { "data-validate" => "presence" } - = f.input :country, as: :select, collection: Questionnaire::POSSIBLE_COUNTRIES, include_blank: "(select one...)", input_html: { "data-validate" => "presence" } + = f.input :country, as: :select, collection: Questionnaire::POSSIBLE_COUNTRIES, include_blank: "(select one...)" - if !HackathonConfig['digital_hackathon'] .card.mb-4 From ecac35002c1a671728c02b0eced6fa4a30ba9472 Mon Sep 17 00:00:00 2001 From: Jeremy Rudman Date: Thu, 11 Feb 2021 02:10:02 -0500 Subject: [PATCH 2/7] fix hound complaint and added missing file --- app/models/questionnaire.rb | 2 +- config/app.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/questionnaire.rb b/app/models/questionnaire.rb index cd7bdfb34..35a298aea 100644 --- a/app/models/questionnaire.rb +++ b/app/models/questionnaire.rb @@ -432,7 +432,7 @@ def unaccepted_agreements def update_with_invalid_attributes(attributes) assign_attributes(attributes) - save!(:validate => false) + save!(validate: false) end def as_json(options = {}) diff --git a/config/app.yml b/config/app.yml index 544c53127..4962860df 100644 --- a/config/app.yml +++ b/config/app.yml @@ -4,6 +4,7 @@ defaults: &defaults # Logic config accepting_questionnaires: true digital_hackathon: false + brickhack_7: true last_day_to_apply: "<%= Date.new(2000, 1, 1).to_s %>" event_start_date: "<%= Date.new(2000, 1, 1).to_s %>" auto_late_waitlist: false From 2c6bc1e6e59482204d085216a107fe0347f85f83 Mon Sep 17 00:00:00 2001 From: Jeremy Rudman Date: Sun, 14 Feb 2021 02:40:21 -0500 Subject: [PATCH 3/7] implemented switch to disable validation in manage questionnaire --- app/assets/javascripts/manage/lib/forms.js | 8 +++++ .../manage/questionnaires_controller.rb | 4 +-- app/models/questionnaire.rb | 2 ++ .../manage/questionnaires/_form.html.haml | 34 +++++++++++-------- config/app.yml | 1 - 5 files changed, 31 insertions(+), 18 deletions(-) diff --git a/app/assets/javascripts/manage/lib/forms.js b/app/assets/javascripts/manage/lib/forms.js index fc7db2584..e41668514 100644 --- a/app/assets/javascripts/manage/lib/forms.js +++ b/app/assets/javascripts/manage/lib/forms.js @@ -32,3 +32,11 @@ var setupManageForms = function() { updateMessageForm(); }); }; + +document.addEventListener('turbolinks:load', function () { + $('#validateFormSwitch').val($('#validateSwitch').is(':checked')); + $('#validateSwitch').on('change', function () { + $('#validateFormSwitch').val($('#validateSwitch').is(':checked')); + }) +}); + diff --git a/app/controllers/manage/questionnaires_controller.rb b/app/controllers/manage/questionnaires_controller.rb index a84ae7edd..66c95017b 100644 --- a/app/controllers/manage/questionnaires_controller.rb +++ b/app/controllers/manage/questionnaires_controller.rb @@ -61,7 +61,7 @@ def update @questionnaire.user.update_attributes(email: email) if email.present? update_params = convert_school_name_to_id(update_params) update_params = convert_boarded_bus_param(update_params, @questionnaire) - if HackathonConfig['brickhack_7'] + if update_params[:validate_switch] == 'false' @questionnaire.update_with_invalid_attributes(update_params) else @questionnaire.update_attributes(update_params) @@ -161,7 +161,7 @@ def questionnaire_params :portfolio_url, :vcs_url, :bus_captain_interest, :phone, :can_share_info, :travel_not_from_school, :travel_location, :graduation_year, :race_ethnicity, :resume, :delete_resume, :why_attend, - :bus_list_id, :is_bus_captain, :boarded_bus, :country + :bus_list_id, :is_bus_captain, :boarded_bus, :country, :validate_switch ) end diff --git a/app/models/questionnaire.rb b/app/models/questionnaire.rb index 35a298aea..4902353fe 100644 --- a/app/models/questionnaire.rb +++ b/app/models/questionnaire.rb @@ -1,6 +1,8 @@ class Questionnaire < ApplicationRecord audited + attr_accessor :validate_switch + include ActiveModel::Dirty include DeletableAttachment before_validation :consolidate_school_names diff --git a/app/views/manage/questionnaires/_form.html.haml b/app/views/manage/questionnaires/_form.html.haml index e130da5a2..92775673e 100644 --- a/app/views/manage/questionnaires/_form.html.haml +++ b/app/views/manage/questionnaires/_form.html.haml @@ -13,15 +13,15 @@ %h6.card-subtitle.mb-2 %span.badge.badge-info Provided by MyMLH = f.simple_fields_for :user, @questionnaire.user do |u| - = u.input :first_name, input_html: { "data-validate" => "presence" }, label: "First Name", autofocus: true - = u.input :last_name, input_html: { "data-validate" => "presence" }, label: "Last Name" - = f.input :email, input_html: { "data-validate" => "presence email", value: @questionnaire.user.try(:email) }, required: true, hint: 'Can be an existing user (without a questionnaire) or a new user. If this is a new user, they will receive a randomly-generated password that they must request a password reset for.' - = f.input :phone, input_html: { "data-validate" => "presence" } - = f.input :date_of_birth, start_year: Date.today.year - 18, end_year: Date.today.year - 90, order: [:month, :day, :year], input_html: { "data-validate" => "presence" } - = f.input :school_id, as: :school_selection, input_html: { "data-validate" => "presence" } - = f.input :level_of_study, input_html: { "data-validate" => "presence" } - = f.input :major, input_html: { "data-validate" => "presence" } - = f.input :gender, input_html: { "data-validate" => "presence" } + = u.input :first_name, label: "First Name", autofocus: true + = u.input :last_name, label: "Last Name" + = f.input :email, input_html: { value: @questionnaire.user.try(:email) }, required: true, hint: 'Can be an existing user (without a questionnaire) or a new user. If this is a new user, they will receive a randomly-generated password that they must request a password reset for.' + = f.input :phone + = f.input :date_of_birth, start_year: Date.today.year - 18, end_year: Date.today.year - 90, order: [:month, :day, :year] + = f.input :school_id, as: :school_selection + = f.input :level_of_study + = f.input :major + = f.input :gender = f.input :country, as: :select, collection: Questionnaire::POSSIBLE_COUNTRIES, include_blank: "(select one...)" - if !HackathonConfig['digital_hackathon'] @@ -30,7 +30,7 @@ .card-body - travel_state = !@questionnaire.new_record? && @questionnaire.travel_not_from_school = f.input :travel_not_from_school, label: "I will not be traveling from my school" - = f.input :travel_location, input_html: { "data-validate" => "presence", disabled: !travel_state }, wrapper_html: { style: travel_state ? "" : "display: none" }, label: "Travel Location" + = f.input :travel_location, input_html: { disabled: !travel_state }, wrapper_html: { style: travel_state ? "" : "display: none" }, label: "Travel Location" = f.association :bus_list, label: "Bus list", include_blank: 'Not travelling on a sponsored bus' = f.input :boarded_bus, as: :boolean, label: "Boarded bus", input_html: { checked: @questionnaire.boarded_bus_at.present? } @@ -40,7 +40,7 @@ .card.mb-4 .card-header Special notices .card-body - = f.input :shirt_size, as: :select, collection: Questionnaire::POSSIBLE_SHIRT_SIZES, include_blank: "(select one...)", input_html: { "data-validate" => "presence" } + = f.input :shirt_size, as: :select, collection: Questionnaire::POSSIBLE_SHIRT_SIZES, include_blank: "(select one...)" - if !HackathonConfig['digital_hackathon'] = f.input :dietary_restrictions, label: "Dietary restrictions" = f.input :special_needs, label: "Special needs" @@ -50,11 +50,11 @@ - if HackathonManager.field_enabled?(:why_attend) = f.input :why_attend, label: "Why #{HackathonConfig['name']}?", placeholder: "In a sentence or two, why would you like to attend #{HackathonConfig['name']}?", input_html: { rows: 3, maxlength: 280 } - = f.input :experience, as: :select, collection: Questionnaire::POSSIBLE_EXPERIENCES.invert, include_blank: "(select one...)", label: "Experience", input_html: { "data-validate" => "presence" } - = f.input :interest, as: :select, collection: Questionnaire::POSSIBLE_INTERESTS.invert, include_blank: "(select one...)", label: "Interest", input_html: { "data-validate" => "presence" } + = f.input :experience, as: :select, collection: Questionnaire::POSSIBLE_EXPERIENCES.invert, include_blank: "(select one...)", label: "Experience" + = f.input :interest, as: :select, collection: Questionnaire::POSSIBLE_INTERESTS.invert, include_blank: "(select one...)", label: "Interest" - = f.input :graduation_year, as: :select, collection: Questionnaire::POSSIBLE_GRAD_YEARS, include_blank: "(select one...)", label: "Graduation year", input_html: { "data-validate" => "presence" }, wrapper_html: { class: 'input--half' } - = f.input :race_ethnicity, as: :select, collection: Questionnaire::POSSIBLE_RACE_ETHNICITIES, include_blank: "(select one...)", label: "Race/Ethnicity", input_html: { "data-validate" => "presence" }, wrapper_html: { class: 'input--half' } + = f.input :graduation_year, as: :select, collection: Questionnaire::POSSIBLE_GRAD_YEARS, include_blank: "(select one...)", label: "Graduation year", wrapper_html: { class: 'input--half' } + = f.input :race_ethnicity, as: :select, collection: Questionnaire::POSSIBLE_RACE_ETHNICITIES, include_blank: "(select one...)", label: "Race/Ethnicity", wrapper_html: { class: 'input--half' } = f.input :resume, as: :deletable_attachment, hint: "Must be under 2MB", input_html: { "data-validate" => "file-max-size file-content-type", "data-validate-file-max-size" => "2097152", "data-validate-file-content-type" => "application/pdf" }, label: "Resume (PDF)" @@ -64,4 +64,8 @@ = f.input :can_share_info, label: "Share resume with employers?" .center.mb-4 + .custom-control.custom-switch.pb-3 + = f.input :validate_switch, as: :hidden, input_html: { id: "validateFormSwitch" } + %input.custom-control-input{ type: "checkbox", id: "validateSwitch", checked: true } + %label.custom-control-label{ for: "validateSwitch" } Enable Validation = f.button :submit, value: ( @questionnaire.new_record? ? 'Create' : 'Save' ), class: 'btn-primary' diff --git a/config/app.yml b/config/app.yml index 4962860df..544c53127 100644 --- a/config/app.yml +++ b/config/app.yml @@ -4,7 +4,6 @@ defaults: &defaults # Logic config accepting_questionnaires: true digital_hackathon: false - brickhack_7: true last_day_to_apply: "<%= Date.new(2000, 1, 1).to_s %>" event_start_date: "<%= Date.new(2000, 1, 1).to_s %>" auto_late_waitlist: false From f28d73592e7f0b6cf8c7486548e6dfe1a152f9fb Mon Sep 17 00:00:00 2001 From: JeremyRudman <38338616+JeremyRudman@users.noreply.github.com> Date: Sun, 14 Feb 2021 03:13:59 -0500 Subject: [PATCH 4/7] Update forms.js --- app/assets/javascripts/manage/lib/forms.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/manage/lib/forms.js b/app/assets/javascripts/manage/lib/forms.js index e41668514..2ade7d323 100644 --- a/app/assets/javascripts/manage/lib/forms.js +++ b/app/assets/javascripts/manage/lib/forms.js @@ -37,6 +37,6 @@ document.addEventListener('turbolinks:load', function () { $('#validateFormSwitch').val($('#validateSwitch').is(':checked')); $('#validateSwitch').on('change', function () { $('#validateFormSwitch').val($('#validateSwitch').is(':checked')); - }) + }); }); From 66e85ec367f48abe56fa3b5c2d78e645f18a260d Mon Sep 17 00:00:00 2001 From: JeremyRudman <38338616+JeremyRudman@users.noreply.github.com> Date: Sun, 14 Feb 2021 19:54:22 -0500 Subject: [PATCH 5/7] Update forms.js --- app/assets/javascripts/manage/lib/forms.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/manage/lib/forms.js b/app/assets/javascripts/manage/lib/forms.js index 2ade7d323..86597c854 100644 --- a/app/assets/javascripts/manage/lib/forms.js +++ b/app/assets/javascripts/manage/lib/forms.js @@ -33,9 +33,9 @@ var setupManageForms = function() { }); }; -document.addEventListener('turbolinks:load', function () { +document.addEventListener('turbolinks:load', function() { $('#validateFormSwitch').val($('#validateSwitch').is(':checked')); - $('#validateSwitch').on('change', function () { + $('#validateSwitch').on('change', function() { $('#validateFormSwitch').val($('#validateSwitch').is(':checked')); }); }); From 2d7f383f33209ba0184a663c90df2e10aa47eaf8 Mon Sep 17 00:00:00 2001 From: JeremyRudman <38338616+JeremyRudman@users.noreply.github.com> Date: Sun, 14 Feb 2021 20:06:22 -0500 Subject: [PATCH 6/7] Update _form.html.haml --- app/views/manage/questionnaires/_form.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/manage/questionnaires/_form.html.haml b/app/views/manage/questionnaires/_form.html.haml index 92775673e..efe43cd60 100644 --- a/app/views/manage/questionnaires/_form.html.haml +++ b/app/views/manage/questionnaires/_form.html.haml @@ -17,7 +17,7 @@ = u.input :last_name, label: "Last Name" = f.input :email, input_html: { value: @questionnaire.user.try(:email) }, required: true, hint: 'Can be an existing user (without a questionnaire) or a new user. If this is a new user, they will receive a randomly-generated password that they must request a password reset for.' = f.input :phone - = f.input :date_of_birth, start_year: Date.today.year - 18, end_year: Date.today.year - 90, order: [:month, :day, :year] + = f.input :date_of_birth, start_year: Date.today.year - 5, end_year: Date.today.year - 90, order: [:month, :day, :year] = f.input :school_id, as: :school_selection = f.input :level_of_study = f.input :major From 8ddf078b419e1d47ca6e5d8141ed2aa15f660c54 Mon Sep 17 00:00:00 2001 From: Jeremy Rudman Date: Sun, 14 Feb 2021 22:38:36 -0500 Subject: [PATCH 7/7] added cursor pointer to switch --- app/assets/stylesheets/manage.sass | 3 +++ app/views/manage/questionnaires/_form.html.haml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/manage.sass b/app/assets/stylesheets/manage.sass index 8e7464574..f0edf4a0a 100644 --- a/app/assets/stylesheets/manage.sass +++ b/app/assets/stylesheets/manage.sass @@ -55,6 +55,9 @@ $grey-med: #999 .county :hover stroke: #000 +.switch-input + cursor: pointer + #map text-align: center overflow: auto diff --git a/app/views/manage/questionnaires/_form.html.haml b/app/views/manage/questionnaires/_form.html.haml index be727fd3d..5c595df07 100644 --- a/app/views/manage/questionnaires/_form.html.haml +++ b/app/views/manage/questionnaires/_form.html.haml @@ -72,5 +72,5 @@ .custom-control.custom-switch.pb-3 = f.input :validate_switch, as: :hidden, input_html: { id: "validateFormSwitch" } %input.custom-control-input{ type: "checkbox", id: "validateSwitch", checked: true } - %label.custom-control-label{ for: "validateSwitch" } Enable Validation + %label.custom-control-label.switch-input{ for: "validateSwitch" } Enable Validation = f.button :submit, value: ( @questionnaire.new_record? ? 'Create' : 'Save' ), class: 'btn-primary'