Merge pull request #1775 from abpframework/revert-1736-maliming/patch-2

Revert "Add IIdentityStoreAutoSaveChanges."
pull/1822/head
maliming 5 years ago committed by GitHub
commit 7df0b41eaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -41,54 +41,44 @@ namespace Volo.Abp.Identity
[Authorize(IdentityPermissions.Roles.Create)]
public async Task<IdentityRoleDto> CreateAsync(IdentityRoleCreateDto input)
{
using (_roleManager.AutoSaveRoleChanges(false))
{
var role = new IdentityRole(GuidGenerator.Create(), input.Name, CurrentTenant.Id);
var role = new IdentityRole(GuidGenerator.Create(), input.Name, CurrentTenant.Id);
role.IsDefault = input.IsDefault;
role.IsPublic = input.IsPublic;
role.IsDefault = input.IsDefault;
role.IsPublic = input.IsPublic;
(await _roleManager.CreateAsync(role)).CheckErrors();
await CurrentUnitOfWork.SaveChangesAsync();
(await _roleManager.CreateAsync(role)).CheckErrors();
await CurrentUnitOfWork.SaveChangesAsync();
return ObjectMapper.Map<IdentityRole, IdentityRoleDto>(role);
}
return ObjectMapper.Map<IdentityRole, IdentityRoleDto>(role);
}
[Authorize(IdentityPermissions.Roles.Update)]
public async Task<IdentityRoleDto> UpdateAsync(Guid id, IdentityRoleUpdateDto input)
{
using (_roleManager.AutoSaveRoleChanges(false))
{
var role = await _roleManager.GetByIdAsync(id);
role.ConcurrencyStamp = input.ConcurrencyStamp;
var role = await _roleManager.GetByIdAsync(id);
role.ConcurrencyStamp = input.ConcurrencyStamp;
(await _roleManager.SetRoleNameAsync(role, input.Name)).CheckErrors();
(await _roleManager.SetRoleNameAsync(role, input.Name)).CheckErrors();
role.IsDefault = input.IsDefault;
role.IsPublic = input.IsPublic;
role.IsDefault = input.IsDefault;
role.IsPublic = input.IsPublic;
(await _roleManager.UpdateAsync(role)).CheckErrors();
await CurrentUnitOfWork.SaveChangesAsync();
(await _roleManager.UpdateAsync(role)).CheckErrors();
await CurrentUnitOfWork.SaveChangesAsync();
return ObjectMapper.Map<IdentityRole, IdentityRoleDto>(role);
}
return ObjectMapper.Map<IdentityRole, IdentityRoleDto>(role);
}
[Authorize(IdentityPermissions.Roles.Delete)]
public async Task DeleteAsync(Guid id)
{
using (_roleManager.AutoSaveRoleChanges(false))
var role = await _roleManager.FindByIdAsync(id.ToString());
if (role == null)
{
var role = await _roleManager.FindByIdAsync(id.ToString());
if (role == null)
{
return;
}
(await _roleManager.DeleteAsync(role)).CheckErrors();
await CurrentUnitOfWork.SaveChangesAsync();
return;
}
(await _roleManager.DeleteAsync(role)).CheckErrors();
}
}
}

@ -53,55 +53,45 @@ namespace Volo.Abp.Identity
[Authorize(IdentityPermissions.Users.Create)]
public async Task<IdentityUserDto> CreateAsync(IdentityUserCreateDto input)
{
using (_userManager.AutoSaveUserChanges(false))
{
var user = new IdentityUser(GuidGenerator.Create(), input.UserName, input.Email, CurrentTenant.Id);
var user = new IdentityUser(GuidGenerator.Create(), input.UserName, input.Email, CurrentTenant.Id);
(await _userManager.CreateAsync(user, input.Password)).CheckErrors();
await UpdateUserByInput(user, input);
(await _userManager.CreateAsync(user, input.Password)).CheckErrors();
await UpdateUserByInput(user, input);
await CurrentUnitOfWork.SaveChangesAsync();
await CurrentUnitOfWork.SaveChangesAsync();
return ObjectMapper.Map<IdentityUser, IdentityUserDto>(user);
}
return ObjectMapper.Map<IdentityUser, IdentityUserDto>(user);
}
[Authorize(IdentityPermissions.Users.Update)]
public async Task<IdentityUserDto> UpdateAsync(Guid id, IdentityUserUpdateDto input)
{
using (_userManager.AutoSaveUserChanges(false))
{
var user = await _userManager.GetByIdAsync(id);
user.ConcurrencyStamp = input.ConcurrencyStamp;
var user = await _userManager.GetByIdAsync(id);
user.ConcurrencyStamp = input.ConcurrencyStamp;
(await _userManager.SetUserNameAsync(user, input.UserName)).CheckErrors();
await UpdateUserByInput(user, input);
(await _userManager.UpdateAsync(user)).CheckErrors();
await CurrentUnitOfWork.SaveChangesAsync();
(await _userManager.SetUserNameAsync(user, input.UserName)).CheckErrors();
await UpdateUserByInput(user, input);
(await _userManager.UpdateAsync(user)).CheckErrors();
await CurrentUnitOfWork.SaveChangesAsync();
return ObjectMapper.Map<IdentityUser, IdentityUserDto>(user);
}
return ObjectMapper.Map<IdentityUser, IdentityUserDto>(user);
}
[Authorize(IdentityPermissions.Users.Delete)]
public async Task DeleteAsync(Guid id)
{
using (_userManager.AutoSaveUserChanges(false))
if (CurrentUser.Id == id)
{
if (CurrentUser.Id == id)
{
throw new BusinessException(code: IdentityErrorCodes.UserSelfDeletion);
}
var user = await _userManager.FindByIdAsync(id.ToString());
if (user == null)
{
return;
}
(await _userManager.DeleteAsync(user)).CheckErrors();
await CurrentUnitOfWork.SaveChangesAsync();
throw new BusinessException(code: IdentityErrorCodes.UserSelfDeletion);
}
var user = await _userManager.FindByIdAsync(id.ToString());
if (user == null)
{
return;
}
(await _userManager.DeleteAsync(user)).CheckErrors();
}
[Authorize(IdentityPermissions.Users.Update)]

@ -1,7 +0,0 @@
namespace Volo.Abp.Identity
{
public interface IIdentityStoreAutoSaveChanges
{
bool AutoSaveChanges { get; set; }
}
}

@ -69,20 +69,5 @@ namespace Volo.Abp.Identity
return await base.DeleteAsync(role);
}
public IDisposable AutoSaveRoleChanges(bool autoSaveChanges)
{
if (!(Store is IIdentityStoreAutoSaveChanges store))
{
throw new InvalidOperationException(Store.GetType().FullName + " does not support AutoSaveChanges");
}
var currentAutoSaveChanges = store.AutoSaveChanges;
store.AutoSaveChanges = autoSaveChanges;
return new DisposeAction(() =>
{
store.AutoSaveChanges = currentAutoSaveChanges;
});
}
}
}

@ -20,7 +20,6 @@ namespace Volo.Abp.Identity
public class IdentityRoleStore :
IRoleStore<IdentityRole>,
IRoleClaimStore<IdentityRole>,
IIdentityStoreAutoSaveChanges,
ITransientDependency
{
private readonly IIdentityRoleRepository _roleRepository;

@ -75,20 +75,5 @@ namespace Volo.Abp.Identity
return IdentityResult.Success;
}
public IDisposable AutoSaveUserChanges(bool autoSaveChanges)
{
if (!(Store is IIdentityStoreAutoSaveChanges store))
{
throw new InvalidOperationException(Store.GetType().FullName + " does not support AutoSaveChanges");
}
var currentAutoSaveChanges = store.AutoSaveChanges;
store.AutoSaveChanges = autoSaveChanges;
return new DisposeAction(() =>
{
store.AutoSaveChanges = currentAutoSaveChanges;
});
}
}
}

@ -31,7 +31,6 @@ namespace Volo.Abp.Identity
IUserAuthenticationTokenStore<IdentityUser>,
IUserAuthenticatorKeyStore<IdentityUser>,
IUserTwoFactorRecoveryCodeStore<IdentityUser>,
IIdentityStoreAutoSaveChanges,
ITransientDependency
{
private const string InternalLoginProvider = "[AspNetUserStore]";

Loading…
Cancel
Save