panda_pal 5.15.1.beta1 → 5.15.1.beta3
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.
- checksums.yaml +4 -4
- data/app/controllers/panda_pal/api_call_controller.rb +1 -2
- data/app/controllers/panda_pal/lti_controller.rb +1 -3
- data/app/controllers/panda_pal/lti_v1_p0_controller.rb +1 -3
- data/app/controllers/panda_pal/lti_v1_p3_controller.rb +1 -3
- data/app/controllers/panda_pal/{application_controller.rb → panda_pal_controller.rb} +1 -1
- data/config/initializers/apartment.rb +32 -22
- data/db/migrate/20250401214421_rename_session_session_key.rb +1 -1
- data/lib/panda_pal/engine.rb +1 -0
- data/lib/panda_pal/version.rb +1 -1
- data/panda_pal.gemspec +0 -14
- data/spec/controllers/panda_pal/api_call_controller_spec.rb +18 -20
- data/spec/core/apartment_multidb_spec.rb +1 -1
- data/spec/factories/panda_pal_organizations.rb +1 -1
- data/spec/factories/panda_pal_sessions.rb +4 -4
- data/spec/{dummy → internal}/config/database.yml +1 -12
- data/spec/{dummy → internal}/config/routes.rb +2 -1
- data/spec/internal/config/storage.yml +3 -0
- data/spec/internal/db/schema.rb +6 -0
- data/spec/models/panda_pal/api_call_spec.rb +1 -1
- data/spec/models/panda_pal/organization/settings_validation_spec.rb +1 -1
- data/spec/models/panda_pal/organization/task_scheduling_spec.rb +1 -1
- data/spec/models/panda_pal/organization_spec.rb +4 -4
- data/spec/models/panda_pal/session_spec.rb +1 -1
- data/spec/spec_helper.rb +54 -5
- metadata +10 -220
- data/spec/dummy/README.rdoc +0 -28
- data/spec/dummy/Rakefile +0 -6
- data/spec/dummy/app/assets/javascripts/application.js +0 -13
- data/spec/dummy/app/assets/stylesheets/application.css +0 -15
- data/spec/dummy/app/bin/bundle +0 -3
- data/spec/dummy/app/bin/rails +0 -4
- data/spec/dummy/app/bin/rake +0 -4
- data/spec/dummy/app/bin/setup +0 -29
- data/spec/dummy/app/controllers/application_controller.rb +0 -5
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/config/application.rb +0 -29
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -27
- data/spec/dummy/config/environments/production.rb +0 -68
- data/spec/dummy/config/environments/test.rb +0 -47
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -16
- data/spec/dummy/config/initializers/mime_types.rb +0 -4
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -23
- data/spec/dummy/config/secrets.yml +0 -22
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/db/schema.rb +0 -49
- data/spec/dummy/db/test2_schema.rb +0 -49
- data/spec/dummy/public/404.html +0 -67
- data/spec/dummy/public/422.html +0 -67
- data/spec/dummy/public/500.html +0 -66
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/rails_helper.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fb9b051afba3b9befb9e505f2c8d6bd8f595112ceea1778af4ea0190220d9a5
|
4
|
+
data.tar.gz: 7368671098738bbd1229c0329d9919e48d675357fcf4d13db9e3d408ed1b03f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24151b3bfe982fb78ff9093141482bcb0d065f1ca1a462c0ba252fb1a4e987f8001ea06bb8fc79258d93adf448db7bd67e24aaa5bd4f6b21608bac4b34250b97
|
7
|
+
data.tar.gz: e8d9921e233f328b1d96efda77fa8a1520052562ff942f4a759f4d6c3d386f7de0c6effd5edf2b5c1a216eab9c47b1d2ce276bdf9ca143ef9f3ddfe041680013
|
@@ -1,8 +1,7 @@
|
|
1
1
|
require 'jwt'
|
2
|
-
require_dependency "panda_pal/application_controller"
|
3
2
|
|
4
3
|
module PandaPal
|
5
|
-
class ApiCallController <
|
4
|
+
class ApiCallController < PandaPalController
|
6
5
|
rescue_from StandardError do |err|
|
7
6
|
render json: { status: 'error' }, status: 500
|
8
7
|
end
|
@@ -10,25 +10,29 @@ require "apartment/adapters/postgresql_adapter"
|
|
10
10
|
module Apartment
|
11
11
|
SHARD_PREFIXES = ["SHARD_DB", "HEROKU_POSTGRESQL"]
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
shard_to_env = {}
|
13
|
+
class << self
|
14
|
+
def_delegators :connection_class, :connected?
|
16
15
|
|
17
|
-
|
16
|
+
def shard_configurations
|
17
|
+
$shard_configurations ||= begin
|
18
|
+
shard_to_env = {}
|
18
19
|
|
19
|
-
|
20
|
-
m = /^(#{SHARD_PREFIXES.join("|")})_(\w+)_URL$/.match(k)
|
21
|
-
next unless m
|
20
|
+
base_config = ActiveRecord::Base.configurations.find_db_config(Rails.env).configuration_hash
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
ENV.keys.each do |k|
|
23
|
+
m = /^(#{SHARD_PREFIXES.join("|")})_(\w+)_URL$/.match(k)
|
24
|
+
next unless m
|
25
|
+
|
26
|
+
url = ENV[k]
|
27
|
+
shardcfg = ActiveRecord::Base.configurations.resolve(url).configuration_hash
|
28
|
+
shardcfg = base_config.merge(shardcfg || {})
|
29
|
+
shard_to_env[m[2].downcase] = shardcfg
|
30
|
+
end
|
28
31
|
|
29
|
-
|
32
|
+
shard_to_env.freeze unless Rails.env.test?
|
30
33
|
|
31
|
-
|
34
|
+
shard_to_env
|
35
|
+
end
|
32
36
|
end
|
33
37
|
end
|
34
38
|
|
@@ -120,14 +124,12 @@ module Apartment
|
|
120
124
|
|
121
125
|
raise ActiveRecord::StatementInvalid, "PandaPal/Apartment Mutli-DB support does not currently support DB roles" if ActiveRecord::Base.current_role != ActiveRecord::Base.default_role
|
122
126
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
end
|
127
|
-
|
127
|
+
shard, schema = Apartment::Tenant.split_tenant(@current)
|
128
|
+
Apartment.establish_connection(multi_tenantify(tenant, false)) if shard != "default"
|
129
|
+
Apartment.connection.verify!
|
128
130
|
Apartment.connection.enable_query_cache! if query_cache_enabled
|
129
131
|
|
130
|
-
raise ActiveRecord::StatementInvalid, "Could not find schema for tenant #{tenant} (#{tenant_schemas.inspect})" unless schema_exists?(tenant_schemas)
|
132
|
+
raise ActiveRecord::StatementInvalid, "Could not find schema for tenant \"#{tenant}\": (#{tenant_schemas.inspect})" unless schema_exists?(tenant_schemas)
|
131
133
|
|
132
134
|
Apartment.connection.schema_search_path = full_search_path
|
133
135
|
rescue *rescuable_exceptions => e
|
@@ -150,6 +152,14 @@ module Apartment
|
|
150
152
|
schema
|
151
153
|
end
|
152
154
|
end
|
155
|
+
|
156
|
+
def raise_schema_connect_to_new(tenant, exception)
|
157
|
+
shard, schema = Tenant.split_tenant(tenant)
|
158
|
+
raise TenantNotFound, <<~EXCEPTION_MESSAGE
|
159
|
+
Could not set search path to schemas, they may be invalid: "#{schema}" #{full_search_path}.
|
160
|
+
Original error: #{exception.class}: #{exception}
|
161
|
+
EXCEPTION_MESSAGE
|
162
|
+
end
|
153
163
|
end
|
154
164
|
end
|
155
165
|
|
@@ -181,7 +191,7 @@ module Apartment
|
|
181
191
|
# to effectively disable this patch for that model.
|
182
192
|
if (adapter = Thread.current[:apartment_adapter]) && adapter.is_a?(Apartment::Adapters::PostgresMultiDBSchemaAdapter) && !adapter.is_excluded_model?(self)
|
183
193
|
shard, schema = Apartment::Tenant.split_tenant(adapter.current)
|
184
|
-
return "
|
194
|
+
return "apt:#{shard}" unless shard == "default"
|
185
195
|
end
|
186
196
|
|
187
197
|
pre_apartment_current_shard
|
@@ -210,7 +220,7 @@ Apartment.configure do |config|
|
|
210
220
|
shard_configurations = Apartment.shard_configurations
|
211
221
|
|
212
222
|
PandaPal::Organization.all.to_a.each_with_object({}) do |org, hash|
|
213
|
-
shard = org.shard || "default"
|
223
|
+
shard = org.shard.to_s || "default"
|
214
224
|
hash[org.tenant_name] = shard == "default" ? base_config : shard_configurations[shard.downcase]
|
215
225
|
end
|
216
226
|
else
|
data/lib/panda_pal/engine.rb
CHANGED
data/lib/panda_pal/version.rb
CHANGED
data/panda_pal.gemspec
CHANGED
@@ -29,18 +29,4 @@ Gem::Specification.new do |s|
|
|
29
29
|
s.add_dependency 'json-jwt'
|
30
30
|
s.add_dependency 'jwt'
|
31
31
|
s.add_dependency 'httparty'
|
32
|
-
|
33
|
-
s.add_development_dependency "rails", "~> 7.0"
|
34
|
-
s.add_development_dependency 'pg'
|
35
|
-
s.add_development_dependency 'sidekiq', "< 7.0"
|
36
|
-
s.add_development_dependency 'sidekiq-scheduler'
|
37
|
-
s.add_development_dependency 'ros-apartment', '~> 3.0'
|
38
|
-
s.add_development_dependency 'ros-apartment-sidekiq', '~> 1.2'
|
39
|
-
s.add_development_dependency 'rspec-rails'
|
40
|
-
s.add_development_dependency 'factory_girl_rails'
|
41
|
-
|
42
|
-
s.add_development_dependency "redis", ">=4.2", "< 5.0"
|
43
|
-
|
44
|
-
# TODO See https://github.com/mikel/mail/issues/1489
|
45
|
-
s.add_development_dependency "mail", "2.7.1"
|
46
32
|
end
|
@@ -1,27 +1,25 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
let!(:api_call) { ApiCall.create!(logic: '"#{p[:foo]}_bar"') }
|
3
|
+
RSpec.describe PandaPal::ApiCallController, type: :controller do
|
4
|
+
let!(:api_call) { PandaPal::ApiCall.create!(logic: '"#{p[:foo]}_bar"') }
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def json_body
|
7
|
+
JSON.parse(response.body)
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
describe "#call" do
|
11
|
+
it "calls the function with parameters" do
|
12
|
+
get :call, params: { token: api_call.jwt_token, foo: 'bar', use_route: 'panda_pal' }
|
13
|
+
expect(response).to be_successful
|
14
|
+
expect(json_body["status"]).to eq 'ok'
|
15
|
+
expect(json_body["result"]).to eq 'bar_bar'
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
18
|
+
it "fails given a bad JWT" do
|
19
|
+
get :call, params: { token: "bad.jwt.token", foo: 'bar', use_route: 'panda_pal' }
|
20
|
+
expect(response).not_to be_successful
|
21
|
+
expect(json_body["status"]).to eq 'error'
|
22
|
+
expect(json_body["error"]).to eq 'Invalid JWT'
|
25
23
|
end
|
26
24
|
end
|
27
25
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
1
|
default: &default
|
2
|
+
database: panda-pal-test
|
3
3
|
adapter: postgresql
|
4
4
|
encoding: unicode
|
5
5
|
# For details on connection pooling, see Rails configuration guide
|
@@ -9,10 +9,6 @@ default: &default
|
|
9
9
|
password: <%= ENV.fetch("DB_PASSWORD", "") %>
|
10
10
|
host: <%= ENV.fetch("DB_ADDRESS", "localhost") %>
|
11
11
|
|
12
|
-
development:
|
13
|
-
<<: *default
|
14
|
-
database: panda_pal_development
|
15
|
-
|
16
12
|
test:
|
17
13
|
test1:
|
18
14
|
<<: *default
|
@@ -20,10 +16,3 @@ test:
|
|
20
16
|
test2:
|
21
17
|
<<: *default
|
22
18
|
database: panda_pal_test2
|
23
|
-
|
24
|
-
production:
|
25
|
-
<<: *default
|
26
|
-
host: <%= ENV.fetch('DB_ADDRESS', 'localhost') %>
|
27
|
-
database: panda_pal_production
|
28
|
-
username: <%= ENV.fetch("DB_USERNAME", "panda_pal_specs_postgres_user") %>
|
29
|
-
password: <%= ENV.fetch("DB_PASSWORD", 'panda_pal_specs_postgres_password') %>
|
@@ -1,15 +1,15 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
module PandaPal
|
4
4
|
RSpec.describe Organization, type: :model do
|
5
5
|
it 'creates a schema upon creation' do
|
6
|
-
expect(Apartment::Tenant).to receive(:create)
|
6
|
+
expect(Apartment::Tenant).to receive(:create).and_call_original
|
7
7
|
create :panda_pal_organization
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'deletes a schema upon deletion' do
|
11
|
-
expect(Apartment::Tenant).to receive(:create)
|
12
|
-
expect(Apartment::Tenant).to receive(:drop)
|
11
|
+
expect(Apartment::Tenant).to receive(:create).and_call_original
|
12
|
+
expect(Apartment::Tenant).to receive(:drop).and_call_original
|
13
13
|
org = create :panda_pal_organization
|
14
14
|
org.destroy
|
15
15
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,19 +1,40 @@
|
|
1
|
-
ENV["RAILS_ENV"] ||= 'test'
|
1
|
+
# ENV["RAILS_ENV"] ||= 'test'
|
2
2
|
|
3
|
+
require 'bundler'
|
4
|
+
Bundler.require :default, :development
|
5
|
+
|
6
|
+
Combustion.initialize! :active_record, :active_job, :action_controller
|
7
|
+
|
8
|
+
require 'sidekiq'
|
9
|
+
require 'sidekiq/rails'
|
3
10
|
require 'sidekiq/testing'
|
4
11
|
require 'sidekiq-scheduler'
|
5
12
|
|
6
|
-
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
7
13
|
require 'rspec/rails'
|
8
14
|
require 'rspec/autorun'
|
9
15
|
require 'nokogiri'
|
10
|
-
require '
|
16
|
+
require 'factory_bot_rails'
|
17
|
+
|
18
|
+
require "panda_pal/spec_helper"
|
11
19
|
|
12
|
-
ActiveRecord::Migration.maintain_test_schema!
|
13
20
|
ActiveRecord::Schema.verbose = false
|
14
21
|
|
22
|
+
Dir[File.dirname(__FILE__) + "/factories/**/*.rb"].each {|f| require f }
|
23
|
+
|
15
24
|
RSpec.configure do |config|
|
16
|
-
config.include
|
25
|
+
config.include PandaPal::SpecHelper
|
26
|
+
config.include FactoryBot::Syntax::Methods
|
27
|
+
|
28
|
+
config.before(:each) do
|
29
|
+
allow_any_instance_of(PandaPal::Organization).to receive(:create_schema).and_wrap_original do |m, *args|
|
30
|
+
org = m.receiver
|
31
|
+
m.call(*args)
|
32
|
+
org.switch_tenant do
|
33
|
+
Combustion::Database::LoadSchema.call
|
34
|
+
Combustion::Database::Migrate.call
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
17
38
|
|
18
39
|
# rspec-expectations config goes here. You can use an alternate
|
19
40
|
# assertion/expectation library such as wrong or the stdlib/minitest
|
@@ -45,6 +66,34 @@ RSpec.configure do |config|
|
|
45
66
|
}
|
46
67
|
end
|
47
68
|
|
69
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
70
|
+
config.fixture_paths |= [
|
71
|
+
"#{::Rails.root}/spec/fixtures"
|
72
|
+
]
|
73
|
+
|
74
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
75
|
+
# examples within a transaction, remove the following line or assign false
|
76
|
+
# instead of true.
|
77
|
+
config.use_transactional_fixtures = true
|
78
|
+
|
79
|
+
# RSpec Rails can automatically mix in different behaviours to your tests
|
80
|
+
# based on their file location, for example enabling you to call `get` and
|
81
|
+
# `post` in specs under `spec/controllers`.
|
82
|
+
#
|
83
|
+
# You can disable this behaviour by removing the line below, and instead
|
84
|
+
# explicitly tag your specs with their type, e.g.:
|
85
|
+
#
|
86
|
+
# RSpec.describe UsersController, :type => :controller do
|
87
|
+
# # ...
|
88
|
+
# end
|
89
|
+
#
|
90
|
+
# The different available types are documented in the features, such as in
|
91
|
+
# https://relishapp.com/rspec/rspec-rails/docs
|
92
|
+
config.infer_spec_type_from_file_location!
|
93
|
+
|
94
|
+
# Filter lines from Rails gems in backtraces.
|
95
|
+
config.filter_rails_from_backtrace!
|
96
|
+
|
48
97
|
# The settings below are suggested to provide a good initial experience
|
49
98
|
# with RSpec, but feel free to customize to your heart's content.
|
50
99
|
=begin
|