Class: PandaPal::Session

Inherits:
PandaPalRecord show all
Defined in:
app/models/panda_pal/session.rb

Defined Under Namespace

Classes: DataSerializer, RoleStore

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



9
10
11
12
13
14
15
# File 'app/models/panda_pal/session.rb', line 9

def [](key)
  if column_names.include?(key.to_s)
    super
  else
    data[key]
  end
end

#[]=(key, value) ⇒ Object



17
18
19
20
21
22
23
# File 'app/models/panda_pal/session.rb', line 17

def []=(key, value)
  if column_names.include?(key.to_s)
    super
  else
    data[key] = value
  end
end

#cache(key, &blk) ⇒ Object



25
26
27
28
# File 'app/models/panda_pal/session.rb', line 25

def cache(key, &blk)
  data[:cache] ||= {}
  data[:cache][key] ||= blk.call
end

#canvas_account_role_labels(account = 'self') ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/models/panda_pal/session.rb', line 70

def ( = 'self')
   = 'self' if .to_s == "root"
   = .canvas_id if .respond_to?(:canvas_id)

  if "::Admin".safe_constantize && ::Admin < ::ActiveRecord::Base
     = current_organization. if  == 'self'
    adm_query = ::Admin.where(canvas_account_id: , workflow_state: "active")
    adm_query.pluck(:role_name)
  else
    Rails.cache.fetch([self.class.name, "AccountAdminLinks", , canvas_user_id], expires_in: 1.hour) do
      admin_entries = canvas_sync_client.(, user_id: [canvas_user_id])
      admin_entries = admin_entries.select{|ent| ent[:workflow_state] == 'active' }
      admin_entries.map{|ent| ent[:role] }
    end
  end
end

#canvas_role_labelsObject



65
66
67
68
# File 'app/models/panda_pal/session.rb', line 65

def canvas_role_labels
  labels = get_lti_cust_param('custom_canvas_role')
  labels.is_a?(String) ? labels.split(',') : []
end

#canvas_site_admin?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'app/models/panda_pal/session.rb', line 91

def canvas_site_admin?
  lti_roles.system_roles.include?("sys_admin")
end

#custom_lti_paramsObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/panda_pal/session.rb', line 44

def custom_lti_params
  # LT 1.3
  custom_params = launch_params["https://purl.imsglobal.org/spec/lti/claim/custom"]
  return custom_params if custom_params.present?

  # LTI 1.0/1.1
  custom_params = {}
  launch_params.each do |k, v|
    next unless k.start_with?("custom_")
    custom_params[k[7..-1]] = v
  end

  custom_params.with_indifferent_access
end

#get_lti_cust_param(key) ⇒ Object



59
60
61
62
63
# File 'app/models/panda_pal/session.rb', line 59

def get_lti_cust_param(key)
  nkey = key.to_s.gsub(/^custom_/, '')

  launch_params.dig("https://purl.imsglobal.org/spec/lti/claim/custom", nkey) || launch_params[nkey] || launch_params["custom_#{nkey}"]
end

#launch_paramsObject



30
31
32
# File 'app/models/panda_pal/session.rb', line 30

def launch_params
  data[:launch_params] || {}
end

#lti_launch_placementObject



40
41
42
# File 'app/models/panda_pal/session.rb', line 40

def lti_launch_placement
  launch_params['https://www.instructure.com/placement'] || launch_params[:launch_type]
end

#lti_platformObject



34
35
36
37
38
# File 'app/models/panda_pal/session.rb', line 34

def lti_platform
  return nil unless data[:lti_platform].present?

  @lti_platform ||= Platform.from_serialized(data[:lti_platform])
end

#lti_rolesObject



87
88
89
# File 'app/models/panda_pal/session.rb', line 87

def lti_roles
  @lti_roles ||= RoleStore.new(launch_params["https://purl.imsglobal.org/spec/lti/claim/roles"] || launch_params['ext_roles'] || '')
end