coalescing_panda 5.0.0.beta.1 → 5.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 04cba708232c8e0c9b6a463672856af29a163ea5c99f3f1f3cc9a25574384e4a
4
- data.tar.gz: 4bf9e5644ef1d4224de236ae57cd966eda287ca1942b8bc6f5350362dc6e2a64
3
+ metadata.gz: 306dfeeb30b6ae7918306493e16fad1153218caff10326e85e20767fe65e6939
4
+ data.tar.gz: 8e1d71edd52810dc203bffabc505f4bf1d594b9dd6a41af69850d00d9a7a49bf
5
5
  SHA512:
6
- metadata.gz: 4d58f85ac65e2bc2374dfa77ded152c6afd0193c46a0c28f0ef19b14270112888d553efdb22d063a44c31257cd70e0ac5aa9173c2f830da5e1722765bfee85aa
7
- data.tar.gz: b59db693a31dc3fe091aa4bfa7838008a43b69f5a4c486dd55a74bcf684a88be3719eff5bc0bdf63ba043111a36324c45584bd0dc39084069daad62a09ecdb37
6
+ metadata.gz: c07375ac5edf196130f97ad74d87b78895c0c75ee22452b739932b525a5cb79a29e6e4a751ad0addf2e92782e466f4403ace209399245d5fb0d26f20764e892d
7
+ data.tar.gz: 923158157e37c46b0374ccebcd5b3c9dac3e7f70d2df759aa6f340fec35f4b179b2fc3fe8ac51babe7a95ea0f569ff066f07bd46ee536e5679ad89da3b77472e
@@ -0,0 +1,3 @@
1
+ //= link_tree ../../images
2
+ //= link_directory ../../javascripts/coalescing_panda/ .js
3
+ //= link_directory ../../stylesheets/coalescing_panda/ .css
@@ -7,6 +7,8 @@ module CoalescingPanda
7
7
  end
8
8
 
9
9
  def redirect
10
+ use_secure_headers_override(:allow_inline_scripts)
11
+
10
12
  if !params[:error] && retrieve_oauth_state
11
13
  lti_account = LtiAccount.find_by_key(@oauth_state.data[:key])
12
14
  client_id = lti_account.oauth2_client_id
@@ -0,0 +1,13 @@
1
+ module CoalescingPanda
2
+ class JSONWithIndifferentAccess
3
+ def self.load(str)
4
+ return nil unless str.present?
5
+ parsed = JSON.parse(str)
6
+ parsed.is_a?(Hash) ? HashWithIndifferentAccess.new(parsed) : parsed
7
+ end
8
+
9
+ def self.dump(obj)
10
+ JSON.dump(obj)
11
+ end
12
+ end
13
+ end
@@ -1,10 +1,11 @@
1
1
  module CoalescingPanda
2
2
  class PersistentSession < ActiveRecord::Base
3
- serialize :data, Hash
3
+ serialize :data, JSONWithIndifferentAccess
4
4
  belongs_to :coalescing_panda_lti_account, :class_name => 'CoalescingPanda::LtiAccount'
5
5
  validates :coalescing_panda_lti_account_id, presence: true
6
6
 
7
7
  after_initialize do
8
+ self.data ||= {}
8
9
  self.session_key ||= SecureRandom.urlsafe_base64(60)
9
10
  end
10
11
 
@@ -2,15 +2,32 @@ require 'browser'
2
2
 
3
3
  module CoalescingPanda
4
4
  module ControllerHelpers
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ alias_method :rails_session, :session
9
+
10
+ helper_method :encrypted_session_key, :current_session_data, :current_session
11
+ append_after_action :save_session, if: -> { @current_session && session_changed? }
12
+ end
13
+
14
+ class_methods do
15
+ def use_native_sessions
16
+ after_action do
17
+ rails_session['persistent_session_key'] = current_session.session_key if @current_session.present?
18
+ end
19
+ end
20
+ end
21
+
5
22
  def current_session
6
- @current_session ||= CoalescingPanda::PersistentSession.find_by(session_key: session_key) if session_key
7
- @current_session ||= CoalescingPanda::PersistentSession.create_from_launch(params, current_lti_account.id)
23
+ @current_session ||= (CoalescingPanda::PersistentSession.find_by(session_key: session_key) if session_key)
24
+ @current_session ||= (CoalescingPanda::PersistentSession.create_from_launch(params, current_lti_account.id) if current_lti_account.present?)
8
25
  @current_session
9
26
  end
10
27
 
11
28
  def current_lti_account
