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?

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

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.
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 16, 2026, 14:50
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.