-
-
Notifications
You must be signed in to change notification settings - Fork 267
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
Overlapping tenants #191
base: master
Are you sure you want to change the base?
Overlapping tenants #191
Conversation
Overlapping tenants
Any chance to merge this? |
Just curious, what is your use case for overlapping tenants? Merging of this pr has been on my plate for quite some time, but I've been hesitant to do it given how little demand for this feature seems to be. |
In our case we have devices that both belong to a manufacturer and a client (each with their own login and management features). |
Hello, any chance of having this merged? It's a really useful feature. |
This looks more like a feature for your own fork, not general-purpose |
I'm undecided on this one without a good example. class Manager < ApplicationRecord
acts_as_tenant :account
acts_as_tenant :project
end In this example, Project is a global model that is not in the Account tenant as well? |
Perhaps the names here are misleading.
A client might have multiple projects in the platform, the same for a freelancer doing projects. Both different subsets of project. ps. We are actively using this feature on a large project now |
it could be either way: it could be a global model, and it could be in the Account tenant. regardless, |
maybe I don't get it... why is the purpose of using ActsAsTenant here? Why not just
@borisd so in your case,
...And in different controller actions you Just trying to understand in what scenarios this could be useful... In my imagination, there is
and this looks like some sort of deviation from multitenancy to build platform features. |
We are running two different "sub sites" on the same database. One group of controllers set tenant as Client while the other group as Freelancer. Quite a number of different models belong have two inheritance columns. With this system I am (99%) certain that a client or freelancer never see any data they have no access to. But there is still some common models between them. Specifically the project (the most sensitive model) is correctly scoped away by tenancy instead of worrying to filter in the app. |
@yshmarov the purpose of using ActsAsTenant is the same as it is when there's only one tenant. I think @borisd has a point that the models used in the tests in this PR (Account, Manager, and Project) are a little confusing and do not serve the purpose of communicating the idea of it very well. There were chosen simply because they were existing models. Maybe a real example of how this feature is used will be more useful, so here it goes. Here at Collage we've been using this feature for about 2 years now to support two types of users, or accounts: companies and brokers.
When you log into Collage as a company, you can see all employees in your company, since Employee
and rely on ActsAsTenant to correctly scope Employees to either company or broker, whichever is relevant at the moment. |
Problem
As it stands, we can only have one tenant per model. Sometimes a need arises to define multiple tenants owning the same model, which
acts_as_tenant
does not currently support. For example,Manager
belongs toProject
andAccount
, but only acts as tenant withAccount
; you can't set the current tenant toProject
to limit your scope of managers to all managers belonging to the project.Desired functionality
Changes introduced in this PR
This PR allows you to specify as many
acts_as_tenant
directives on the model as you want. If current tenant is of typeAccount
, then only theacts_as_tenant :account
will be used in the default scope / validation callbacks / etc. Similarly, if current tenant isProject
, only theacts_as_tenant :project
will take effect.Backwards compatibility
This PR introduces a breaking change by removing some public API (
ActsAsTenant.fkey
, etc.) Since this API was not covered by the original test suite, I'm assuming it to be a non-documented API which was not supposed to be used directly by the users of this gem anyway. However, this may break things for some people, so we might want to put those back with a deprecation warning and remove it in the next major release of the gem. Obviously those functions are meaningless when using more than one type of tenant, so we can raise if that's the case. That way all current users of the gem will get deprecation warnings but won't have anything broken.Included changes
This PR basically includes changes from #190, since without fixing the issue mentioned in that PR tests related to polymorphic tenants would not pass.