panda_pal 5.2.0 → 5.2.5

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: 581c5acd9f7a7ade63f59c20f00f2dcbe7ee4e77670a6e5b98e3b29491f2edc9
4
- data.tar.gz: d42d100b86c391585fa5f45d23368711487c78eff96916aa9868ba1e22f868c1
3
+ metadata.gz: dc40f9ca1d3a036a82a30105f8390bfe9faf57519ca977040921999c1e97221c
4
+ data.tar.gz: 01cca7d9851d83e6d2029291fde3f0baba97c1ba46e51287211b9769f803ae7f
5
5
  SHA512:
6
- metadata.gz: 3ec8c2b412e14dcfc0398fbb496d68d62aec0b897a3f30b5471df867d32b3db8279bd774c0b620a074b204cbbcf5f51c4edb80cfc92285205849f77c11d68122
7
- data.tar.gz: 397d0cfccec6719e1ca201925fd7b5d23e87dff5a4170169c9f7aafd741a2956c8540abcf19dcbbff672faa3e85c54d0e81bc73d033a5e7d5f1ba21d5437577e
6
+ metadata.gz: f41f229e1d8101ce9de5ba9d97ec3e8a3a96b5a11d5fa7972534df8e1d2226172db2e82c3af17f228cc48b1ceb0f8e71e6ded9ed08308c9124a45365e89cf8fa
7
+ data.tar.gz: 29dbfab39a1b5445d31975306af414e336f0a3965c2fd5426e90335963d4da50238c69c7232a66248ad4f7524b7fd3444fc01d2a535ba4e1414aa2f02267b1bc
@@ -1,5 +1,7 @@
1
1
  module PandaPal
2
2
  module MiscHelper
3
+ MigrationClass = Rails.version < '5.0' ? ActiveRecord::Migration : ActiveRecord::Migration[4.2]
4
+
3
5
  def self.to_boolean(v)
4
6
  if Rails.version < '5.0'
5
7
  ActiveRecord::Type::Boolean.new.type_cast_from_user("0")
@@ -1,7 +1,8 @@
1
1
  require 'apartment/elevators/generic'
2
2
 
3
3
  Apartment.configure do |config|
4
- config.excluded_models = ['PandaPal::Organization', 'PandaPal::Session']
4
+ config.excluded_models ||= []
5
+ config.excluded_models |= ['PandaPal::Organization', 'PandaPal::Session']
5
6
 
