module CoalescingPanda class PersistentSession < ActiveRecord::Base serialize :data, Hash belongs_to :coalescing_panda_lti_account, :class_name => 'CoalescingPanda::LtiAccount' validates :coalescing_panda_lti_account_id, presence: true after_initialize do self.session_key ||= SecureRandom.urlsafe_base64(60) end def self.create_from_launch(launch_params, account_id) session = PersistentSession.new(coalescing_panda_lti_account_id: account_id) session.data[:launch_params] = launch_params.to_unsafe_h session.data[:roles] = launch_params['roles'].split(',').map { |role| case role.downcase.strip when 'admin' :admin when 'urn:lti:instrole:ims/lis/administrator' :admin when 'learner' :student when 'instructor' :teacher when 'urn:lti:role:ims/lis/teachingassistant' :ta when 'contentdeveloper' :designer when 'urn:lti:instrole:ims/lis/observer' :observer else :none end }.uniq session.save! session end end end