Base solution for your next web application
Open Closed

User Belongs to Multiple Companies #719


User avatar
0
nipunjoshi created

Hello Halil,

I have an urgent requirement that kind of aligns at the intersection of Tenants and OUs. Our company has acquired multiple small companies, and we want to create users in the system from each company. However, some of the users may belong to multiple companies as well.

When the user logs in, if they are members of multiple companies, then I want to show them an option to select which company they want to manage. They select one and that loads the app with the features and permissions for that company. They should have the ability to switch to another company and manage things in for another company.

For some staff, once they are set up they might never see the menu to select company because they belong to only one company.

What is the best way to achieve this? I would greatly appreciate if you could elaborate a little bit on how to achieve this quickly.

Thanks in advance! Nipun


4 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    Single user can not be in multiple tenants. Relation is 1 ot N, not N to N. But, you can achive it by a trick. You can create multiple accounts for a user with same email address and pasword under different tenants. Then you can shitch between tenants or select tenants on login. OU is not proper for it (since permissions, features... are tenant based).

  • User Avatar
    0
    nipunjoshi created

    Thanks for the response!

    My concern is that with this approach, using the trick you mentioned, the data would not be shared between multiple tenants. Or would it be possible to do that?

    In our scenario, the data needs to be shared. Employee of one company should be able to add information into the system, and that information should be available to employees of other companies if they have the right permission in the other company account. I believe multi-tenancy would not let us achieve that.

    Could you please advise on the best way to achieve this?

    I was thinking to may be introduce a concept of sub-tenants, where we add a new table related to sub-tenants and map them to users. Then at the click of login, we can check if the user is associated with more than one sub-tenant, then show a list to select from and if not, then just continue the current way. But that may require mapping to lot of other entities like roles, permissions etc and we do not have much time to get this done. We need a smart solution, which I am hoping you can provide! :)

    Thanks a lot!

  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    I hope I will provide :)

    Good news: You can share data between tenants. There are two ways:

    1. If you do not implement IMayHaveTenant or IMustHaveTenant for an entity, then it's already shared between tenants. You can query the table in any tenant and you access to the all data. Then you can add a custom property to that entity to distinguish permissions or tenants. You can even add a TenantId to the entity (without implementing the interfaces). Then you can manually add where condition if you need.

    2. You can disable automatic filtering even if your entity is tenant specific (see docs: <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Data-Filters#DocDisableFilters">http://www.aspnetboilerplate.com/Pages/ ... bleFilters</a>)

  • User Avatar
    0
    nipunjoshi created

    Excellent! We'll give it a try today and let you know how it goes. Thanks a lot!