Skip to content

Commit f7e2a9d

Browse files
fix: Resolves issue preventing new MyMLH users from creating questionnaires (#516)
* fix: Resolves issue preventing new MyMLH users from creating questionnaires * refactor: Cleans code * Attempt to pull any # of params from MyMLH frontend validation is triggered via page skip, whether successful (will skip) or not (no skip) * Cange error msg, pet hound Co-authored-by: Peter Kos <[email protected]>
1 parent 2726945 commit f7e2a9d

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

app/controllers/questionnaires_controller.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def logged_in
1111
# GET /apply
1212
# GET /apply.json
1313
def show
14+
flash[:alert] = nil
1415
respond_to do |format|
1516
format.html # show.html.erb
1617
format.json { render json: @questionnaire }
@@ -29,17 +30,23 @@ def new
2930
if session["devise.provider_data"] && session["devise.provider_data"]["info"]
3031
info = session["devise.provider_data"]["info"]
3132
@skip_my_mlh_fields = true
33+
unless all_my_mlh_fields_provided?
34+
flash[:notice] = nil
35+
flash[:alert] = t(:my_mlh_null, scope: 'errors')
36+
end
3237
@questionnaire.tap do |q|
3338
q.phone = info["phone_number"]
3439
q.level_of_study = info["level_of_study"]
3540
q.major = info["major"]
3641
q.date_of_birth = info["date_of_birth"]
3742
q.gender = info["gender"]
3843

39-
school = School.where(name: session["devise.provider_data"]["info"]["school"]["name"]).first_or_create do |s|
40-
s.name = session["devise.provider_data"]["info"]["school"]["name"]
44+
if info["school"]
45+
school = School.where(name: info["school"]["name"]).first_or_create do |s|
46+
s.name = info["school"]["name"]
47+
end
48+
q.school_id = school.id
4149
end
42-
q.school_id = school.id
4350
end
4451
end
4552

@@ -124,6 +131,14 @@ def schools
124131

125132
private
126133

134+
def all_my_mlh_fields_provided?
135+
info = session["devise.provider_data"]["info"]
136+
137+
return true unless info["phone_number"].blank? || info["level_of_study"].blank? || info["major"].blank? ||
138+
info["date_of_birth"].blank? || info["gender"].blank? || info["school"].blank? ||
139+
info["school"]["name"].blank?
140+
end
141+
127142
def questionnaire_params
128143
params.require(:questionnaire).permit(
129144
:email, :experience, :gender,

config/locales/en.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ en:
3636
registrations:
3737
user:
3838
signed_up: Welcome! Your account has been created.
39+
errors:
40+
my_mlh_null: Some information from MyMLH is missing, please fill in the missing fields.
3941
simple_form:
4042
hints:
4143
bus_list:
@@ -136,7 +138,7 @@ en:
136138
title: Bus Lists
137139
schools:
138140
title: Schools
139-
users:
141+
users:
140142
title: Users & Staff
141143
users: All Users
142144
staff: "%{hackathon_name} Staff"

0 commit comments

Comments
 (0)