require_tenant doesn't throw on controller index of newly scaffolded model
Not sure if this is working as intended, but from what I'm able to gather from the acts_as_tenant gem, it should be throwing a ActsAsTenant::NoTenant error.
Steps to repro:
Steps to repro:
- Scaffold out new model (e.g. A projects model), add account_id and multitenancy acts_as_tenant/belongs to values
- Set require_tenant to true in acts_as_tenant intialializer
- Restart app
- Visit /projects URL in incognito browser
- All projects show
- Open Rails Console, type "Project.all", you'll get the NoTenant error.
Seems to be an issue with sort_by_params not respecting the tenant.
... or I'm misunderstanding the usage/etc. Thoughts?
I think know the problem. I'm using subdomains. The first account I created in the config does not have a subdomain set up, (it is nil in the db).
In the set_current_request_details.rb file we check for the subdomain (I'm running on localhost:5000, the root domain) and this line of code is executing:
In the set_current_request_details.rb file we check for the subdomain (I'm running on localhost:5000, the root domain) and this line of code is executing:
if Jumpstart::Multitenancy.subdomain? Current.account ||= Account.find_by(subdomain: request.subdomains.first) end
The request.subdomains.first is nil. The "Account.find_by(...)" is looking for a subdomain that is nil. Since the subdomain in my only account is nil, its using that one. Therefore, the account is set (the tenant is set), which is why when I attempt to load it in a signed out manner, the app still finds a tenant.
If I change the code to this:
if Jumpstart::Multitenancy.subdomain? && request.subdomains.first != nil Current.account ||= Account.find_by(subdomain: request.subdomains.first) end
Then it works as I would expect and I get a NoTenant error. However, I'm not sure if thats the best place to check for it.
Opinions on this?
Turn on `require_tenant` for ActsAsTenant. https://gitlab.com/gorails/jumpstart-pro/-/blob/master/config/initializers/acts_as_tenant.rb#L5
Since it depends on how you intend to use it, we just keep it using the defaults.
Since it depends on how you intend to use it, we just keep it using the defaults.
Notifications
You’re not receiving notifications from this thread.