class User
Schema Information
Table name: users
id :bigint not null, primary key
current_sign_in_at :datetime
current_sign_in_ip :string
email :string
encrypted_password :string default(""), not null
fallback_role :integer
family_name :string not null
given_name :string not null
last_sign_in_at :datetime
last_sign_in_ip :string
provider :string
remember_created_at :datetime
reporting_api_session_token :string
session_token :string
show_in_suppliers :boolean default(FALSE), not null
sign_in_count :integer default(0), not null
uid :string
created_at :datetime not null
updated_at :datetime not null
Indexes
index_users_on_email (email) UNIQUE index_users_on_provider_and_uid (provider,uid) UNIQUE index_users_on_reporting_api_session_token (reporting_api_session_token) UNIQUE
Attributes
Public Class Methods
Source
# File app/models/user.rb, line 91 def self.find_or_create_from_cis2_oidc(userinfo, teams) user = User.find_or_initialize_by( provider: userinfo[:provider], uid: userinfo[:uid] ) raw_info = userinfo[:extra][:raw_info] user.assign_attributes( raw_info.slice(:email, :family_name, :given_name).to_h ) user.session_token = raw_info[:sid].presence || Devise.friendly_token ActiveRecord::Base.transaction do user.save! teams.each { |team| user.teams << team unless user.teams.include?(team) } user end end
Public Instance Methods
Source
# File app/models/user.rb, line 186 def can_access_sensitive_flagged_records? if cis2_enabled? cis2_info.can_access_sensitive_flagged_records? else fallback_role_superuser? end end
Source
# File app/models/user.rb, line 194 def can_perform_local_system_administration? if cis2_enabled? cis2_info.can_perform_local_system_administration? else fallback_role_superuser? end end
Source
# File app/models/user.rb, line 204 def cis2_enabled? = Settings.cis2.enabled def fhir_mapper = @fhir_mapper ||= FHIRMapper::User.new(self)
Source
# File app/models/user.rb, line 206 def fhir_mapper = @fhir_mapper ||= FHIRMapper::User.new(self) end
Source
# File app/models/user.rb, line 157 def is_healthcare_assistant? if cis2_enabled? cis2_info.is_healthcare_assistant? else fallback_role_healthcare_assistant? end end
Source
# File app/models/user.rb, line 145 def is_medical_secretary? if cis2_enabled? cis2_info.is_medical_secretary? else fallback_role_medical_secretary? end end
Source
# File app/models/user.rb, line 153 def is_nurse? cis2_enabled? ? cis2_info.is_nurse? : fallback_role_nurse? end
Source
# File app/models/user.rb, line 165 def is_prescriber? cis2_enabled? ? cis2_info.is_prescriber? : fallback_role_prescriber? end
Source
# File app/models/user.rb, line 169 def is_superuser? can_access_sensitive_flagged_records? || can_perform_local_system_administration? end
Source
# File app/models/user.rb, line 174 def is_support? cis2_enabled? ? cis2_info.is_support? : fallback_role_support? end
Source
# File app/models/user.rb, line 178 def is_support_with_pii_access? if cis2_enabled? cis2_info.is_support_with_pii_access? else fallback_role_support? end end
Source
# File app/models/user.rb, line 122 def programmes = selected_team&.programmes def role_name cis2_info.role_name if cis2_enabled? end def role_description role = if is_healthcare_assistant? "Healthcare Assistant" elsif is_prescriber? "Prescriber" elsif is_nurse? "Nurse" elsif is_medical_secretary? "Medical secretary" else "Support" end is_superuser? ? "#{role} (Superuser)" : role end def is_medical_secretary? if cis2_enabled? cis2_info.is_medical_secretary? else fallback_role_medical_secretary? end end def is_nurse? cis2_enabled? ? cis2_info.is_nurse? : fallback_role_nurse? end def is_healthcare_assistant? if cis2_enabled? cis2_info.is_healthcare_assistant? else fallback_role_healthcare_assistant? end end def is_prescriber? cis2_enabled? ? cis2_info.is_prescriber? : fallback_role_prescriber? end def is_superuser? can_access_sensitive_flagged_records? || can_perform_local_system_administration? end def is_support? cis2_enabled? ? cis2_info.is_support? : fallback_role_support? end def is_support_with_pii_access? if cis2_enabled? cis2_info.is_support_with_pii_access? else fallback_role_support? end end def can_access_sensitive_flagged_records? if cis2_enabled? cis2_info.can_access_sensitive_flagged_records? else fallback_role_superuser? end end def can_perform_local_system_administration? if cis2_enabled? cis2_info.can_perform_local_system_administration? else fallback_role_superuser? end end private def cis2_enabled? = Settings.cis2.enabled def fhir_mapper = @fhir_mapper ||= FHIRMapper::User.new(
Source
# File app/models/user.rb, line 114 def requires_email_and_password? provider.blank? || uid.blank? end
Source
# File app/models/user.rb, line 128 def role_description role = if is_healthcare_assistant? "Healthcare Assistant" elsif is_prescriber? "Prescriber" elsif is_nurse? "Nurse" elsif is_medical_secretary? "Medical secretary" else "Support" end is_superuser? ? "#{role} (Superuser)" : role end
Source
# File app/models/user.rb, line 124 def role_name cis2_info.role_name if cis2_enabled? end
Source
# File app/models/user.rb, line 118 def selected_organisation = cis2_info.organisation def selected_team = cis2_info.team def programmes = selected_team&.programmes def role_name cis2_info.role_name if cis2_enabled? end def role_description role = if is_healthcare_assistant? "Healthcare Assistant" elsif is_prescriber? "Prescriber" elsif is_nurse? "Nurse" elsif is_medical_secretary? "Medical secretary" else "Support" end is_superuser? ? "#{role} (Superuser)" : role end def is_medical_secretary? if cis2_enabled? cis2_info.is_medical_secretary? else fallback_role_medical_secretary? end end def is_nurse? cis2_enabled? ? cis2_info.is_nurse? : fallback_role_nurse? end def is_healthcare_assistant? if cis2_enabled? cis2_info.is_healthcare_assistant? else fallback_role_healthcare_assistant? end end def is_prescriber? cis2_enabled? ? cis2_info.is_prescriber? : fallback_role_prescriber? end def is_superuser? can_access_sensitive_flagged_records? || can_perform_local_system_administration? end def is_support? cis2_enabled? ? cis2_info.is_support? : fallback_role_support? end def is_support_with_pii_access? if cis2_enabled? cis2_info.is_support_with_pii_access? else fallback_role_support? end end def can_access_sensitive_flagged_records? if cis2_enabled? cis2_info.can_access_sensitive_flagged_records? else fallback_role_superuser? end end def can_perform_local_system_administration? if cis2_enabled? cis2_info.can_perform_local_system_administration? else fallback_role_superuser? end end private def cis2_enabled? = Settings.cis2.enabled def fhir_mapper = @fhir_mapper ||= FHIRMapper::
Source
# File app/models/user.rb, line 120 def selected_team = cis2_info.team def programmes = selected_team&.programmes def role_name cis2_info.role_name if cis2_enabled? end def role_description role = if is_healthcare_assistant? "Healthcare Assistant" elsif is_prescriber? "Prescriber" elsif is_nurse? "Nurse" elsif is_medical_secretary? "Medical secretary" else "Support" end is_superuser? ? "#{role} (Superuser)" : role end def is_medical_secretary? if cis2_enabled? cis2_info.is_medical_secretary? else fallback_role_medical_secretary? end end def is_nurse? cis2_enabled? ? cis2_info.is_nurse? : fallback_role_nurse? end def is_healthcare_assistant? if cis2_enabled? cis2_info.is_healthcare_assistant? else fallback_role_healthcare_assistant? end end def is_prescriber? cis2_enabled? ? cis2_info.is_prescriber? : fallback_role_prescriber? end def is_superuser? can_access_sensitive_flagged_records? || can_perform_local_system_administration? end def is_support? cis2_enabled? ? cis2_info.is_support? : fallback_role_support? end def is_support_with_pii_access? if cis2_enabled? cis2_info.is_support_with_pii_access? else fallback_role_support? end end def can_access_sensitive_flagged_records? if cis2_enabled? cis2_info.can_access_sensitive_flagged_records? else fallback_role_superuser? end end def can_perform_local_system_administration? if cis2_enabled? cis2_info.can_perform_local_system_administration? else fallback_role_superuser? end end private def cis2_enabled? = Settings.cis2.enabled def fhir_mapper = @fhir_mapper ||= FHIRMapper::User.