Skip to content

Commit

Permalink
set user_type field based on the value of the PYORK_TYPE header
Browse files Browse the repository at this point in the history
  • Loading branch information
amtuannguyen committed Jan 8, 2025
1 parent a1fd667 commit c98aa58
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/lib/warden/ppy_auth_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand All @@ -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]
Expand Down
7 changes: 7 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c98aa58

Please sign in to comment.