panda_pal 5.4.5 → 5.4.6

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: 6de9e366030521aaa18328dbb06bfdb1ebb40a27493fab4c0168f85195f3838e
4
- data.tar.gz: a08d0f4c61695f4898ec46d004e06e9115aee2759bef97499bd17501d18f14c2
3
+ metadata.gz: 47e93c2f05e4078784f066642ed837e56c60cab9d342a2b9cd0d5e72192a248c
4
+ data.tar.gz: 4bd5d5e668b0a6a4cd069234170d460bfc44bdd80bc2b0b872b1f00cdbe77339
5
5
  SHA512:
6
- metadata.gz: bd659d9a64acbb986f7481faf8962dff90cdfc1c9c2654462fff6f293e9757c3d87edc55337cc56cf1ab6ab0208f0b8be186d6ba3f81e01aaaa0705cbd6137e1
7
- data.tar.gz: 0fc0ddb7daf4ec3636deedb6e47fa866b0511ca66d338d19c19817020f7ee8ab871c08b40ef37172678c52f14a0697f8fe41ef1374b6a1c9242b9f795dbeec55
6
+ metadata.gz: 67905790789c0a503b453c09abd1255d7b4720a313cc60be816db7cf58806e878b52933eb749f346b78291780d17632bb6cabed66581426614a3e4b5f999b653
7
+ data.tar.gz: 913aa637b83f0de8d664dfbb811ce379a61c4fae6cc7c64c79eab9f95c167b0428fff77bb83bb3faed8880d129605f5026a085f1f62960b7755176c1df392972
@@ -1,4 +1,12 @@
1
1
  module PandaPal
2
2
  class ApplicationController < ActionController::Base
3
+ around_action :share_controller_on_thread
4
+
5
+ def share_controller_on_thread
6
+ Thread.current[:controller] = self
7
+ yield
8
+ ensure
9
+ Thread.current[:controller] = nil
10
+ end
3
11
  end
4
12
  end
@@ -17,10 +17,24 @@ module PandaPal
17
17
  end
18
18
  end
19
19
 
20
+ def self.url_for(options)
21
+ request = Thread.current[:controller]&.request
22
+ host = "#{request.scheme}://#{request.host_with_port}"
23
+ if options.is_a?(Symbol)
24
+ Rails.application.routes.url_helpers.send(options, host: host)
25
+ else
26
+ options[:host] ||= host
27
+ Rails.application.routes.url_helpers.url_for(options)
28
+ end
29
+ end
30
+
20
31
  def self.normalize_lti_launch_desc(opts)
21
32
  opts = opts.dup
22
33
  opts.delete(:route_helper_key)
23
34
  opts.delete(:auto_launch)
35
+ opts.each do |k, v|
36
+ opts[k] = v.call if v.is_a?(Proc)
37
+ end
24
38
  opts
25
39
  end
26
40
 
@@ -2,5 +2,4 @@ module PandaPal::Helpers
2
2
  require_relative 'helpers/controller_helper'
3
3
  require_relative 'helpers/route_helper'
4
4
  require_relative 'helpers/secure_headers'
5
- require_relative 'helpers/ability_mixin'
6
5
  end
@@ -1,3 +1,3 @@
1
1
  module PandaPal
2
- VERSION = "5.4.5"
2
+ VERSION = "5.4.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: panda_pal
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.4.5
4
+ version: 5.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Instructure ProServe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-07 00:00:00.000000000 Z
11
+ date: 2022-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -226,7 +226,6 @@ files:
226
226
  - lib/panda_pal.rb
227
227
  - lib/panda_pal/engine.rb
228
228
  - lib/panda_pal/helpers.rb
229
- - lib/panda_pal/helpers/ability_mixin.rb
230
229
  - lib/panda_pal/helpers/controller_helper.rb
231
230
  - lib/panda_pal/helpers/route_helper.rb
232
231
  - lib/panda_pal/helpers/secure_headers.rb
@@ -1,85 +0,0 @@
1
- module PandaPal
2
- module AbilityMixin
3
- extend ActiveSupport::Concern
4
-
5
- class_methods do
6
- def self.role_permissions(labels)
7
- roles = find_roles_by_label(labels)
8
-
9
- if Rails.env.test? && roles.count == 0 && (labels || []).include?('Administrator')
10
- return Hash.new(true)
11
- end
12
-
13
- final = {}
14
- roles.find_each do |role|
15
- role.permissions.each do |perm_name, perm|
16
- final[perm_name] = false if final[perm_name].nil?
17
- final[perm_name] = true if perm['enabled'] == true
18
- end
19
- end
20
- final
21
- end
22
-
23
- def self.find_roles_by_label(labels)
24
- raise "PandaPal AbilityMixin's support for Roles and Permissions requires that Roles be synced by CanvasSync" unless defined?(Role)
25
-
26
- built_ins = []
27
- labels = labels.split(',') if labels.is_a?(String)
28
- custom_labels = Array(labels).reject do |l|
29
- if role_is_default?(l)
30
- built_ins << l
31
- elsif l == 'Account Admin'
32
- built_ins << 'AccountMembership'
33
- else
34
- next
35
- end
36
- true
37
- end
38
- Role.where(workflow_state: 'built_in', base_role_type: built_ins)
39
- .or(Role.where.not(workflow_state: 'built_in').where(label: custom_labels))
40
- end
41
-
42
- def self.role_is_default?(role)
43
- %w[TeacherEnrollment TaEnrollment StudentEnrollment DesignerEnrollment ObserverEnrollment].include? role
44
- end
45
- end
46
-
47
- def is_lti_launch?
48
- @controller.current_session.present?
49
- end
50
-
51
- def panda_pal_session
52
- @panda_pal_session ||= @controller.current_session&.data || {}
53
- end
54
-
55
- def rails_session
56
- @rails_session ||= @controller.session
57
- end
58
-
59
- def launch_params
60
- @launch_params ||= panda_pal_session[:launch_params] || {}
61
- end
62
-
63
- # Roles and Permissions
64
- def lti_roles
65
- @lti_roles ||= LTIRoles::RoleManager.new(launch_params['ext_roles'] || '')
66
- end
67
-
68
- def canvas_permissions
69
- panda_pal_session[:canvas_permissions] ||= self.class.role_permissions(launch_params['custom_canvas_role'])
70
- end
71
-
72
- def canvas_role_labels
73
- labels = launch_params['custom_canvas_role']
74
- labels.is_a?(String) ? labels.split(',') : []
75
- end
76
-
77
- def canvas_roles
78
- self.class.find_roles_by_label(canvas_role_labels)
79
- end
80
-
81
- def launch_role_ids
82
- panda_pal_session[:launch_role_ids] ||= canvas_roles.map(&:canvas_id)
83
- end
84
- end
85
- end