Starts in:
0 DAY
16 HRS
29 MIN
37 SEC
Starts in:
0 D
16 H
29 M
37 S
Open Closed

Permission management across multiple tenants #4959


User avatar
0
portx-dev created

Let's assume that Tenant 1 is treated as a parent tenant, and Tenant 2 and Tenant 3 are child tenants. There is a specification to create roles to be used for Tenant 2 and Tenant 3 on Tenant 1. Is that possible with ABP?

  • ABP Framework version: ABP Commercial 7.1e:

2 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You can consider creating the same role with permissions for tenants 2 and 3 using domain events or override the application service interface of the module

    • https://docs.abp.io/en/abp/latest/Local-Event-Bus#pre-built-events
    • https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Overriding-Services

    Pseudocode:

    public class MyIdentityRoleAppService: IdentityRoleAppService
    {
        
        public override async ....CreateAsync()
        {
            create role...
            
            if(CurrentTenant.Name = "Tenant1")
            {
               using(CurrentTenant.Change("Tenant2"))
               {
                  Create role...           
               }
            }
        }
    }
    
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Here's another suggestion:

    If you can accept data sync delay, you can create a background worker to synchronize tenant and role permissions: https://docs.abp.io/en/abp/latest/Background-Workers#asyncperiodicbackgroundworkerbase

    For example:

    public class RolePermissionsSynchronizeWorker : AsyncPeriodicBackgroundWorkerBase
    {
        public RolePermissionsSynchronizeWorker(
                AbpAsyncTimer timer,
                IServiceScopeFactory serviceScopeFactory
            ) : base(
                timer, 
                serviceScopeFactory)
        {
            Timer.Period = 600000; //10 minutes
        }
    
        protected async override Task DoWorkAsync(
            PeriodicBackgroundWorkerContext workerContext)
        {
            Logger.LogInformation("Starting: Sync roles...");
    
            .....
            
            Logger.LogInformation("Completed: Sync roles...");
        }
    }
    
Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06