Open Closed

Bug: Cannot update user details if IdentityUserController and MaxUserCount has been set #2724


User avatar
0
dmeagor created

ABP Framework version: 5.1.1 User Interface: Angular database provider: EF Core

When using the IdentityUserController and MaxUserCount has been set, the tenant is at the maximum number of users. Updating the details of an existing user is not possible.

If there a way to bypass this quickly?

Thanks in advance :)

[INF] Route matched with {area = "identity", controller = "User", action = "Update", page = ""}. Executing controller action with signature System.Threading.Tasks.Task1[Volo.Abp.Identity.IdentityUserDto] UpdateAsync(System.Guid, Volo.Abp.Identity.IdentityUserUpdateDto) on controller Volo.Abp.Identity.IdentityUserController (Volo.Abp.Identity.Pro.HttpApi). 

[WRN] ---------- RemoteServiceErrorInfo ---------- 

Reached maximum allowed user count! This tenant is allowed to have a maximum of 3 users. 

[WRN] Exception of type 'Volo.Abp.BusinessException' was thrown.

  Volo.Abp.BusinessException: Exception of type 'Volo.Abp.BusinessException' was thrown
  . at Volo.Abp.Identity.MaxUserCountValidator.CheckMaxUserCountAsync()
   at Volo.Abp.Identity.MaxUserCountValidator.ValidateAsync(UserManager1 manager, IdentityUser user)
at Microsoft.AspNetCore.Identity.UserManager1.ValidateUserAsync(TUser user)
 at Microsoft.AspNetCore.Identity.UserManager1.UpdateUserAsync(TUser user)

7 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    How many users do you have now? Is it three?

  • User Avatar
    0
    luke created

    Hi

    Yes, it's three users in the tenant when the error is thrown

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    ok, I will try to fix it.

  • User Avatar
    0
    dmeagor created

    Reopening as the bot appears to have closed this issue before resolution.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    HI

    This problem has been fixed.

    PreConfigure<IdentityBuilder>(builder =>
    {
        builder.Services.RemoveAll(x => x.ImplementationType == typeof(MaxUserCountValidator));
        builder.AddUserValidator<MyMaxUserCountValidator>();
    });
    
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Identity;
    using Volo.Abp.Features;
    using Volo.Abp.Identity.Features;
    
    namespace Volo.Abp.Identity;
    
    public class MyMaxUserCountValidator : IUserValidator<IdentityUser>
    {
        protected IFeatureChecker FeatureChecker { get; }
        protected IIdentityUserRepository UserRepository { get; }
    
        public MyMaxUserCountValidator (IFeatureChecker featureChecker, IIdentityUserRepository userRepository)
        {
            FeatureChecker = featureChecker;
            UserRepository = userRepository;
        }
    
        public async Task<IdentityResult> ValidateAsync(UserManager<IdentityUser> manager, IdentityUser user)
        {
            await CheckMaxUserCountAsync(user);
    
            return IdentityResult.Success;
        }
    
        protected virtual async Task CheckMaxUserCountAsync(IdentityUser user)
        {
            var maxUserCount = await FeatureChecker.GetAsync<int>(IdentityProFeature.MaxUserCount);
            if (maxUserCount <= 0)
            {
                return;
            }
    
            var existUser = await UserRepository.FindAsync(user.Id);
            if (existUser == null)
            {
                var currentUserCount = await UserRepository.GetCountAsync();
                if (currentUserCount >= maxUserCount)
                {
                    throw new BusinessException(IdentityProErrorCodes.MaximumUserCount)
                        .WithData("MaxUserCount", maxUserCount);
                }
            }
        }
    }
    
  • User Avatar
    0
    luke created

    Thanks for that :)

    Has it made it to the nuget packages yet?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Yes, 5.2-RC2

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09