Class: Renalware::User
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Renalware::User
- Includes:
- Deviseable, Personable
- Defined in:
- app/models/renalware/user.rb
Instance Attribute Summary collapse
-
#with_extended_validation ⇒ Object
Non-persistent attribute to signify we want to use extended validation.
Class Method Summary collapse
- .policy_class ⇒ Object
-
.ransackable_scopes(_auth_object = nil) ⇒ Object
So we can uses these scopes as Ransack predicates eg.
Instance Method Summary collapse
-
#auth_token ⇒ Object
Create a sha that can be saved in another model to indicate a user has authenticated (or perhaps more correctly, authorised) an action - e.g.
- #generate_new_authentication_token! ⇒ Object
-
#has_role?(name) ⇒ Boolean
rubocop:disable Naming/PredicateName.
-
#professional_signature ⇒ Object
Official name for use when displaying e.g.
-
#role_names ⇒ Object
rubocop:enable Naming/PredicateName.
Instance Attribute Details
#with_extended_validation ⇒ Object
Non-persistent attribute to signify we want to use extended validation. We need to refactor this by ising a form object for updating a user.
47 48 49 |
# File 'app/models/renalware/user.rb', line 47 def with_extended_validation @with_extended_validation end |
Class Method Details
.policy_class ⇒ Object
49 50 51 |
# File 'app/models/renalware/user.rb', line 49 def self.policy_class UserPolicy end |
.ransackable_scopes(_auth_object = nil) ⇒ Object
So we can uses these scopes as Ransack predicates eg. { expired: true }
54 55 56 |
# File 'app/models/renalware/user.rb', line 54 def self.ransackable_scopes(_auth_object = nil) %i(unapproved inactive expired) end |
Instance Method Details
#auth_token ⇒ Object
Create a sha that can be saved in another model to indicate a user has authenticated (or perhaps more correctly, authorised) an action - e.g. in HD Session form where a nurse and witness both enter their credentials against a prescription administered on HD. The idea is that we can check the token belongs to the user buy regenerating the token at any time and checking it still matches. Unlike Devise.friendly_token, we can always regenerate the same token here for any user as it is salted with the same secret. This secret is not stored git for staging and production environments.
89 90 91 92 93 |
# File 'app/models/renalware/user.rb', line 89 def auth_token digest = OpenSSL::Digest.new("sha256") key = Rails.application.secrets.secret_key_base OpenSSL::HMAC.hexdigest(digest, key, id.to_s) end |
#generate_new_authentication_token! ⇒ Object
76 77 78 79 80 |
# File 'app/models/renalware/user.rb', line 76 def generate_new_authentication_token! build_authentication_token.tap do |token| update_column(:authentication_token, token) end end |
#has_role?(name) ⇒ Boolean
rubocop:disable Naming/PredicateName
59 60 61 |
# File 'app/models/renalware/user.rb', line 59 def has_role?(name) role_names.include?(name.to_s) end |
#professional_signature ⇒ Object
Official name for use when displaying e.g. on a letter. For example:
Dr Isaac Newton (Consultant Gravitationalist)
70 71 72 73 74 |
# File 'app/models/renalware/user.rb', line 70 def professional_signature signed = signature || full_name signed += " (#{professional_position})" if professional_position? signed end |
#role_names ⇒ Object
rubocop:enable Naming/PredicateName
64 65 66 |
# File 'app/models/renalware/user.rb', line 64 def role_names @role_names ||= roles.pluck(:name) end |