Skip to content

Commit

Permalink
feat(utilities/multi_tenant): add parent tenant support
Browse files Browse the repository at this point in the history
  • Loading branch information
stakach committed Jan 21, 2025
1 parent e13df4c commit b9623f7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ shards:

placeos-models:
git: https://github.com/placeos/models.git
version: 9.62.1
version: 9.62.2

pool:
git: https://github.com/ysbaddaden/pool.git
Expand Down
4 changes: 3 additions & 1 deletion src/controllers/utilities/multi_tenant.cr
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ module Utils::MultiTenant
begin
user_email_domain = token.user.email.split('@', 2)[1]
tenants = Tenant.where("domain = ? AND (email_domain = ? OR email_domain IS NULL)", authority_domain_host, user_email_domain).to_a
@tenant = tenants.find(tenants.first) { |t| t.email_domain == user_email_domain } unless tenants.empty?
if !tenants.empty? && (found = tenants.find(tenants.first) { |t| t.email_domain == user_email_domain })
@tenant = found.parent || found
end
Log.context.set(domain: authority_domain_host, tenant_id: @tenant.try &.id)
rescue error
respond_with(:not_found) do
Expand Down

0 comments on commit b9623f7

Please sign in to comment.