Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Extend Tenant with Region and give access accordingly #2916


User avatar
0
bilalhaidar created

Hello, In a previous post you directed me to an article on how to extend a Tenant or any existing entity with additional properties or fields. I have a requirement where I need to add a Region property for each Tenant. Then, when a user logs in on the host, he/she will be given access to all Tenants having a certain Region property. Can you please guide me on how to implement such thing with the multitenancy Abp?

At first, I thought of the following: 1- Add a Region property to each Tenant. This will be a 1-to-many relationship, as a Region can have 1 or more Tenant, while a Tenant can only have 1 single Tenant. 2- Create a Role per Region at the Host-side 3- Add users to roles, and hence, based on role name I get to know all Tenants under that role.

I still believe I should make use of Permissions somewhere, but not sure how and where.

I appreciate your feedback.

Thank you Bilal


7 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Instead of creating roles, you can filter tenants in TenantAppService by current user's granted regions. This is a simpler way I think.

  • User Avatar
    0
    bilalhaidar created

    Hi Ismail So how would I link user to Region?

    The user cannot be part of a Tenant to view other tenants right? So I need to create user as host user.

    Then according to what you said I should be linking user to Region?

    Can you pls illustrate more Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    The user cannot be part of a Tenant to view other tenants right? So I need to create user as host user.
    

    Yes, you are right. I think you want to do it only for host users, is this right ?

    Then according to what you said I should be linking user to Region?

    Yes, you can create a new entity UserRegions and it can contain UserId and list of region Ids.

    What do you think ?

    Thanks.

  • User Avatar
    0
    bilalhaidar created

    That sounds interesting.

    To recap:

    1. A tenant is to be extended with a new property called 'Region'. Upon creation of a new Tenant a region will be assigned accordingly.

    2. A host user makes more sense to be given access to multiple tenants instead of tenant user.

    3. A host admin needs to assign users to regions. This way the app would query data from all the tenants under each assigned region. An example: region 1 is assigned to 2 tenants. A user would get data from 2 tenants under region 1.

    4. The User Region entity. Is it a many to many relation between user and region? I can create a new entity UserRegion and then add a new property of list of UserRegion on the User entity?

    How does it sound?

    Originally given the fact regions are static I thought of creating a role per region and add users to roles. Then a union between regions for all roles the user is assigned to would give me all regions. However I like more your solution. It's more dynamic.

    Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Yes, you explained better then I do :). Just one thing, I thought you are going to show only tenant list to users according to allowed regions but according to your last explanation I think you are going to show tenant related data to users right ?

    If you are going to use DB per Tenant, this might be hard to do technically.

    Thanks.

  • User Avatar
    0
    bilalhaidar created

    Yes true. Some users will be assigned to regions hence they want to be able to see data under all tenants they have access to.

    I'm using a single dB which I think will be easier to do correct?

    One more thing, is it okay to extend the Tenant and User entities as per above?

    Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    One more thing, is it okay to extend the Tenant and User entities as per above?

    Yes, there is no problem with that, you can extend them according to your needs.

    If you are using single DB, then it will not be a problem to query data for different tenants in a single query.