Sha256: 57d719b17faf891cc4e8b8ddadae63cafba4c4b67210d57bea8f8d061b467966

Contents?: true

Size: 1.19 KB

Versions: 29

Compression:

Stored size: 1.19 KB

Contents

module CoalescingPanda
  class PersistentSession < ActiveRecord::Base
    serialize :data, JSONWithIndifferentAccess
    belongs_to :coalescing_panda_lti_account, :class_name => 'CoalescingPanda::LtiAccount'
    validates :coalescing_panda_lti_account_id, presence: true

    after_initialize do
      self.data ||= {}
      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.with_indifferent_access
      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

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
coalescing_panda-5.3.0 app/models/coalescing_panda/persistent_session.rb
coalescing_panda-5.2.2 app/models/coalescing_panda/persistent_session.rb
coalescing_panda-5.2.2.beta1 app/models/coalescing_panda/persistent_session.rb
coalescing_panda-5.2.1 app/models/coalescing_panda/persistent_session.rb
coalescing_panda-5.2.0 app/models/coalescing_panda/persistent_session.rb
coalescing_panda-5.2.0.beta2 app/models/coalescing_panda/persistent_session.rb
coalescing_panda-5.2.0.beta1 app/models/coalescing_panda/persistent_session.rb
coalescing_panda-5.1.13 app/models/coalescing_panda/persistent_session.rb
coalescing_panda-5.1.12 app/models/coalescing_panda/persistent_session.rb
coalescing_panda-5.1.11 app/models/coalescing_panda/persistent_session.rb
coalescing_panda-5.1.10 app/models/coalescing_panda/persistent_session.rb
coalescing_panda-5.1.9 app/models/coalescing_panda/persistent_session.rb
coalescing_panda-5.1.8 app/models/coalescing_panda/persistent_session.rb
coalescing_panda-5.1.7 app/models/coalescing_panda/persistent_session.rb
coalescing_panda-5.1.6 app/models/coalescing_panda/persistent_session.rb
coalescing_panda-5.1.5 app/models/coalescing_panda/persistent_session.rb
coalescing_panda-5.1.4 app/models/coalescing_panda/persistent_session.rb
coalescing_panda-5.1.3.beta.2 app/models/coalescing_panda/persistent_session.rb
coalescing_panda-5.1.3.beta.1 app/models/coalescing_panda/persistent_session.rb
coalescing_panda-5.1.3 app/models/coalescing_panda/persistent_session.rb