Class: MHVMessagingPolicy

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#mhv_messagingObject

Returns the value of attribute mhv_messaging

Returns:

  • (Object)

    the current value of mhv_messaging



5
6
7
# File 'app/policies/mhv_messaging_policy.rb', line 5

def mhv_messaging
  @mhv_messaging
end

#userObject

Returns the value of attribute user

Returns:

  • (Object)

    the current value of user



5
6
7
# File 'app/policies/mhv_messaging_policy.rb', line 5

def user
  @user
end

Instance Method Details

#access?Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
# File 'app/policies/mhv_messaging_policy.rb', line 6

def access?
  return false unless user.mhv_correlation_id

  client = SM::Client.new(session: { user_id: user.mhv_correlation_id })
  validate_client(client)
end

#log_denial_detailsObject (private)



34
35
36
37
38
39
40
# File 'app/policies/mhv_messaging_policy.rb', line 34

def log_denial_details
  Rails.logger.info('SM ACCESS DENIED IN MOBILE POLICY',
                    mhv_id: user.mhv_correlation_id.presence || 'false',
                    sign_in_service: user.identity.[:service_name],
                    va_facilities: user.va_treatment_facility_ids.length,
                    va_patient: user.va_patient?)
end

#mobile_access?Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
# File 'app/policies/mhv_messaging_policy.rb', line 13

def mobile_access?
  return false unless user.mhv_correlation_id

  client = Mobile::V0::Messaging::Client.new(session: { user_id: user.mhv_correlation_id })
  validate_client(client)
end

#validate_client(client) ⇒ Object (private)



22
23
24
25
26
27
28
29
30
31
32
# File 'app/policies/mhv_messaging_policy.rb', line 22

def validate_client(client)
  if client.session.expired?
    client.authenticate
    !client.session.expired?
  else
    true
  end
rescue
  log_denial_details
  false
end