Skip to content

Commit ede300f

Browse files
feat: Updates MyMLH to V3 (#329)
* feat: Updates MyMLH to V3 * fix(User): Adds missing provider field * refactor: Updates MyMLH branding * Autofill MyMLH provider if info is missing * houndbot Co-authored-by: Peter Kos <[email protected]>
1 parent 675b3f6 commit ede300f

File tree

8 files changed

+29
-25
lines changed

8 files changed

+29
-25
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ gem 'bootsnap', '>= 1.1.0', require: false
3939

4040
# Authentication
4141
gem 'devise', '~> 4.7'
42-
gem 'omniauth-mlh', '~> 0.1'
42+
gem 'omniauth-mlh', '~> 0.4.1'
4343
gem 'doorkeeper', '~> 5.0'
4444
gem 'devise-doorkeeper'
4545
gem 'omniauth-rails_csrf_protection'

Gemfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ GEM
233233
minitest (>= 5.0)
234234
ruby-progressbar
235235
msgpack (1.3.3)
236-
multi_json (1.14.1)
236+
multi_json (1.15.0)
237237
multi_xml (0.6.0)
238238
multipart-post (2.1.1)
239239
mustache (1.1.1)
@@ -254,7 +254,7 @@ GEM
254254
omniauth (1.9.1)
255255
hashie (>= 3.4.6)
256256
rack (>= 1.6.2, < 3)
257-
omniauth-mlh (0.3.1)
257+
omniauth-mlh (0.4.1)
258258
activesupport
259259
omniauth (~> 1.0)
260260
omniauth-oauth2 (~> 1.3.1)
@@ -466,7 +466,7 @@ DEPENDENCIES
466466
minitest-reporters
467467
mustache (~> 1.0)
468468
mysql2 (>= 0.4.4, < 0.6.0)
469-
omniauth-mlh (~> 0.1)
469+
omniauth-mlh (~> 0.4.1)
470470
omniauth-rails_csrf_protection
471471
puma (~> 4.3)
472472
rails (~> 5.2.4.3)

app/controllers/questionnaires_controller.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ def new
3434
q.level_of_study = session["devise.provider_data"]["info"]["level_of_study"]
3535
q.major = session["devise.provider_data"]["info"]["major"]
3636
q.date_of_birth = session["devise.provider_data"]["info"]["date_of_birth"]
37-
q.shirt_size = session["devise.provider_data"]["info"]["shirt_size"]
38-
q.dietary_restrictions = session["devise.provider_data"]["info"]["dietary_restrictions"]
39-
q.special_needs = session["devise.provider_data"]["info"]["special_needs"]
4037
q.gender = session["devise.provider_data"]["info"]["gender"]
4138

4239
school = School.where(name: session["devise.provider_data"]["info"]["school"]["name"]).first_or_create do |s|

app/controllers/users/omniauth_callbacks_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ def mlh
44
if @user.persisted?
55
sign_in_and_redirect @user, event: :authentication # this will throw if @user is not activated
66
session["devise.provider_data"] = request.env["omniauth.auth"]
7-
set_flash_message(:notice, :success, kind: "My MLH") if is_navigational_format?
7+
set_flash_message(:notice, :success, kind: "MyMLH") if is_navigational_format?
88
else
99
redirect_to new_user_registration_url
1010
end

app/models/user.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,18 @@ def full_name
6565
def self.from_omniauth(auth)
6666
matching_provider = where(provider: auth.provider, uid: auth.uid)
6767
matching_email = where(email: auth.info.email)
68-
matching_provider.or(matching_email).first_or_create do |user|
68+
current_user = matching_provider.or(matching_email).first_or_create do |user|
6969
user.uid = auth.uid
70+
user.provider = auth.provider
7071
user.email = auth.info.email
7172
user.password = Devise.friendly_token[0, 20]
7273
end
74+
# Autofill MyMLH provider if provider info is missing
75+
# (as we are executing this from OAuth)
76+
if current_user.provider.blank?
77+
current_user.provider = auth.provider
78+
end
79+
current_user
7380
end
7481

7582
def self.non_admins

app/views/application/_questionnaire_summary.html.haml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,19 @@
1717
%p
1818
%b Traveling from:
1919
= @questionnaire.travel_not_from_school ? "Somewhere else (#{@questionnaire.travel_location})" : "My school (#{@questionnaire.school.full_name})"
20+
%p
21+
%b Shirt size:
22+
= @questionnaire.shirt_size
23+
%p
24+
%b Dietary restrictions
25+
= @questionnaire.dietary_restrictions || "<i>(none)</i>".html_safe
26+
%p
27+
%b Special needs
28+
= @questionnaire.special_needs || "<i>(none)</i>".html_safe
2029

2130
%fieldset
2231
- if @questionnaire.user.provider == 'mlh'
23-
%legend Provided by My MLH
32+
%legend Provided by MyMLH
2433
%p
2534
%b First name:
2635
= @questionnaire.first_name
@@ -48,12 +57,3 @@
4857
%p
4958
%b Level of study:
5059
= @questionnaire.level_of_study
51-
%p
52-
%b Shirt size:
53-
= @questionnaire.shirt_size
54-
%p
55-
%b Dietary restrictions
56-
= @questionnaire.dietary_restrictions || "<i>(none)</i>".html_safe
57-
%p
58-
%b Special needs
59-
= @questionnaire.special_needs || "<i>(none)</i>".html_safe

app/views/manage/questionnaires/_overview.html.haml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
= @questionnaire.age_at_time_of_event / 1.year
2424
%dt.col-md-4 Gender
2525
%dd.col-md-8= @questionnaire.gender
26-
%dt.col-md-4 Shirt size
27-
%dd.col-md-8= @questionnaire.shirt_size
2826
2927
= render 'checkin_compliance_card'
3028
@@ -33,6 +31,8 @@
3331
.card-header Special notices
3432
.card-body
3533
.row
34+
%dt.col-md-4 Shirt size
35+
%dd.col-md-8= @questionnaire.shirt_size
3636
%dt.col-md-4 Dietary restrictions
3737
%dd.col-md-8
3838
- if @questionnaire.dietary_restrictions.present?

app/views/questionnaires/_form.html.haml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919
= f.input :level_of_study, collection: collection_or_text(@questionnaire.level_of_study, Questionnaire::POSSIBLE_LEVELS_OF_STUDY), include_blank: "(select one...)", input_html: { "data-validate" => "presence" }, wrapper_html: { class: 'input--half' }
2020
= f.input :major, input_html: { "data-validate" => "presence" }, wrapper_html: { class: 'input--half' }
2121
= f.input :gender, collection: collection_or_text(@questionnaire.gender, Questionnaire::POSSIBLE_GENDERS), include_blank: "(select one...)", input_html: { "data-validate" => "presence" }, wrapper_html: { class: 'input--half' }
22-
= f.input :shirt_size, as: :select, collection: Questionnaire::POSSIBLE_SHIRT_SIZES, include_blank: "(select one...)", input_html: { "data-validate" => "presence" }, wrapper_html: { class: 'input--half' }
23-
= f.input :dietary_restrictions, as: :text, label: "Health restrictions", wrapper_html: { class: 'input--half' }, maxlength: Questionnaire::DIETARY_SPECIAL_NEEDS_MAX_LENGTH
24-
= f.input :special_needs, as: :text, label: "Special needs", wrapper_html: { class: 'input--half' }, maxlength: Questionnaire::DIETARY_SPECIAL_NEEDS_MAX_LENGTH
25-
2622
.right
2723
%button.button{ type: "button", "data-wizard" => "next" } Next
2824
@@ -46,6 +42,10 @@
4642
= f.input :travel_not_from_school, as: :radio_buttons, collection: { " My school" => false, " Somewhere else" => true }, label: "I am traveling from..."
4743
= f.input :travel_location, input_html: { "data-validate" => "presence", disabled: !travel_state }, wrapper_html: { style: travel_state ? "" : "display: none" }, label: "Where are you traveling from?", placeholder: "New York City"
4844

45+
= f.input :shirt_size, as: :select, collection: Questionnaire::POSSIBLE_SHIRT_SIZES, include_blank: "(select one...)", input_html: { "data-validate" => "presence" }
46+
= f.input :dietary_restrictions, as: :text, label: "Health restrictions", wrapper_html: { class: 'input--half' }, maxlength: Questionnaire::DIETARY_SPECIAL_NEEDS_MAX_LENGTH
47+
= f.input :special_needs, as: :text, label: "Special needs", wrapper_html: { class: 'input--half' }, maxlength: Questionnaire::DIETARY_SPECIAL_NEEDS_MAX_LENGTH
48+
4949
%hr
5050

5151
.form-inputs

0 commit comments

Comments
 (0)