12
- @account ||= CoalescingPanda::LtiAccount.find_by!(key: organization_key) if organization_key
13
- @account ||= CoalescingPanda::LtiAccount.find_by(id: organization_id) if organization_id
29
+ @account ||= (CoalescingPanda::LtiAccount.find_by!(key: organization_key) if organization_key)
30
+ @account ||= (CoalescingPanda::LtiAccount.find_by(id: organization_id) if organization_id)
14
31
  @account
15
32
  end
16
33
 
@@ -83,42 +100,42 @@ module CoalescingPanda
83
100
  end
84
101
 
85
102
  def check_refresh_token
86
- return unless session['uri'] && session['user_id'] && session['oauth_consumer_key']
87
- uri = BearcatUri.new(session['uri'])
88
- api_auth = CanvasApiAuth.find_by(user_id: session['user_id'], api_domain: uri.api_domain)
89
- @lti_account = LtiAccount.find_by(key: session['oauth_consumer_key'])
103
+ return unless current_session_data['uri'] && current_session_data['user_id'] && current_session_data['oauth_consumer_key']
104
+ uri = BearcatUri.new(current_session_data['uri'])
105
+ api_auth = CanvasApiAuth.find_by(user_id: current_session_data['user_id'], api_domain: uri.api_domain)
106
+ @lti_account = LtiAccount.find_by(key: current_session_data['oauth_consumer_key'])
90
107
  return if @lti_account.nil? || api_auth.nil? # Not all tools use oauth
91
108
 
92
109
  refresh_token(uri, api_auth) if api_auth.expired?
93
110
  rescue Footrest::HttpError::BadRequest
94
- render_oauth2_page uri, session['user_id']
111
+ render_oauth2_page uri, current_session_data['user_id']
95
112
  end
96
113
 
97
114
  def set_session(launch_presentation_return_url)
98
- session['user_id'] = params['user_id']
99
- session['uri'] = launch_presentation_return_url
100
- session['lis_person_sourcedid'] = params['lis_person_sourcedid']
101
- session['oauth_consumer_key'] = params['oauth_consumer_key']
102
- session['custom_canvas_account_id'] = params['custom_canvas_account_id']
115
+ current_session_data['user_id'] = params['user_id']
116
+ current_session_data['uri'] = launch_presentation_return_url
117
+ current_session_data['lis_person_sourcedid'] = params['lis_person_sourcedid']
118
+ current_session_data['oauth_consumer_key'] = params['oauth_consumer_key']
119
+ current_session_data['custom_canvas_account_id'] = params['custom_canvas_account_id']
103
120
  end
104
121
 
105
122
  def have_session?
106
- if params['tool_consumer_instance_guid'] && session['user_id'] != params['user_id']
123
+ if params['tool_consumer_instance_guid'] && current_session_data['user_id'] != params['user_id']
107
124
  reset_session
108
125
  logger.info("resetting session params")
109
- session['user_id'] = params['user_id']
126
+ current_session_data['user_id'] = params['user_id']
110
127
  end
111
128
 
112
- if (session['user_id'] && session['uri'])
113
- uri = BearcatUri.new(session['uri'])
114
- api_auth = CanvasApiAuth.find_by('user_id = ? and api_domain = ?', session['user_id'], uri.api_domain)
129
+ if (current_session_data['user_id'] && current_session_data['uri'])
130
+ uri = BearcatUri.new(current_session_data['uri'])
131
+ api_auth = CanvasApiAuth.find_by('user_id = ? and api_domain = ?', current_session_data['user_id'], uri.api_domain)
115
132
  if api_auth && !api_auth.expired?
116
133
  @client = Bearcat::Client.new(token: api_auth.api_token, prefix: uri.prefix)
117
134
  @client.user_profile 'self'
118
135
  end
119
136
  end
120
137
 
121
- @lti_account = LtiAccount.find_by_key(session['oauth_consumer_key']) if session['oauth_consumer_key']
138
+ @lti_account = LtiAccount.find_by_key(current_session_data['oauth_consumer_key']) if current_session_data['oauth_consumer_key']
122
139
 
123
140
  !!@client
124
141
  rescue Footrest::HttpError::Unauthorized
@@ -198,7 +215,7 @@ module CoalescingPanda
198
215
  if params[:encrypted_session_key]
199
216
  return msg_encryptor.decrypt_and_verify(params[:encrypted_session_key])
200
217
  end
201
- params[:session_key] || session_key_header
218
+ params[:session_key] || session_key_header || rails_session['persistent_session_key']
202
219
  end
203
220
 
204
221
  def session_key_header
@@ -218,26 +235,26 @@ module CoalescingPanda
218
235
  # nicely with webpack-dev-server live reloading (otherwise
219
236
  # you get an access error every time it tries to live reload).
220
237
 
