qalam_lti_provider_engine 2.0.6 → 2.1.0

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: 3f8241935a752778f3aaf18a334c18e0ca34f38942f1f08bbdcc937f77c9913e
4
- data.tar.gz: 7a5ed02a9a13c728c8ffe34c1fd66e2c8b07b66da5541f3b55742886aa5e3879
3
+ metadata.gz: ffc7781e66b1cae37477f81e36d212e3e52a115aa49e908a8954dda144d05ede
4
+ data.tar.gz: ee3ad8f02faa0314cea6192a5d264935d5b0ecb8d10b9622125acc4c635fd608
5
5
  SHA512:
6
- metadata.gz: 738e91d04b9c70e04d10d575b2b8a497cf0fa064dd6cb0d39aadcc8226d6c13d1de35528edcb4b308a942466e0c0c37ac751f76c3f3e91f644a1b315d80c7972
7
- data.tar.gz: b0aa71ce229a8dcb0a631029fd2fd15899b4c2daa3dc32d2c52f6777acd79ab7507aa2efc1749a3abded690a1e1c8ab75ff711dcca086b2aa740f68e74a7b57c
6
+ metadata.gz: d180b3146931ff792403020def0d9b562dedd791fd3ec5f869199736d11501390675b9003c4701b1f0354ce2477808ce23c8e565749df339b79858efcd57b86c
7
+ data.tar.gz: d5cd47670bef6e30fb0f4764e7c4c509aa21083edc8afd44aaffce076f2caad9d90dd0b2c67d0b96bd2816b2702b75a9fab5f0e4fc3b8e42b8a1998fc3dd8bd3
@@ -4,9 +4,18 @@ require 'colorize'
4
4
  module LtiProvider
5
5
  class LtiController < LtiProvider::LtiApplicationController
6
6
  skip_before_action :require_lti_launch
7
+ skip_before_action :verify_authenticity_token, only: :launch, if: :digital_library?
7
8
 
8
9
  def launch
9
- provider = IMS::LTI::ToolProvider.new(params['oauth_consumer_key'], LtiProvider::Config.secret, params)
10
+ tool_key = params['oauth_consumer_key']
11
+ if canvas_url_domain && ToolLtiKey.table_exists?
12
+ tool_lti_key = ToolLtiKey.where(key: tool_key).where('lower(canvas_url) LIKE :q', q: "%#{canvas_url_domain.downcase}%" ).first
13
+ tool_secret = tool_lti_key&.secret or LtiProvider::Config.secret
14
+ else
15
+ tool_secret = LtiProvider::Config.secret
16
+ end
17
+
18
+ provider = IMS::LTI::ToolProvider.new(tool_key, tool_secret, params)
10
19
  launch = Launch.initialize_from_request(provider, request)
11
20
 
12
21
  if !launch.valid_provider?
@@ -14,7 +23,6 @@ module LtiProvider
14
23
  return show_error msg
15
24
  elsif launch.save
16
25
  session[:cookie_test] = true
17
-
18
26
  ### QALAM ###
19
27
  if params[:timetable_date] && params[:section_room]
20
28
  redirect_to cookie_test_path(nonce: launch.nonce, timetable_date: params[:timetable_date], section_room: params[:section_room])
@@ -23,26 +31,34 @@ module LtiProvider
23
31
  end
24
32
  ### END ###
25
33
  else
26
- return show_error "Unable to launch #{LtiProvider::XmlConfig.tool_title}. Please check your External Tools configuration and try again."
34
+ # if params[:qalam_url] && params[:launch_tool] == 'digital_library'
35
+ # redirect_to main_app.root_path and return
36
+ # else
37
+ return show_error "Unable to launch #{LtiProvider::XmlConfig.tool_title}. Please check your External Tools configuration and try again."
38
+ # end
27
39
  end
28
40
  end
29
41
 
30
42
  def cookie_test
43
+ @launch = Launch.where("created_at > ?", 5.minutes.ago).find_by_nonce(params[:nonce])
44
+
31
45
  if session[:cookie_test]
32
46
  # success!!! we've got a session!
33
47
  consume_launch
34
48
  else
35
- render
49
+ # if @launch.launch_tool && @launch.launch_tool == 'digital_library'
50
+ # redirect_to main_app.root_path and return
51
+ # else
52
+ render and return
53
+ # end
36
54
  end
37
55
  end
38
56
 
39
57
  def consume_launch
40
- launch = Launch.where("created_at > ?", 5.minutes.ago).find_by_nonce(params[:nonce])
41
-
42
- if launch
58
+ if @launch
43
59
  [:account_id, :course_name, :course_id, :canvas_url, :tool_consumer_instance_guid,
44
60
  :user_id, :user_name, :user_roles, :user_avatar_url, :launch_tool].each do |attribute|
45
- session[attribute] = launch.public_send(attribute)
61
+ session[attribute] = @launch.public_send(attribute)
46
62
  end
47
63
 
48
64
  ### QALAM ###
@@ -52,11 +68,19 @@ module LtiProvider
52
68
  end
53
69
  ### END ###
54
70
 
55
- launch.destroy
71
+ @launch.destroy
56
72
 
57
- redirect_to main_app.root_path
73
+ # if @launch.launch_tool && @launch.launch_tool == 'digital_library'
74
+ # redirect_to main_app.root_path and return
75
+ # else
76
+ redirect_to main_app.root_path and return
77
+ # end
58
78
  else
59
- return show_error "The tool was not launched successfully. Please try again."
79
+ # if @launch.launch_tool && @launch.launch_tool == 'digital_library'
80
+ # redirect_to main_app.root_path and return
81
+ # else
82
+ return show_error "The tool was not launched successfully. Please try again."
83
+ # end
60
84
  end
61
85
  end
62
86
 
@@ -72,5 +96,19 @@ module LtiProvider
72
96
  def show_error(message)
73
97
  render plain: message
74
98
  end
99
+
100
+ private
101
+ def canvas_url_domain
102
+ if params['launch_presentation_return_url']
103
+ uri = URI.parse(params['launch_presentation_return_url'])
104
+ domain = "#{uri.scheme}://#{uri.host}"
105
+ domain += ":#{uri.port}" unless uri.port.nil? || [80, 443].include?(uri.port.to_i)
106
+ return domain
107
+ end
108
+ end
109
+
110
+ def digital_library?
111
+ session[:qalam_url] ? true : false
112
+ end
75
113
  end
76
114
  end
@@ -0,0 +1,4 @@
1
+ class ToolLtiKey < ApplicationRecord
2
+ validates :canvas_url, :secret, presence: true
3
+ validates :key, presence: true, :uniqueness => {:scope=>:canvas_url}
4
+ end
@@ -1,12 +1,14 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
- <head>
4
- <title>LtiProvider</title>
5
- <%= csrf_meta_tags %>
6
- </head>
7
- <body>
8
-
9
- <%= yield %>
10
-
11
- </body>
12
- </html>
3
+ <head>
4
+ <title>QalamLtiProvider</title>
5
+ <%= csrf_meta_tags %>
6
+ <meta name="description" content="About QalamLtiProvider">
7
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
8
+ <%= csrf_meta_tags %>
9
+ <%= csp_meta_tag %>
10
+ </head>
11
+ <body>
12
+ <%= yield %>
13
+ </body>
14
+ </html>
@@ -0,0 +1,11 @@
1
+ class CreateToolLtiKeys < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :tool_lti_keys do |t|
4
+ t.string :key
5
+ t.string :secret
6
+ t.string :canvas_url
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -12,8 +12,13 @@ module LtiProvider
12
12
  protected
13
13
  def require_lti_launch
14
14
  if canvas_url.blank? || user_id.blank?
15
- reset_session
16
- prompt_for_launch
15
+ if session[:qalam_url]
16
+ reset_session
17
+ prompt_for_launch_authorized
18
+ else
19
+ reset_session
20
+ prompt_for_launch
21
+ end
17
22
  end
18
23
  end
19
24
 
@@ -21,6 +26,10 @@ module LtiProvider
21
26
  render plain: 'Please launch this tool from Qalam and then try again.'
22
27
  end
23
28
 
29
+ def prompt_for_launch_authorized
30
+ render plain: 'You need to be login on Qalam.'
31
+ end
32
+
24
33
  def canvas_url
25
34
  session[:canvas_url]
26
35
  end
@@ -59,19 +68,19 @@ module LtiProvider
59
68
  end
60
69
 
61
70
  def student_launch?
62
- user_roles.split(',').include? 'urn:lti:role:ims/lis/Learner'
71
+ user_roles&.split(',')&.include? 'urn:lti:role:ims/lis/Learner'
63
72
  end
64
73
 
65
74
  def teacher_launch?
66
- user_roles.split(',').include? 'urn:lti:role:ims/lis/Instructor'
75
+ user_roles&.split(',')&.include? 'urn:lti:role:ims/lis/Instructor'
67
76
  end
