Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable SoftDelete for AbpUserRole

By default, the AbpUserRole and AbpRole implement ISoftDelete. Is it possible to disable it?

I tried to do this:

[AbpAuthorize(AppPermissions.Pages_Administration_Roles_Delete)]
public async Task DeleteRole(EntityDto input)
{
    using (CurrentUnitOfWork.DisableFilter(AbpDataFilters.SoftDelete))
    {
        var role = await _roleManager.GetRoleByIdAsync(input.Id);
        var users = await UserManager.GetUsersInRoleAsync(role.Name);

        foreach (var user in users)
        {
            CheckErrors(await UserManager.RemoveFromRoleAsync(user, role.Name));
        }

        CheckErrors(await _roleManager.DeleteAsync(role));
    }
}

Although the filter is disabled in the current unit of work, it doesn't work. The entity is marked as deleted.

like image 499
Marcos Lommez Avatar asked Jan 17 '26 13:01

Marcos Lommez


1 Answers

Answered in this topic: https://forum.aspnetboilerplate.com/viewtopic.php?p=6180#p6193

Data filters work on selecting data. If your entity is SoftDelete, ABP always soft-deletes it and prevents actually deleting.

You can override CancelDeletionForSoftDelete method in your DbContext and prevent cancellation conditionally.

So, like this:

protected override void CancelDeletionForSoftDelete(EntityEntry entry)
{
    if (IsSoftDeleteFilterEnabled)
    {
        base.CancelDeletionForSoftDelete(entry);
    }
}
like image 184
aaron Avatar answered Jan 20 '26 03:01

aaron



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!