Skip to content

develop <- 2.1.4 #519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions app/controllers/questionnaires_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -29,17 +30,23 @@ def new
if session["devise.provider_data"] && session["devise.provider_data"]["info"]
info = session["devise.provider_data"]["info"]
@skip_my_mlh_fields = true
unless 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"]

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 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
q.school_id = school.id
end
end

Expand Down Expand Up @@ -84,12 +91,13 @@ def update
update_params = questionnaire_params
update_params = convert_school_name_to_id(update_params)

@agreements = Agreement.all
respond_to do |format|
if @questionnaire.update_attributes(update_params)
format.html { redirect_to questionnaires_path, notice: 'Application was successfully updated.' }
format.json { head :no_content }
else
format.html { redirect_to edit_questionnaires_url }
format.html { render action: "edit" }
format.json { render json: @questionnaire.errors, status: :unprocessable_entity }
end
end
Expand Down Expand Up @@ -124,6 +132,14 @@ def schools

private

def all_my_mlh_fields_provided?
info = session["devise.provider_data"]["info"]

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
params.require(:questionnaire).permit(
:email, :experience, :gender,
Expand Down
4 changes: 3 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ en:
registrations:
user:
signed_up: Welcome! Your account has been created.
errors:
my_mlh_null: Some information from MyMLH is missing, please fill in the missing fields.
simple_form:
hints:
bus_list:
Expand Down Expand Up @@ -136,7 +138,7 @@ en:
title: Bus Lists
schools:
title: Schools
users:
users:
title: Users & Staff
users: All Users
staff: "%{hackathon_name} Staff"
Expand Down