diff --git a/app/lib/warden/ppy_auth_strategy.rb b/app/lib/warden/ppy_auth_strategy.rb index 5e9ca2d..2f0c0f0 100644 --- a/app/lib/warden/ppy_auth_strategy.rb +++ b/app/lib/warden/ppy_auth_strategy.rb @@ -20,7 +20,6 @@ def authenticate! @user.password = Digest::SHA256.hexdigest(rand().to_s) @user.admin = false @user.active = true - @user.user_type = request.headers[TYPE] @user.role = User::INSTRUCTOR_ROLE @user.uid = request.headers[USER] @user.username = request.headers[USER] @@ -29,6 +28,8 @@ def authenticate! @user.univ_id = request.headers[CYIN] @user.audit_comment = 'PpyAuthStrategy created new user from authenticated PYORK headers' + @user.set_user_type(request.headers[TYPE]) + if !@user.valid? fail!('Not authenticated. User validation failed.') return false @@ -39,7 +40,7 @@ def authenticate! resource = @user end - resource.user_type = request.headers[TYPE] + resource.set_user_type(request.headers[TYPE]) resource.uid = request.headers[USER] resource.username = request.headers[USER] resource.email = request.headers[EMAIL] diff --git a/app/models/user.rb b/app/models/user.rb index 3916852..f0eac48 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -47,6 +47,13 @@ class User < ApplicationRecord audited associated_with: :location has_associated_audits + def set_user_type(type) + self.user_type = FACULTY if type.downcase.include?('faculty') + self.user_type = GRADUATE if type.downcase.include?('graduate') + self.user_type = UNDERGRAD if type.downcase.include?('undergrad') + self.user_type = STAFF if type.downcase.include?('staff') + end + def update_external_alma(user_id) return false if user_id.nil? || Setting.alma_apikey.nil? || Setting.alma_apikey.strip.length == 0