require "panda_pal/engine" require 'panda_pal/plugins' require 'panda_pal/helpers' require 'oauth/request_proxy/rack_request' require 'oauth/request_proxy/action_dispatch_request' Dir[File.dirname(__FILE__) + "/panda_pal/concerns/**/*.rb"].each { |file| require file } module PandaPal class LtiNavigationInUse < StandardError;end class NotMounted < StandardError;end @@lti_navigation = {} @@lti_options = {} @@lti_properties = {} @@lti_environments = {} @@lti_custom_params = {} @@extensions = {} @@lti_private_key = nil def self.lti_options= lti_options @@lti_options = lti_options end def self.lti_options @@lti_options.deep_dup end def self.lti_properties= lti_properties @@lti_properties = lti_properties end def self.lti_properties @@lti_properties.deep_dup end def self.lti_environments=(lti_environments) @@lti_environments = lti_environments end def self.lti_environments @@lti_environments.deep_dup end def self.lti_custom_params=(custom_params) @@lti_custom_params = custom_params.with_indifferent_access end def self.lti_custom_params @@lti_custom_params.deep_dup end def self.stage_navigation(navigation, options) @@lti_navigation[navigation] ||= {} @@lti_navigation[navigation].merge!(options) end def self.lti_paths @@lti_navigation.deep_dup end def self.lti_private_key key = @@lti_private_key.presence key ||= ENV['LTI_PRIVATE_KEY'].presence key ||= File.read(File.join( File.dirname(__FILE__), "../config/dev_lti_key.key")) if Rails.env.development? return nil unless key.present? key = OpenSSL::PKey::RSA.new(key) if key.is_a?(String) key end def self.lti_private_key=(v) @@lti_private_key = k end def self.register_extension(type, modul) type = normalize_ext_type(type) @@extensions[type] ||= [] @@extensions[type] << modul.to_s end def self.extensions_for(type) (@@extensions[normalize_ext_type(type)] || []).uniq end def self.resolved_extensions_for(type) extensions_for(type).map do |ext| ext.safe_constantize end.compact end private def self.normalize_ext_type(type) type = type.to_s type = "#{self.to_s}::#{type}" unless type.start_with?('::') || type.start_with?(self.to_s) type end def self.validate_pandapal_config! errors = [] validate_lti_navigation(errors) if errors.present? lines = errors.map { |e| " - #{e}" } raise "PandaPal was not configured correctly:\n#{lines.join("\n")}" end end def self.validate_lti_navigation(errors = []) @@lti_navigation.each do |k, v| next if v[:route_helper_key] errors << "lti navigation '#{k}' does not have a Route!" unless (LaunchUrlHelpers.launch_url(k) rescue nil) end errors end end PandaPal.register_extension 'Organization', '::OrganizationExtension'