Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DisableValidation doesn't work after adding it to Controller and AppService #9082

Closed
ebicoglu opened this issue May 19, 2021 · 1 comment
Closed
Assignees
Milestone

Comments

@ebicoglu
Copy link
Member

Reported at https://support.abp.io/QA/Questions/1340/How-to-removedisable-validation-for-existing-DTO-object

I tried to put [DisableValidation] to CreateAsync in both Controller and AppService, it still does not work.
if the Password field has value, it hits the method -> the override is succesfully
if the Password is null/empty, the validation is triggered -> the [DisableValidation] is not working

    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(IdentityUserController))]
    public class CustomIdentityUserController : IdentityUserController
    {
        public CustomIdentityUserController(IIdentityUserAppService userAppService) : base(userAppService)
        {
        }

        [DisableValidation]
        public override Task<IdentityUserDto> CreateAsync(IdentityUserCreateDto input)
        {
            return UserAppService.CreateAsync(input);
        }
    }
    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(IdentityUserAppService))]
    public class CustomIdentityUserAppService : IdentityUserAppService
    {
        public CustomIdentityUserAppService(
            IdentityUserManager userManager,
            IIdentityUserRepository userRepository,
            IIdentityRoleRepository roleRepository,
            IOrganizationUnitRepository organizationUnitRepository,
            IIdentityClaimTypeRepository identityClaimTypeRepository,
            IdentityTwoFactorManager identityTwoFactorManager
        ) : base(userManager,
            userRepository,
            roleRepository,
            organizationUnitRepository,
            identityClaimTypeRepository,
            identityTwoFactorManager)
        {
        }

        [DisableValidation]
        public override async Task<IdentityUserDto> CreateAsync(IdentityUserCreateDto input)
        {
            var user = new IdentityUser(
                GuidGenerator.Create(),
                input.UserName,
                input.Email,
                CurrentTenant.Id
            );

            input.MapExtraPropertiesTo(user);

            (await UserManager.CreateAsync(user)).CheckErrors();
            await UpdateUserByInput(user, input);

            await CurrentUnitOfWork.SaveChangesAsync();

            var userDto = ObjectMapper.Map<IdentityUser, IdentityUserDto>(user);

            return userDto;
        }
    }
@maliming
Copy link
Member

public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
//TODO: Configuration to disable validation for controllers..?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
@maliming @ebicoglu and others