6
7
  config.tenant_names = lambda {
7
8
  PandaPal::Organization.pluck(:name)
@@ -14,6 +15,21 @@ Rails.application.config.middleware.use Apartment::Elevators::Generic, lambda {
14
15
  end
15
16
  }
16
17
 
18
+ module PandaPal::Plugins::ApartmentCache
19
+ private
20
+
21
+ if Rails.version >= '5.0'
22
+ def normalize_key(key, options)
23
+ "tenant:#{Apartment::Tenant.current}/#{super}"
24
+ end
25
+ else
26
+ def namespaced_key(*args)
27
+ "tenant:#{Apartment::Tenant.current}/#{super}"
28
+ end
29
+ end
30
+ end
31
+ ActiveSupport::Cache::Store.send(:prepend, PandaPal::Plugins::ApartmentCache)
32
+
17
33
  if defined?(ActionCable)
18
34
  module ActionCable
19
35
  module Channel
@@ -38,7 +54,7 @@ if defined?(ActionCable)
38
54
  end
39
55
  end
40
56
 
41
- module ActionCableApartment
57
+ module PandaPal::Plugins::ActionCableApartment
42
58
  module Connection
43
59
  def tenant=(name)
44
60
  @tenant = name
@@ -56,18 +72,50 @@ if defined?(ActionCable)
56
72
  end
57
73
  end
58
74
 
59
- ActionCable::Connection::Base.prepend(ActionCableApartment::Connection)
75
+ ActionCable::Connection::Base.prepend(PandaPal::Plugins::ActionCableApartment::Connection)
60
76
  end
61
77
 
62
- module ApartmentCache
63
- private
78
+ if defined?(Delayed)
79
+ module PandaPal::Plugins
80
+ class ApartmentDelayedJobsPlugin < ::Delayed::Plugin
81
+ callbacks do |lifecycle|
82
+ lifecycle.around(:enqueue) do |job, *args, &block|
83
+ current_tenant = Apartment::Tenant.current
64
84
 
65
- def normalize_key(key, options)
66
- "tenant:#{Apartment::Tenant.current}/#{super}"
67
- end
85
+ #make sure enqueue on public tenant unless we are testing since delayed job is set to run immediately
86
+ Apartment::Tenant.switch!('public') unless Rails.env.test?
87
+ job.tenant = current_tenant
88
+ begin
89
+ block.call(job, *args)
90
+ rescue Exception => e
91
+ Rails.logger.error("Error enqueing job #{job.to_s} - #{e.backtrace}")
92
+ ensure
93
+ #switch back to prev tenant
94
+ Apartment::Tenant.switch!(current_tenant)
95
+ end
96
+ end
97
+
98
+ lifecycle.before(:perform) do |worker, *args, &block|
99
+ tenant = args.first.tenant
100
+ Apartment::Tenant.switch!(tenant) if tenant.present?
101
+ Rails.logger.debug("Running job with tenant #{Apartment::Tenant.current}")
102
+ end
103
+
104
+ lifecycle.around(:invoke_job) do |job, *args, &block|
105
+ begin
106
+ block.call(job, *args)
107
+ ensure
108
+ Apartment::Tenant.switch!('public')
109
+ Rails.logger.debug("Resetting Tenant back to: #{Apartment::Tenant.current}")
110
+ end
111
+ end
68
112
 
69
- def namespaced_key(*args)
70
- normalize_key(*args)
113
+ lifecycle.after(:failure) do |job, *args|
114
+ Rails.logger.error("Job failed on tenant: #{Apartment::Tenant.current}")
115
+ end
116
+ end
117
+ end
71
118
  end
119
+
120
+ Delayed::Worker.plugins << PandaPal::Plugins::ApartmentDelayedJobsPlugin
72
121
  end
73
- ActiveSupport::Cache::Store.send :prepend, ApartmentCache
@@ -1,4 +1,4 @@
1
- class CreatePandaPalOrganizations < ActiveRecord::Migration
1
+ class CreatePandaPalOrganizations < PandaPal::MiscHelper::MigrationClass
2
2
  def change
3
3
  create_table :panda_pal_organizations do |t|
4
4
  t.string :name
@@ -1,4 +1,4 @@
1
- class CreatePandaPalSessions < ActiveRecord::Migration
1
+ class CreatePandaPalSessions < PandaPal::MiscHelper::MigrationClass
2
2
  def change
3
3
  create_table :panda_pal_sessions do |t|
4
4
  t.string :session_key
@@ -1,4 +1,4 @@
1
- class AddPandaPalOrganizationToSession < ActiveRecord::Migration
1
+ class AddPandaPalOrganizationToSession < PandaPal::MiscHelper::MigrationClass
2
2
  def change
3
3
  add_column :panda_pal_sessions, :panda_pal_organization_id, :integer
4
4
  add_index :panda_pal_sessions, :panda_pal_organization_id
@@ -1,4 +1,4 @@
1
- class AddSalesforceIdToOrganizations < ActiveRecord::Migration
1
+ class AddSalesforceIdToOrganizations < PandaPal::MiscHelper::MigrationClass
2
2
  def change
3
3
  add_column :panda_pal_organizations, :salesforce_id, :string, unique: true
4
4
  end
@@ -1,4 +1,4 @@
1
- class EncryptOrganizationSettings < ActiveRecord::Migration
1
+ class EncryptOrganizationSettings < PandaPal::MiscHelper::MigrationClass
2
2
  def up
3
3
  # don't rerun this if it was already run before we renamed the migration.
4
4
  existing_versions = execute ("SELECT * from schema_migrations where version = '30171205183457'")
@@ -1,4 +1,4 @@
1
- class RemoveOldOrganizationSettings < ActiveRecord::Migration
1
+ class RemoveOldOrganizationSettings < PandaPal::MiscHelper::MigrationClass
2
2
  def current_tenant
3
3
  @current_tenant ||= PandaPal::Organization.find_by_name(Apartment::Tenant.current)
4
4
  end
@@ -3,7 +3,7 @@ require 'browser'
3
3
  module PandaPal::Helpers::ControllerHelper
4
4
  extend ActiveSupport::Concern
5
5
 
6
- class SessionNotFound < StandardError; end
6
+ class SessionNonceMismatch < StandardError; end
7
7
 
8
8
  included do
9
9
  helper_method :link_nonce, :current_session
@@ -22,17 +22,16 @@ module PandaPal::Helpers::ControllerHelper
22
22
  payload = JSON.parse(panda_pal_cryptor.decrypt_and_verify(params[:session_token])).with_indifferent_access
23
23
  matched_session = PandaPal::Session.find_by(session_key: payload[:session_key])
24
24
 
25
- if matched_session.present? && matched_session.data[:link_nonce] == params[:session_token]
25
+ if matched_session.present? && matched_session.data[:link_nonce] == payload[:nonce]
26
26
  @current_session = matched_session
27
27
  @current_session.data[:link_nonce] = nil
28
28
  end
29
+ raise SessionNonceMismatch, "Session Not Found" unless @current_session.present?
29
30
  elsif (session_key = params[:session_key] || session_key_header || flash[:session_key] || session[:session_key]).present?
30
31
  @current_session = PandaPal::Session.find_by(session_key: session_key) if session_key.present?
31
- else
32
- @current_session = PandaPal::Session.new(panda_pal_organization_id: current_organization.id)
33
32
  end
34
33
 
35
- raise SessionNotFound, "Session Not Found" unless @current_session.present?
34
+ @current_session ||= PandaPal::Session.new(panda_pal_organization_id: current_organization.id)
36
35
 
37
36
  @current_session
38
37
  end
@@ -154,6 +153,8 @@ module PandaPal::Helpers::ControllerHelper
154
153
  current_session.panda_pal_organization_id == current_organization.id,
155
154
  Apartment::Tenant.current == current_organization.name
156
155
  ].all?
156
+ rescue SessionNonceMismatch
157
+ false
157
158
  end
158
159
 
159
160
  def safari_override
@@ -166,7 +167,8 @@ module PandaPal::Helpers::ControllerHelper
166
167
  # nicely with webpack-dev-server live reloading (otherwise
167
168
  # you get an access error everytime it tries to live reload).
168
169
 
169
- def redirect_with_session_to(location, params = {}, route_context: self)
170
+ def redirect_with_session_to(location, params = {}, route_context: self, **rest)
171
+ params.merge!(rest)
170
172
  if Rails.env.development?
171
173
  redirect_to route_context.send(location, {
172
174
  session_key: current_session.session_key,
@@ -1,3 +1,3 @@
1
1
  module PandaPal
2
- VERSION = "5.2.0"
2
+ VERSION = "5.2.5"
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.2.0
4
+ version: 5.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Instructure ProServe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-17 00:00:00.000000000 Z
11
+ date: 2020-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails