Open Closed

How to prevent assigning a user to multiple Organization Units #1977


User avatar
0
bozkan created
  • ABP Framework version: v4.4.3
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes
  • Exception message and stack trace:
  • Steps to reproduce the issue:"

We have a requirement to prevent assigning a user to multiple OU's. A user should only be a member of single group. Is there a way to achieve this?


1 Answer(s)
  • User Avatar
    1
    EngincanV created
    Support Team .NET Developer

    Hi @bozkan, you can override the AddToOrganizationUnitAsync method of IdentityUserManager class and inside of the method simply check the user is in any organization unit or not.

    • You can implement something similar with the following code.
    public async override Task AddToOrganizationUnitAsync(IdentityUser user, OrganizationUnit ou)
    {
        if (user.OrganizationUnits.Any())
        {
            return;
        }
        
        base.AddToOrganizationUnitAsync(user, ou);
    }
    
    • To overriding IdentityUserManager, see https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Overriding-Services#example-overriding-a-domain-service.
Made with ❤️ on ABP v9.1.0-preview. Updated on November 11, 2024, 11:11