Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add models and helpers for multi tenancy #45

Merged
merged 23 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
229 changes: 126 additions & 103 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,107 +2,106 @@ PATH
remote: .
specs:
atomic_tenant (1.3.1)
atomic_lti (>= 1.3, < 3)
rails (~> 7.0)
atomic_lti (>= 1.3, < 4)
rails (>= 7.0, < 9)

GEM
remote: https://rubygems.org/
specs:
actioncable (7.1.3.4)
actionpack (= 7.1.3.4)
activesupport (= 7.1.3.4)
actioncable (8.0.0)
actionpack (= 8.0.0)
activesupport (= 8.0.0)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
zeitwerk (~> 2.6)
actionmailbox (7.1.3.4)
actionpack (= 7.1.3.4)
activejob (= 7.1.3.4)
activerecord (= 7.1.3.4)
activestorage (= 7.1.3.4)
activesupport (= 7.1.3.4)
mail (>= 2.7.1)
net-imap
net-pop
net-smtp
actionmailer (7.1.3.4)
actionpack (= 7.1.3.4)
actionview (= 7.1.3.4)
activejob (= 7.1.3.4)
activesupport (= 7.1.3.4)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
actionmailbox (8.0.0)
actionpack (= 8.0.0)
activejob (= 8.0.0)
activerecord (= 8.0.0)
activestorage (= 8.0.0)
activesupport (= 8.0.0)
mail (>= 2.8.0)
actionmailer (8.0.0)
actionpack (= 8.0.0)
actionview (= 8.0.0)
activejob (= 8.0.0)
activesupport (= 8.0.0)
mail (>= 2.8.0)
rails-dom-testing (~> 2.2)
actionpack (7.1.3.4)
actionview (= 7.1.3.4)
activesupport (= 7.1.3.4)
actionpack (8.0.0)
actionview (= 8.0.0)
activesupport (= 8.0.0)
nokogiri (>= 1.8.5)
racc
rack (>= 2.2.4)
rack-session (>= 1.0.1)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
actiontext (7.1.3.4)
actionpack (= 7.1.3.4)
activerecord (= 7.1.3.4)
activestorage (= 7.1.3.4)
activesupport (= 7.1.3.4)
useragent (~> 0.16)
actiontext (8.0.0)
actionpack (= 8.0.0)
activerecord (= 8.0.0)
activestorage (= 8.0.0)
activesupport (= 8.0.0)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (7.1.3.4)
activesupport (= 7.1.3.4)
actionview (8.0.0)
activesupport (= 8.0.0)
builder (~> 3.1)
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
activejob (7.1.3.4)
activesupport (= 7.1.3.4)
activejob (8.0.0)
activesupport (= 8.0.0)
globalid (>= 0.3.6)
activemodel (7.1.3.4)
activesupport (= 7.1.3.4)
activerecord (7.1.3.4)
activemodel (= 7.1.3.4)
activesupport (= 7.1.3.4)
activemodel (8.0.0)
activesupport (= 8.0.0)
activerecord (8.0.0)
activemodel (= 8.0.0)
activesupport (= 8.0.0)
timeout (>= 0.4.0)
activestorage (7.1.3.4)
actionpack (= 7.1.3.4)
activejob (= 7.1.3.4)
activerecord (= 7.1.3.4)
activesupport (= 7.1.3.4)
activestorage (8.0.0)
actionpack (= 8.0.0)
activejob (= 8.0.0)
activerecord (= 8.0.0)
activesupport (= 8.0.0)
marcel (~> 1.0)
activesupport (7.1.3.4)
activesupport (8.0.0)
base64
benchmark (>= 0.3)
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
concurrent-ruby (~> 1.0, >= 1.3.1)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
logger (>= 1.4.2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
atomic_lti (2.0.0)
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
uri (>= 0.13.1)
atomic_lti (3.1.0)
pg (~> 1.3)
rails (~> 7.1)
rails (>= 7.1, < 9.0)
base64 (0.2.0)
benchmark (0.4.0)
bigdecimal (3.1.8)
builder (3.3.0)
concurrent-ruby (1.3.3)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
crass (1.0.6)
date (3.3.4)
date (3.4.0)
drb (2.2.1)
erubi (1.13.0)
globalid (1.2.1)
activesupport (>= 6.1)
i18n (1.14.5)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
io-console (0.7.2)
irb (1.14.1)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
loofah (2.22.0)
logger (1.6.1)
loofah (2.23.1)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
mail (2.8.1)
Expand All @@ -112,9 +111,8 @@ GEM
net-smtp
marcel (1.0.4)
mini_mime (1.1.5)
minitest (5.24.0)
mutex_m (0.2.0)
net-imap (0.4.16)
minitest (5.25.1)
net-imap (0.5.1)
date
net-protocol
net-pop (0.1.2)
Expand All @@ -123,89 +121,114 @@ GEM
timeout
net-smtp (0.5.0)
net-protocol
nio4r (2.7.3)
nokogiri (1.16.6-arm64-darwin)
nio4r (2.7.4)
nokogiri (1.16.7-aarch64-linux)
racc (~> 1.4)
nokogiri (1.16.7-arm-linux)
racc (~> 1.4)
nokogiri (1.16.7-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.6-x86_64-darwin)
nokogiri (1.16.7-x86-linux)
racc (~> 1.4)
nokogiri (1.16.6-x86_64-linux)
nokogiri (1.16.7-x86_64-darwin)
racc (~> 1.4)
pg (1.5.8)
psych (5.1.2)
nokogiri (1.16.7-x86_64-linux)
racc (~> 1.4)
pg (1.5.9)
psych (5.2.0)
stringio
racc (1.8.0)
rack (3.1.4)
racc (1.8.1)
rack (3.1.8)
rack-session (2.0.0)
rack (>= 3.0.0)
rack-test (2.1.0)
rack (>= 1.3)
rackup (2.1.0)
rackup (2.2.1)
rack (>= 3)
webrick (~> 1.8)
rails (7.1.3.4)
actioncable (= 7.1.3.4)
actionmailbox (= 7.1.3.4)
actionmailer (= 7.1.3.4)
actionpack (= 7.1.3.4)
actiontext (= 7.1.3.4)
actionview (= 7.1.3.4)
activejob (= 7.1.3.4)
activemodel (= 7.1.3.4)
activerecord (= 7.1.3.4)
activestorage (= 7.1.3.4)
activesupport (= 7.1.3.4)
rails (8.0.0)
actioncable (= 8.0.0)
actionmailbox (= 8.0.0)
actionmailer (= 8.0.0)
actionpack (= 8.0.0)
actiontext (= 8.0.0)
actionview (= 8.0.0)
activejob (= 8.0.0)
activemodel (= 8.0.0)
activerecord (= 8.0.0)
activestorage (= 8.0.0)
activesupport (= 8.0.0)
bundler (>= 1.15.0)
railties (= 7.1.3.4)
railties (= 8.0.0)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
railties (7.1.3.4)
actionpack (= 7.1.3.4)
activesupport (= 7.1.3.4)
irb
railties (8.0.0)
actionpack (= 8.0.0)
activesupport (= 8.0.0)
irb (~> 1.13)
rackup (>= 1.0.0)
rake (>= 12.2)
thor (~> 1.0, >= 1.2.2)
zeitwerk (~> 2.6)
rake (13.2.1)
rdoc (6.7.0)
rdoc (6.8.1)
psych (>= 4.0.0)
reline (0.5.10)
reline (0.5.11)
io-console (~> 0.5)
sprockets (4.2.0)
securerandom (0.3.2)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
sprockets-rails (3.4.2)
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets-rails (3.5.2)
actionpack (>= 6.1)
activesupport (>= 6.1)
sprockets (>= 3.0.0)
sqlite3 (1.6.3-arm64-darwin)
sqlite3 (1.6.3-x86_64-darwin)
sqlite3 (1.6.3-x86_64-linux)
stringio (3.1.1)
sqlite3 (2.3.0-aarch64-linux-gnu)
sqlite3 (2.3.0-aarch64-linux-musl)
sqlite3 (2.3.0-arm-linux-gnu)
sqlite3 (2.3.0-arm-linux-musl)
sqlite3 (2.3.0-arm64-darwin)
sqlite3 (2.3.0-x86-linux-gnu)
sqlite3 (2.3.0-x86-linux-musl)
sqlite3 (2.3.0-x86_64-darwin)
sqlite3 (2.3.0-x86_64-linux-gnu)
sqlite3 (2.3.0-x86_64-linux-musl)
stringio (3.1.2)
thor (1.3.2)
timeout (0.4.1)
timeout (0.4.2)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
webrick (1.8.2)
uri (1.0.2)
useragent (0.16.10)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
zeitwerk (2.6.18)
zeitwerk (2.7.1)

PLATFORMS
arm64-darwin-23
x86_64-darwin-22
aarch64-linux
aarch64-linux-gnu
aarch64-linux-musl
arm-linux
arm-linux-gnu
arm-linux-musl
arm64-darwin
x86-linux
x86-linux-gnu
x86-linux-musl
x86_64-darwin
x86_64-linux
x86_64-linux-gnu
x86_64-linux-musl

DEPENDENCIES
atomic_tenant!
sprockets-rails
sqlite3

BUNDLED WITH
2.3.4
2.5.10
4 changes: 2 additions & 2 deletions atomic_tenant.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ Gem::Specification.new do |spec|
Dir['{app,config,db,lib}/**/*', 'MIT-LICENSE', 'Rakefile', 'README.md']
end

spec.add_dependency 'atomic_lti', '>= 1.3', '< 3'
spec.add_dependency "rails", "~> 7.0"
spec.add_dependency 'atomic_lti', '>= 1.3', '< 4'
spec.add_dependency "rails", ">= 7.0", "< 9"
end
15 changes: 14 additions & 1 deletion lib/atomic_tenant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
require 'atomic_tenant/deployment_manager/deployment_manager_strategy'
require 'atomic_tenant/engine'
require 'atomic_tenant/current_application_instance_middleware'
require 'atomic_tenant/tenant_switching'
require 'atomic_tenant/row_level_security'
require 'atomic_tenant/tenantable'
require 'atomic_tenant/active_job'

module AtomicTenant
mattr_accessor :custom_strategies
Expand All @@ -13,9 +17,18 @@ module AtomicTenant
mattr_accessor :jwt_aud

mattr_accessor :admin_subdomain

mattr_accessor :tenants_table
mattr_accessor :db_tenant_restricted_user

def self.get_application_instance(iss:, deployment_id:)
AtomicTenant::LtiDeployment.find_by(iss: iss, deployment_id: deployment_id)
end

def self.tenant_model
AtomicTenant.tenants_table.to_s.classify.constantize
end

def self.tenanted_by
"#{AtomicTenant.tenants_table.to_s.singularize}_id"
end
end
24 changes: 24 additions & 0 deletions lib/atomic_tenant/active_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module AtomicTenant
module ActiveJob
extend ActiveSupport::Concern

class_methods do
def execute(job_data)
tenant_key = job_data.delete("tenant")
tenant = AtomicTenant.tenant_model.find_by(key: tenant_key)
AtomicTenant.tenant_model.switch(tenant) do
super
end
end
end

def initialize(*_args, **_kargs)
@tenant = AtomicTenant.tenant_model.current_key
super
end

def serialize
super.merge('tenant' => @tenant)
end
end
end
Loading