diff --git a/app/controllers/questionnaires_controller.rb b/app/controllers/questionnaires_controller.rb index 0aed9e76f..f8520ca04 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 } @@ -29,6 +30,10 @@ 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"] @@ -36,10 +41,12 @@ def new 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 @@ -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 @@ -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, diff --git a/config/locales/en.yml b/config/locales/en.yml index e942e663f..b806ca6b6 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: Some information from MyMLH is missing, please fill in the missing fields. simple_form: hints: bus_list: @@ -136,7 +138,7 @@ en: title: Bus Lists schools: title: Schools - users: + users: title: Users & Staff users: All Users staff: "%{hackathon_name} Staff"