Class: MHVPrescriptionsPolicy

Inherits:
Struct
  • Object
show all
Defined in:
app/policies/mhv_prescriptions_policy.rb

Constant Summary collapse

RX_ACCOUNT_TYPES =
%w[Premium Advanced].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#mhv_prescriptionsObject

Returns the value of attribute mhv_prescriptions

Returns:

  • (Object)

    the current value of mhv_prescriptions



3
4
5
# File 'app/policies/mhv_prescriptions_policy.rb', line 3

def mhv_prescriptions
  @mhv_prescriptions
end

#userObject

Returns the value of attribute user

Returns:

  • (Object)

    the current value of user



3
4
5
# File 'app/policies/mhv_prescriptions_policy.rb', line 3

def user
  @user
end

Instance Method Details

#access?Boolean

NOTE: This check for va_patient, might break functionality for mhv-sign-in users, since we only query MVI for “Premium”, and Rx is technically available to non-premium.

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/policies/mhv_prescriptions_policy.rb', line 8

def access?
  service_name = user.identity.[:service_name]
  access = RX_ACCOUNT_TYPES.include?(user.) &&
           (user.va_patient? || service_name == SignIn::Constants::Auth::MHV)
  unless access
    Rails.logger.info('RX ACCESS DENIED',
                      account_type: user..presence || 'false',
                      mhv_id: user.mhv_correlation_id.presence || 'false',
                      sign_in_service: service_name,
                      va_facilities: user.va_treatment_facility_ids.length,
                      va_patient: user.va_patient?)
  end
  access
end