221
- def redirect_with_session_to(path, id_or_resource = nil, params = {})
222
- if Rails.env.development?
223
- redirect_development_mode(path, id_or_resource, params)
238
+ def redirect_with_session_to(path, id_or_resource = nil, redirect_params = {})
239
+ if Rails.env.development? || Rails.env.test?
240
+ redirect_development_mode(path, id_or_resource, redirect_params)
224
241
  else
225
- redirect_production_mode(path, id_or_resource, params)
242
+ redirect_production_mode(path, id_or_resource, redirect_params)
226
243
  end
227
244
  end
228
245
 
229
- def redirect_development_mode(path, id_or_resource = nil, params)
246
+ def redirect_development_mode(path, id_or_resource = nil, redirect_params)
230
247
  redirect_to send(path, id_or_resource, {
231
248
  session_key: current_session.session_key,
232
249
  organization_id: current_lti_account.id
233
- }.merge(params))
250
+ }.merge(redirect_params))
234
251
  end
235
252
 
236
- def redirect_production_mode(path, id_or_resource = nil, params)
253
+ def redirect_production_mode(path, id_or_resource = nil, redirect_params)
237
254
  redirect_to send(path, id_or_resource, {
238
255
  encrypted_session_key: encrypted_session_key,
239
256
  organization_id: current_lti_account.id
240
- }.merge(params))
257
+ }.merge(redirect_params))
241
258
  end
242
259
 
243
260
  end
@@ -25,6 +25,10 @@ module CoalescingPanda
25
25
  end
26
26
  end
27
27
 
28
+ initializer 'coalescing_panda.assets' do |app|
29
+ app.config.assets.precompile << 'coalescing_panda/manifest.js'
30
+ end
31
+
28
32
  initializer 'cloaescing_panda.route_helper' do |route|
29
33
  ActionDispatch::Routing::Mapper.send :include, CoalescingPanda::RouteHelpers
30
34
  end
@@ -50,6 +54,9 @@ module CoalescingPanda
50
54
  # https://github.com/MiniProfiler/rack-mini-profiler/issues/327
51
55
  # DON'T ENABLE THIS FOR PRODUCTION!
52
56
  script_src << "'unsafe-eval'"
57
+ elsif CoalescingPanda.lti_options.has_key?(:allow_unsafe_eval) && CoalescingPanda.lti_options[:allow_unsafe_eval] == true
58
+ # For when code is returned from server and injected into dom. Need to have unsafe-eval or it won't work.
59
+ script_src << "'unsafe-eval'"
53
60
  end
54
61
 
55
62
  SecureHeaders::Configuration.default do |config|
@@ -80,6 +87,10 @@ module CoalescingPanda
80
87
  SecureHeaders::Configuration.override(:safari_override) do |config|
81
88
  config.cookies = SecureHeaders::OPT_OUT
82
89
  end
90
+
91
+ SecureHeaders::Configuration.override(:allow_inline_scripts) do |config|
92
+ config.csp[:script_src] << "'unsafe-inline'"
93
+ end
83
94
  end
84
95
 
85
96
  end
@@ -1,3 +1,3 @@
1
1
  module CoalescingPanda
2
- VERSION = '5.0.0.beta.1'
2
+ VERSION = '5.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coalescing_panda
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0.beta.1
4
+ version: 5.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Mills
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-06-03 00:00:00.000000000 Z
13
+ date: 2020-07-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -400,6 +400,7 @@ extensions: []
400
400
  extra_rdoc_files: []
401
401
  files:
402
402
  - Rakefile
403
+ - app/assets/config/coalescing_panda/manifest.js
403
404
  - app/assets/images/bootstrap/glyphicons-halflings-white.png
404
405
  - app/assets/images/bootstrap/glyphicons-halflings.png
405
406
  - app/assets/javascripts/coalescing_panda/application.js
@@ -422,6 +423,7 @@ files:
422
423
  - app/models/coalescing_panda/group.rb
423
424
  - app/models/coalescing_panda/group_category.rb
424
425
  - app/models/coalescing_panda/group_membership.rb
426
+ - app/models/coalescing_panda/json_with_indifferent_access.rb
425
427
  - app/models/coalescing_panda/lti_account.rb
426
428
  - app/models/coalescing_panda/lti_nonce.rb
427
429
  - app/models/coalescing_panda/oauth_state.rb
@@ -563,9 +565,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
563
565
  version: '0'
564
566
  required_rubygems_version: !ruby/object:Gem::Requirement
565
567
  requirements:
566
- - - ">"
568
+ - - ">="
567
569
  - !ruby/object:Gem::Version
568
- version: 1.3.1
570
+ version: '0'
569
571
  requirements: []
570
572
  rubygems_version: 3.1.2
571
573
  signing_key: