lti2 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/lib/lti2/version.rb +1 -1
  3. data/lti2_tc/Gemfile +14 -0
  4. data/lti2_tc/Gemfile.lock +94 -0
  5. data/lti2_tc/MIT-LICENSE +20 -0
  6. data/lti2_tc/README.rdoc +3 -0
  7. data/lti2_tc/Rakefile +34 -0
  8. data/lti2_tc/app/assets/javascripts/lti2_tc/application.js +13 -0
  9. data/lti2_tc/app/assets/stylesheets/lti2_tc/application.css +13 -0
  10. data/lti2_tc/app/controllers/lti2_tc/application_controller.rb +13 -0
  11. data/lti2_tc/app/controllers/lti2_tc/deployment_requests_controller.rb +9 -0
  12. data/lti2_tc/app/controllers/lti2_tc/tool_consumer_profiles_controller.rb +23 -0
  13. data/lti2_tc/app/controllers/lti2_tc/tool_proxies_controller.rb +8 -0
  14. data/lti2_tc/app/controllers/lti2_tc/tool_settings_controller.rb +215 -0
  15. data/lti2_tc/app/controllers/lti2_tc/tools_controller.rb +361 -0
  16. data/lti2_tc/app/models/lti2_tc/deployment_request.rb +43 -0
  17. data/lti2_tc/app/models/lti2_tc/link.rb +24 -0
  18. data/lti2_tc/app/models/lti2_tc/registry.rb +4 -0
  19. data/lti2_tc/app/models/lti2_tc/resource.rb +6 -0
  20. data/lti2_tc/app/models/lti2_tc/tool.rb +12 -0
  21. data/lti2_tc/app/models/lti2_tc/tool_consumer_profile.rb +4 -0
  22. data/lti2_tc/app/models/lti2_tc/tool_consumer_registry.rb +24 -0
  23. data/lti2_tc/app/models/lti2_tc/tool_registration.rb +83 -0
  24. data/lti2_tc/app/models/lti2_tc/tool_setting.rb +61 -0
  25. data/lti2_tc/app/services/lti2_tc/authorizer.rb +36 -0
  26. data/lti2_tc/app/services/lti2_tc/lti2_launch.rb +259 -0
  27. data/lti2_tc/app/views/layouts/lti2_tc/application.html.erb +14 -0
  28. data/lti2_tc/app/views/lti2_tc/deployment_requests/show.html.erb +2 -0
  29. data/lti2_tc/app/views/lti2_tc/tool_consumer_profiles/index.html.erb +2 -0
  30. data/lti2_tc/app/views/lti2_tc/tool_consumer_profiles/show.html.erb +2 -0
  31. data/lti2_tc/app/views/lti2_tc/tool_proxies_controller/index.html.erb +2 -0
  32. data/lti2_tc/app/views/lti2_tc/tool_settings_controller/show.html.erb +2 -0
  33. data/lti2_tc/app/views/lti2_tc/tool_settings_controller/update.html.erb +2 -0
  34. data/lti2_tc/app/views/lti2_tc/tools_controller/create.html.erb +2 -0
  35. data/lti2_tc/app/views/lti2_tc/tools_controller/show.html.erb +2 -0
  36. data/lti2_tc/bin/rails +8 -0
  37. data/lti2_tc/config/routes.rb +20 -0
  38. data/lti2_tc/db/migrate/20140826141858_create_lti2_tool_consumer_tables.rb +94 -0
  39. data/lti2_tc/db/migrate/20140826150753_create_lti2_tc_resources.rb +37 -0
  40. data/lti2_tc/db/migrate/20141027193548_insert_tool_guid.rb +5 -0
  41. data/lti2_tc/lib/lti2_tc.rb +4 -0
  42. data/lti2_tc/lib/lti2_tc/engine.rb +5 -0
  43. data/lti2_tc/lib/lti2_tc/version.rb +3 -0
  44. data/lti2_tc/lib/tasks/lti2_tc_tasks.rake +4 -0
  45. data/lti2_tc/lti2_tc.gemspec +27 -0
  46. data/lti2_tc/test/controllers/lti2_tc/deployment_requests_controller_test.rb +11 -0
  47. data/lti2_tc/test/controllers/lti2_tc/tool_consumer_profiles_controller_test.rb +16 -0
  48. data/lti2_tc/test/controllers/lti2_tc/tool_proxies_controller_controller_test.rb +11 -0
  49. data/lti2_tc/test/controllers/lti2_tc/tool_settings_controller_controller_test.rb +16 -0
  50. data/lti2_tc/test/controllers/lti2_tc/tools_controller_controller_test.rb +16 -0
  51. data/lti2_tc/test/dummy/README.rdoc +28 -0
  52. data/lti2_tc/test/dummy/Rakefile +6 -0
  53. data/lti2_tc/test/dummy/app/assets/javascripts/application.js +13 -0
  54. data/lti2_tc/test/dummy/app/assets/stylesheets/application.css +13 -0
  55. data/lti2_tc/test/dummy/app/controllers/application_controller.rb +5 -0
  56. data/lti2_tc/test/dummy/app/helpers/application_helper.rb +2 -0
  57. data/lti2_tc/test/dummy/app/views/layouts/application.html.erb +14 -0
  58. data/lti2_tc/test/dummy/bin/bundle +3 -0
  59. data/lti2_tc/test/dummy/bin/rails +4 -0
  60. data/lti2_tc/test/dummy/bin/rake +4 -0
  61. data/lti2_tc/test/dummy/config.ru +4 -0
  62. data/lti2_tc/test/dummy/config/application.rb +23 -0
  63. data/lti2_tc/test/dummy/config/boot.rb +5 -0
  64. data/lti2_tc/test/dummy/config/database.yml +39 -0
  65. data/lti2_tc/test/dummy/config/environment.rb +5 -0
  66. data/lti2_tc/test/dummy/config/environments/development.rb +29 -0
  67. data/lti2_tc/test/dummy/config/environments/production.rb +80 -0
  68. data/lti2_tc/test/dummy/config/environments/test.rb +36 -0
  69. data/lti2_tc/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  70. data/lti2_tc/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  71. data/lti2_tc/test/dummy/config/initializers/inflections.rb +16 -0
  72. data/lti2_tc/test/dummy/config/initializers/mime_types.rb +5 -0
  73. data/lti2_tc/test/dummy/config/initializers/secret_token.rb +12 -0
  74. data/lti2_tc/test/dummy/config/initializers/session_store.rb +3 -0
  75. data/lti2_tc/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  76. data/lti2_tc/test/dummy/config/locales/en.yml +23 -0
  77. data/lti2_tc/test/dummy/config/routes.rb +4 -0
  78. data/lti2_tc/test/dummy/db/database.yml +39 -0
  79. data/lti2_tc/test/dummy/db/migrate/20131121225051_create_lti2_tc_registries.lti2_tc.rb +55 -0
  80. data/lti2_tc/test/dummy/db/schema.rb +68 -0
  81. data/lti2_tc/test/dummy/public/404.html +58 -0
  82. data/lti2_tc/test/dummy/public/422.html +58 -0
  83. data/lti2_tc/test/dummy/public/500.html +57 -0
  84. data/lti2_tc/test/dummy/public/favicon.ico +0 -0
  85. data/lti2_tc/test/fixtures/lti2_tc/registries.yml +7 -0
  86. data/lti2_tc/test/helpers/lti2_tc/deployment_requests_helper_test.rb +6 -0
  87. data/lti2_tc/test/helpers/lti2_tc/tool_consumer_profiles_helper_test.rb +6 -0
  88. data/lti2_tc/test/helpers/lti2_tc/tool_proxies_controller_helper_test.rb +6 -0
  89. data/lti2_tc/test/helpers/lti2_tc/tool_settings_controller_helper_test.rb +6 -0
  90. data/lti2_tc/test/helpers/lti2_tc/tools_controller_helper_test.rb +6 -0
  91. data/lti2_tc/test/integration/navigation_test.rb +10 -0
  92. data/lti2_tc/test/lti2_tc_test.rb +7 -0
  93. data/lti2_tc/test/models/lti2_tc/registries_test.rb +9 -0
  94. data/lti2_tc/test/test_helper.rb +15 -0
  95. metadata +93 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7fb808b35c9fa1aa859277f7fbf6e7789a126cc
4
- data.tar.gz: 58137b32270008ffd738b49b609b27997afd5c5b
3
+ metadata.gz: b2b8f62bd07c6bbec6c19d4f056168731dabad1b
4
+ data.tar.gz: a32c3c21c909f1df452c6b004dd954a285e797b4
5
5
  SHA512:
6
- metadata.gz: c8ebbfa0b82662ebd64d16228ffcc11b68d697f595f4758cbf7841073df1971046b9696761c442300da34192420fbf95bd975fdff857d050fa55f1c654783d3c
7
- data.tar.gz: d78b7a644c7b29e1a4298e6199b3a8edda475cf5d263e40b4483ab592384056c6acdc97cc90e96561d89b1893e1dce4c42af891ce41a92dbaabb2fda0a1a7fa6
6
+ metadata.gz: 41847909bd2bd35c4311dde85c80fe9f884b8177c9282356d0a4fc88f6f52ac6384d8b1673253772854a7de832256040a5d7b720918d40aceb5ac3537267320e
7
+ data.tar.gz: ff6cb38ecd446ac1ce84c95507181bcc0c57a4ac269596a9134ec7db6dc076711fd99f600a729d537597ebc3d2f2468024365f2da265fc3330b226aa5bf2ab12
@@ -1,3 +1,3 @@
1
1
  module Lti2
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Declare your gem's dependencies in lti2_tc.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
7
+
8
+ # Declare any dependencies that are still in development here instead of in
9
+ # your gemspec. These might include edge Rails or gems from your path or
10
+ # Git. Remember to move these dependencies to your gemspec before releasing
11
+ # your gem to rubygems.org.
12
+
13
+ # To use debugger
14
+ # gem 'debugger'
@@ -0,0 +1,94 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lti2_tc (0.0.2)
5
+ mysql2 (~> 0.3.13)
6
+ rails (~> 4.1.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actionmailer (4.1.5)
12
+ actionpack (= 4.1.5)
13
+ actionview (= 4.1.5)
14
+ mail (~> 2.5.4)
15
+ actionpack (4.1.5)
16
+ actionview (= 4.1.5)
17
+ activesupport (= 4.1.5)
18
+ rack (~> 1.5.2)
19
+ rack-test (~> 0.6.2)
20
+ actionview (4.1.5)
21
+ activesupport (= 4.1.5)
22
+ builder (~> 3.1)
23
+ erubis (~> 2.7.0)
24
+ activemodel (4.1.5)
25
+ activesupport (= 4.1.5)
26
+ builder (~> 3.1)
27
+ activerecord (4.1.5)
28
+ activemodel (= 4.1.5)
29
+ activesupport (= 4.1.5)
30
+ arel (~> 5.0.0)
31
+ activesupport (4.1.5)
32
+ i18n (~> 0.6, >= 0.6.9)
33
+ json (~> 1.7, >= 1.7.7)
34
+ minitest (~> 5.1)
35
+ thread_safe (~> 0.1)
36
+ tzinfo (~> 1.1)
37
+ arel (5.0.1.20140414130214)
38
+ builder (3.2.2)
39
+ erubis (2.7.0)
40
+ hike (1.2.3)
41
+ i18n (0.6.11)
42
+ json (1.8.1)
43
+ mail (2.5.4)
44
+ mime-types (~> 1.16)
45
+ treetop (~> 1.4.8)
46
+ mime-types (1.25.1)
47
+ minitest (5.4.1)
48
+ multi_json (1.10.1)
49
+ mysql2 (0.3.16)
50
+ polyglot (0.3.5)
51
+ rack (1.5.2)
52
+ rack-test (0.6.2)
53
+ rack (>= 1.0)
54
+ rails (4.1.5)
55
+ actionmailer (= 4.1.5)
56
+ actionpack (= 4.1.5)
57
+ actionview (= 4.1.5)
58
+ activemodel (= 4.1.5)
59
+ activerecord (= 4.1.5)
60
+ activesupport (= 4.1.5)
61
+ bundler (>= 1.3.0, < 2.0)
62
+ railties (= 4.1.5)
63
+ sprockets-rails (~> 2.0)
64
+ railties (4.1.5)
65
+ actionpack (= 4.1.5)
66
+ activesupport (= 4.1.5)
67
+ rake (>= 0.8.7)
68
+ thor (>= 0.18.1, < 2.0)
69
+ rake (10.3.2)
70
+ sprockets (2.12.2)
71
+ hike (~> 1.2)
72
+ multi_json (~> 1.0)
73
+ rack (~> 1.0)
74
+ tilt (~> 1.1, != 1.3.0)
75
+ sprockets-rails (2.1.4)
76
+ actionpack (>= 3.0)
77
+ activesupport (>= 3.0)
78
+ sprockets (~> 2.8)
79
+ sqlite3 (1.3.8)
80
+ thor (0.19.1)
81
+ thread_safe (0.3.4)
82
+ tilt (1.4.1)
83
+ treetop (1.4.15)
84
+ polyglot
85
+ polyglot (>= 0.3.1)
86
+ tzinfo (1.2.2)
87
+ thread_safe (~> 0.1)
88
+
89
+ PLATFORMS
90
+ ruby
91
+
92
+ DEPENDENCIES
93
+ lti2_tc!
94
+ sqlite3
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ = Lti2Tc
2
+
3
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Lti2Tc'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,13 @@
1
+ module Lti2Tc
2
+
3
+ class ApplicationController < ActionController::Base
4
+ include OAuth::OAuthProxy
5
+ def pre_process_tenant
6
+ Lti2Tc::Authorizer::pre_process_tenant( request )
7
+ end
8
+
9
+ def oauth_validation_using_secret( secret )
10
+ Lti2Tc::Authorizer::validate( request, secret )
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ require_dependency 'lti2_tc/application_controller'
2
+
3
+ module Lti2Tc
4
+ class DeploymentRequestsController < ApplicationController
5
+ def show
6
+ render :json => Rails.application.config.tool_consumer_registry.tool_consumer_profile
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ require_dependency 'lti2_tc/application_controller'
2
+
3
+ module Lti2Tc
4
+ class ToolConsumerProfilesController < ApplicationController
5
+ def index
6
+ show
7
+ end
8
+
9
+ def show
10
+ tcp_objects = Lti2Tc::ToolConsumerProfile.where( :tc_profile_guid => params[:id] )
11
+ tcp_object = tcp_objects.first
12
+ if tcp_object.present?
13
+ registry = Rails.application.config.tool_consumer_registry
14
+ tcp = registry.tool_consumer_profile_wrapper
15
+ tcp.substitute_text_in_all_nodes( '{', '}', { 'tc_profile_guid' => tcp_object.tc_profile_guid } )
16
+ logger.info( JSON.pretty_generate tcp.root )
17
+ render :json => tcp.root, :content_type => 'application/vnd.ims.lti.v2.toolconsumerprofile+json'
18
+ else
19
+ render :inline => '<h2>ToolConsumerProfile not found</h2>', :status => 404
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,8 @@
1
+ require_dependency 'lti2_tc/application_controller'
2
+
3
+ module Lti2Tc
4
+ class ToolProxiesController < ApplicationController
5
+ def index
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,215 @@
1
+ require_dependency 'lti2_tc/application_controller'
2
+
3
+ module Lti2Tc
4
+ class ToolSettingsController < ApplicationController
5
+ skip_before_filter :verify_authenticity_token
6
+
7
+ def initialize
8
+ @acceptable_headers = [ 'application/vnd.ims.lti.v2.toolsettings+json',
9
+ 'application/vnd.ims.lti.v2.toolsettings.simple+json' ]
10
+ @tool_setting_binding_map = { :Tool => :ToolProxy, :Context => :ToolProxyBinding, :Ltilink => :LtiLink }
11
+ end
12
+
13
+ def self.add_ancestor_settings( target_matches )
14
+ return if target_matches.blank?
15
+ tool_id = target_matches.first.tool_id
16
+ node_id = target_matches.first.scopeable_id
17
+ now_collection_type = target_matches.first.scopeable_type
18
+ if now_collection_type == 'Ltilink'
19
+ # we have link in hand, now find courses for link
20
+ course_id = Lti2Tc::Link.find( node_id ).course.id
21
+ target_matches << Lti2Tc::ToolSetting.where(
22
+ :tool_id => tool_id, :scopeable_type => 'Context', :scopeable_id => course_id
23
+ )
24
+ now_node_id = course_id
25
+ now_collection_type = 'Context'
26
+ end
27
+ if now_collection_type == 'Context'
28
+ # we have course settings, now find tool settings for that course
29
+ target_matches << Lti2Tc::ToolSetting.where( :tool_id => tool_id, :scopeable_type => 'Tool' )
30
+ now_collection_type == 'Context'
31
+ end
32
+ target_matches.flatten
33
+ end
34
+
35
+ def self.get_collection_type( path )
36
+ Lti2Tc::ToolSetting.parse_uri( path )[0]
37
+ end
38
+
39
+ def self.get_distinct_matches( matches )
40
+ dupe_check_set = Set.new
41
+ all_matches = []
42
+ matches.each do |match|
43
+ unless dupe_check_set.include?( match.name )
44
+ all_matches << match
45
+ dupe_check_set.add( match.name )
46
+ end
47
+ end
48
+ all_matches
49
+ end
50
+
51
+ def self.get_trimmed_request_uri( uri )
52
+ uri.split('?').first
53
+ end
54
+
55
+ def self.get_target_matches( collection_type, tool_guid, node_id )
56
+ tool = Lti2Tc::Tool.where( :key => tool_guid ).first
57
+ case collection_type
58
+ when 'Tool'
59
+ Lti2Tc::ToolSetting.where( :tool_id => tool.id, :scopeable_type => 'Tool' )
60
+ when 'Context'
61
+ Lti2Tc::ToolSetting.where( :tool_id => tool.id, :scopeable_type => 'Context', :scopeable_id => node_id )
62
+ when 'Ltilink'
63
+ Lti2Tc::ToolSetting.where( :tool_id => tool.id, :scopeable_type => 'Ltilink', :scopeable_id => node_id )
64
+ else
65
+ nil
66
+ end
67
+ end
68
+
69
+ def is_header_full_not_simple( header )
70
+ @acceptable_headers.index( header ) == 0
71
+ end
72
+
73
+ def is_unacceptable( header )
74
+ ! @acceptable_headers.include?( header )
75
+ end
76
+
77
+ def pre_process
78
+ Lti2Tc::Authorizer::pre_process_tenant(request)
79
+ end
80
+
81
+ def show
82
+ oauth_error = pre_process
83
+ (render :text => "Authentication error", :status => 401 if oauth_error) and return
84
+
85
+ tool_guid = params[:tool_guid]
86
+ collection_type = ToolSettingsController.get_collection_type( request.path )
87
+ node_id = collection_type == 'tool' ? nil : params[:node_id]
88
+ bubble = params[:bubble]
89
+
90
+ accept = request.headers['ACCEPT']
91
+
92
+ ( render :json => {}, :status => 406 if is_unacceptable( accept ) ) and return
93
+
94
+ puts "collection_type: #{collection_type}"
95
+ puts "accept: #{accept}"
96
+
97
+ all_match_names = Set.new
98
+ result = {}
99
+ if is_header_full_not_simple( accept )
100
+ content_type = 'application/vnd.ims.lti.v2.toolsettings+json'
101
+ target_matches = ToolSettingsController.get_target_matches( collection_type, tool_guid, node_id )
102
+
103
+ if bubble.present?
104
+ reverse_collections = Lti2Tc::ToolSetting::COLLECTION_TYPES.reverse
105
+ collection_index = reverse_collections.find_index( collection_type.to_sym )
106
+ all_collection_types = reverse_collections[collection_index..-1]
107
+ target_matches = ToolSettingsController.add_ancestor_settings( target_matches )
108
+ reachable_uris = Lti2Tc::ToolSetting.create_reachable_uris( tool_guid, collection_type, node_id )
109
+ else
110
+ all_collection_types = [collection_type]
111
+ reachable_uris = {}
112
+ reachable_uris[collection_type.to_sym] = Lti2Tc::ToolSetting.create_uri( tool_guid, collection_type, node_id )
113
+ end
114
+
115
+ result[:@context] = 'http://purl.imsglobal.org/ctx/lti/v2/ToolSettings'
116
+ result[:@graph] = []
117
+
118
+ all_collection_types.each do |collect_type|
119
+ @match_dict = nil
120
+ graph_element = {}
121
+ result[:@graph] << graph_element
122
+ collection_matches = target_matches.select { |match| match.scopeable_type == collect_type.to_s }
123
+ #if collection_matches.length > 0
124
+ graph_element['@type'] = @tool_setting_binding_map[collect_type.to_sym]
125
+ a_match = collection_matches[0]
126
+ uri = reachable_uris[collect_type.to_sym]
127
+ graph_element['@id'] = uri
128
+ @match_dict = {}
129
+ graph_element['custom'] = @match_dict
130
+
131
+ target_matches = ToolSettingsController.get_distinct_matches( target_matches ) if bubble == 'distinct'
132
+
133
+ target_matches.each do |match|
134
+ if match.scopeable_type.to_sym == collect_type.to_sym
135
+ unless all_match_names.include? match.name
136
+ @match_dict[match.name] = match.value
137
+ all_match_names << match.name if bubble == 'distinct'
138
+ end
139
+ end
140
+ end
141
+ #end
142
+ end
143
+ else
144
+ content_type = 'application/vnd.ims.lti.v2.toolsettings.simple+json'
145
+ target_matches = ToolSettingsController.get_target_matches( collection_type, tool_guid, node_id )
146
+
147
+ if bubble.present?
148
+ if bubble == 'all' && accept == 'application/vnd.ims.lti.v2.toolsettings.simple+json'
149
+ (render :text => 'bubble=all option cannot be used for toolsettings.simple media type', :status => 400) and return
150
+ end
151
+ target_matches = ToolSettingsController.add_ancestor_settings( target_matches )
152
+ end
153
+
154
+ # simple only allows 'distinct' output
155
+ target_matches.flatten
156
+ target_matches = ToolSettingsController.get_distinct_matches( target_matches )
157
+ target_matches.each { |match| result[match['name']] = match['value'] }
158
+ end
159
+
160
+ puts JSON.pretty_generate( result )
161
+
162
+ render :json => result, :content_type => content_type
163
+ end
164
+
165
+ def update
166
+ oauth_error = pre_process
167
+ (render :text => "Authentication error", :status => 401 if oauth_error) and return
168
+
169
+ tool_guid = params[:tool_guid]
170
+ collection_type = ToolSettingsController.get_collection_type(request.path)
171
+ node_id = collection_type == 'Tool' ? nil : params[:node_id]
172
+
173
+ content_type = request.headers['CONTENT_TYPE']
174
+ (render :text => "Unacceptable Content_Type header for ToolSettings", :status => 406 if is_unacceptable(content_type)) and return
175
+
176
+ body_str = request.body.read
177
+ json_str = CGI::unescape body_str
178
+
179
+ if is_header_full_not_simple( content_type )
180
+ settings_object = JSON.load( json_str )
181
+ (render :json => "Multiple level tool setting updates not allowed", :status => 400 if settings_object['@graph'].length > 1) and return
182
+ settings = settings_object['@graph'][0]['custom']
183
+ else
184
+ settings = JSON.load( json_str )
185
+ end
186
+
187
+ scopeable_type, tool_guid, scopeable_id = ToolSetting.parse_uri( request.path )
188
+ tool = Tool.where( :key => tool_guid ).first
189
+
190
+ # for Tool only
191
+ scopeable_id = tool.id if scopeable_type == 'Tool'
192
+
193
+ # first clear out the old data
194
+ if scopeable_type == 'Tool'
195
+ ToolSetting.where( :scopeable_type => scopeable_type, :tool_id => tool.id ).delete_all
196
+ else
197
+ ToolSetting.where( :scopeable_type => scopeable_type, :tool_id => tool.id, :scopeable_id => scopeable_id ).delete_all
198
+ end
199
+
200
+ settings.each_pair do |k,v|
201
+ ts = ToolSetting.create(
202
+ :scopeable_type => scopeable_type,
203
+ :tool_id => tool.id,
204
+ :scopeable_id => scopeable_id,
205
+ :name => k,
206
+ :value => v
207
+ )
208
+ ts.save
209
+ end
210
+
211
+ render :json => "Successfully updated #{settings.length} values"
212
+ end
213
+ end
214
+
215
+ end