From 8768263bf39393bfed8146e71703b226799b365c Mon Sep 17 00:00:00 2001 From: "Chris Baudouin, Jr" Date: Tue, 5 Jan 2021 22:40:50 -0500 Subject: [PATCH 1/4] fix: Resolves issue preventing new MyMLH users from creating questionnaires --- app/controllers/questionnaires_controller.rb | 42 +++++++++++++++----- config/locales/en.yml | 2 + 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/app/controllers/questionnaires_controller.rb b/app/controllers/questionnaires_controller.rb index 0aed9e76f..850e64bb3 100644 --- a/app/controllers/questionnaires_controller.rb +++ b/app/controllers/questionnaires_controller.rb @@ -11,6 +11,7 @@ def logged_in # GET /apply # GET /apply.json def show + flash[:alert] = nil respond_to do |format| format.html # show.html.erb format.json { render json: @questionnaire } @@ -28,18 +29,23 @@ def new if session["devise.provider_data"] && session["devise.provider_data"]["info"] info = session["devise.provider_data"]["info"] - @skip_my_mlh_fields = true - @questionnaire.tap do |q| - q.phone = info["phone_number"] - q.level_of_study = info["level_of_study"] - q.major = info["major"] - q.date_of_birth = info["date_of_birth"] - q.gender = info["gender"] - - school = School.where(name: session["devise.provider_data"]["info"]["school"]["name"]).first_or_create do |s| - s.name = session["devise.provider_data"]["info"]["school"]["name"] + if all_my_mlh_fields_provided? + @skip_my_mlh_fields = true + @questionnaire.tap do |q| + q.phone = info["phone_number"] + q.level_of_study = info["level_of_study"] + q.major = info["major"] + q.date_of_birth = info["date_of_birth"] + q.gender = info["gender"] + + school = School.where(name: info["school"]["name"]).first_or_create do |s| + s.name = info["school"]["name"] + end + q.school_id = school.id end - q.school_id = school.id + else + flash[:notice] = nil + flash[:alert] = t(:my_mlh_null, scope: 'errors') end end @@ -124,6 +130,20 @@ def schools private + def all_my_mlh_fields_provided? + info = session["devise.provider_data"]["info"] + + return false if info["phone_number"].blank? + return false if info["level_of_study"].blank? + return false if info["major"].blank? + return false if info["date_of_birth"].blank? + return false if info["gender"].blank? + return false if info["school"].blank? + return false if info["school"]["name"].blank? + + true + end + def questionnaire_params params.require(:questionnaire).permit( :email, :experience, :gender, diff --git a/config/locales/en.yml b/config/locales/en.yml index e942e663f..ee640c844 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -36,6 +36,8 @@ en: registrations: user: signed_up: Welcome! Your account has been created. + errors: + my_mlh_null: Failed to retrieve application information from MyMLH, please continue manually. simple_form: hints: bus_list: From 208b2fc05de725d423b6cbb6b0c87e4da34f1154 Mon Sep 17 00:00:00 2001 From: "Chris Baudouin, Jr" Date: Tue, 5 Jan 2021 23:39:20 -0500 Subject: [PATCH 2/4] refactor: Cleans code --- app/controllers/questionnaires_controller.rb | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/app/controllers/questionnaires_controller.rb b/app/controllers/questionnaires_controller.rb index 850e64bb3..87433f371 100644 --- a/app/controllers/questionnaires_controller.rb +++ b/app/controllers/questionnaires_controller.rb @@ -133,15 +133,9 @@ def schools def all_my_mlh_fields_provided? info = session["devise.provider_data"]["info"] - return false if info["phone_number"].blank? - return false if info["level_of_study"].blank? - return false if info["major"].blank? - return false if info["date_of_birth"].blank? - return false if info["gender"].blank? - return false if info["school"].blank? - return false if info["school"]["name"].blank? - - true + return true unless info["phone_number"].blank? || info["level_of_study"].blank? || info["major"].blank? || + info["date_of_birth"].blank? || info["gender"].blank? || info["school"].blank? || + info["school"]["name"].blank? end def questionnaire_params From 92d361d0f1f219804c0f27a65b1479ca18bea87e Mon Sep 17 00:00:00 2001 From: Peter Kos Date: Wed, 6 Jan 2021 00:47:37 -0500 Subject: [PATCH 3/4] Attempt to pull any # of params from MyMLH frontend validation is triggered via page skip, whether successful (will skip) or not (no skip) --- app/controllers/questionnaires_controller.rb | 25 ++++++++++---------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/app/controllers/questionnaires_controller.rb b/app/controllers/questionnaires_controller.rb index 87433f371..132b38531 100644 --- a/app/controllers/questionnaires_controller.rb +++ b/app/controllers/questionnaires_controller.rb @@ -29,23 +29,24 @@ def new if session["devise.provider_data"] && session["devise.provider_data"]["info"] info = session["devise.provider_data"]["info"] - if all_my_mlh_fields_provided? - @skip_my_mlh_fields = true - @questionnaire.tap do |q| - q.phone = info["phone_number"] - q.level_of_study = info["level_of_study"] - q.major = info["major"] - q.date_of_birth = info["date_of_birth"] - q.gender = info["gender"] - + @skip_my_mlh_fields = true + if !all_my_mlh_fields_provided? + flash[:notice] = nil + flash[:alert] = t(:my_mlh_null, scope: 'errors') + end + @questionnaire.tap do |q| + q.phone = info["phone_number"] + q.level_of_study = info["level_of_study"] + q.major = info["major"] + q.date_of_birth = info["date_of_birth"] + q.gender = info["gender"] + + if info["school"] school = School.where(name: info["school"]["name"]).first_or_create do |s| s.name = info["school"]["name"] end q.school_id = school.id end - else - flash[:notice] = nil - flash[:alert] = t(:my_mlh_null, scope: 'errors') end end From f9004037f18be117ba92969cb0f678bfde40ef1e Mon Sep 17 00:00:00 2001 From: Peter Kos Date: Wed, 6 Jan 2021 00:55:45 -0500 Subject: [PATCH 4/4] Cange error msg, pet hound --- app/controllers/questionnaires_controller.rb | 2 +- config/locales/en.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/questionnaires_controller.rb b/app/controllers/questionnaires_controller.rb index 132b38531..2c709d393 100644 --- a/app/controllers/questionnaires_controller.rb +++ b/app/controllers/questionnaires_controller.rb @@ -30,7 +30,7 @@ def new if session["devise.provider_data"] && session["devise.provider_data"]["info"] info = session["devise.provider_data"]["info"] @skip_my_mlh_fields = true - if !all_my_mlh_fields_provided? + unless all_my_mlh_fields_provided? flash[:notice] = nil flash[:alert] = t(:my_mlh_null, scope: 'errors') end diff --git a/config/locales/en.yml b/config/locales/en.yml index ee640c844..b806ca6b6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -37,7 +37,7 @@ en: user: signed_up: Welcome! Your account has been created. errors: - my_mlh_null: Failed to retrieve application information from MyMLH, please continue manually. + my_mlh_null: Some information from MyMLH is missing, please fill in the missing fields. simple_form: hints: bus_list: @@ -138,7 +138,7 @@ en: title: Bus Lists schools: title: Schools - users: + users: title: Users & Staff users: All Users staff: "%{hackathon_name} Staff"