Sha256: dd130abae140b417883d1b27f37ec9d90ad29631effc780bde302106141bf573

Contents?: true

Size: 1.08 KB

Versions: 8

Compression:

Stored size: 1.08 KB

Contents

module CoalescingPanda
  class LtiAccount < ActiveRecord::Base
    validates :name, :key, uniqueness: true
    validates :name, :key, :secret, presence: true
    has_many :lti_nonces, foreign_key: :coalescing_panda_lti_account_id, class_name: 'CoalescingPanda::LtiNonce'
    has_many :terms, foreign_key: :coalescing_panda_lti_account_id, class_name: 'CoalescingPanda::Term'
    has_many :courses, foreign_key: :coalescing_panda_lti_account_id, class_name: 'CoalescingPanda::Course'
    has_many :users, foreign_key: :coalescing_panda_lti_account_id, class_name: 'CoalescingPanda::User'
    has_many :sections, through: :courses
    has_many :enrollments, through: :sections
    has_many :assignments, through: :courses
    has_many :submissions, through: :assignments

    serialize :settings

    def validate_nonce(nonce, timestamp)
      cleanup_nonce
      if timestamp > 15.minutes.ago
        lti_nonces.create(nonce: nonce, timestamp: timestamp).persisted?
      end
    end

    private

    def cleanup_nonce
      lti_nonces.where('timestamp > ?', 15.minutes.ago).delete_all
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
coalescing_panda-3.1.5 app/models/coalescing_panda/lti_account.rb
coalescing_panda-3.1.4 app/models/coalescing_panda/lti_account.rb
coalescing_panda-3.1.3 app/models/coalescing_panda/lti_account.rb
coalescing_panda-3.1.2 app/models/coalescing_panda/lti_account.rb
coalescing_panda-3.1.1 app/models/coalescing_panda/lti_account.rb
coalescing_panda-3.1.0 app/models/coalescing_panda/lti_account.rb
coalescing_panda-3.0.1 app/models/coalescing_panda/lti_account.rb
coalescing_panda-3.0.0 app/models/coalescing_panda/lti_account.rb