68
77
 
69
78
  def account_admin_launch?
70
- user_roles.split(',').include? 'urn:lti:instrole:ims/lis/Administrator'
79
+ user_roles&.split(',')&.include? 'urn:lti:instrole:ims/lis/Administrator'
71
80
  end
72
81
 
73
82
  def root_admin_launch?
74
- user_roles.split(',').include? 'urn:lti:sysrole:ims/lis/SysAdmin'
83
+ user_roles&.split(',')&.include? 'urn:lti:sysrole:ims/lis/SysAdmin'
75
84
  end
76
85
  ### END ###
77
86
 
@@ -79,4 +88,4 @@ module LtiProvider
79
88
  render plain: "Unable to process request", status: 406
80
89
  end
81
90
  end
82
- end
91
+ end
@@ -1,4 +1,5 @@
1
1
  require 'yaml'
2
+ require 'colorize'
2
3
 
3
4
  module LtiProvider
4
5
  module LtiConfig
@@ -13,12 +14,12 @@ module LtiProvider
13
14
  def self.setup!
14
15
  config = LtiProvider::Config
15
16
  if File.exists?(config_file)
16
- Rails.logger.info "Initializing LTI key and secret using configuration in #{config_file}"
17
+ Rails.logger.info "Initializing LTI key and secret using configuration in #{config_file}".green
17
18
  load_config.each do |k,v|
18
19
  config.send("#{k}=", v)
19
20
  end
20
21
  elsif ENV['LTI_KEY'].present? && ENV['LTI_SECRET'].present?
21
- Rails.logger.info "Initializing LTI key and secret using environment vars LTI_KEY and LTI_SECRET"
22
+ Rails.logger.info "Initializing LTI key and secret using environment vars LTI_KEY and LTI_SECRET".green
22
23
  config.key = ENV['LTI_KEY']
23
24
  config.secret = ENV['LTI_SECRET']
24
25
  config.require_canvas = !!ENV['LTI_REQUIRE_CANVAS']
@@ -1,3 +1,6 @@
1
+ require 'yaml'
2
+ require 'colorize'
3
+
1
4
  module LtiProvider
2
5
  module LtiXmlConfig
3
6
  def self.load_config
@@ -11,7 +14,7 @@ module LtiProvider
11
14
  def self.setup!
12
15
  config = LtiProvider::XmlConfig
13
16
  if File.exists?(config_file)
14
- Rails.logger.info "Initializing LTI XML config using configuration in #{config_file}"
17
+ Rails.logger.info "Initializing LTI XML config using configuration in #{config_file}".green
15
18
  load_config.each do |k,v|
16
19
  config.send("#{k}=", v)
17
20
  end
@@ -1,3 +1,3 @@
1
1
  module LtiProvider
2
- VERSION = "2.0.6"
2
+ VERSION = "2.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qalam_lti_provider_engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.6
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Donahue
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2021-08-01 00:00:00.000000000 Z
14
+ date: 2021-08-30 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -47,6 +47,20 @@ dependencies:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0'
50
+ - !ruby/object:Gem::Dependency
51
+ name: colorize
52
+ requirement: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
50
64
  - !ruby/object:Gem::Dependency
51
65
  name: sqlite3
52
66
  requirement: !ruby/object:Gem::Requirement
@@ -245,12 +259,14 @@ files:
245
259
  - app/controllers/lti_provider/lti_application_controller.rb
246
260
  - app/controllers/lti_provider/lti_controller.rb
247
261
  - app/models/lti_provider/launch.rb
262
+ - app/models/tool_lti_key.rb
248
263
  - app/views/layouts/lti_provider/application.html.erb
249
264
  - app/views/lti_provider/lti/cookie_test.html.erb
250
265
  - config/lti.yml.example
251
266
  - config/lti_xml.yml.example
252
267
  - config/routes.rb
253
268
  - db/migrate/20130319050003_create_lti_provider_launches.rb
269
+ - db/migrate/20210809101126_create_tool_lti_keys.rb
254
270
  - lib/lti_provider.rb
255
271
  - lib/lti_provider/config.rb
256
272
  - lib/lti_provider/engine.rb
@@ -312,7 +328,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
312
328
  - !ruby/object:Gem::Version
313
329
  version: '0'
314
330
  requirements: []
315
- rubygems_version: 3.2.21
331
+ rubygems_version: 3.2.22
316
332
  signing_key:
317
333
  specification_version: 4
318
334
  summary: LtiProvider is a mountable engine for handling the LTI launch and exposing