From 8df5cc358217eb2f8f92d8b6c072db5aebf29faf Mon Sep 17 00:00:00 2001 From: maliming Date: Mon, 9 Sep 2019 20:26:28 +0800 Subject: [PATCH 1/6] Add IIdentityStoreAutoSaveChanges. --- .../Abp/Identity/IdentityRoleAppService.cs | 48 ++++++++++------- .../Abp/Identity/IdentityUserAppService.cs | 54 +++++++++++-------- .../Identity/IIdentityStoreAutoSaveChanges.cs | 7 +++ .../Volo/Abp/Identity/IdentityRoleManager.cs | 15 ++++++ .../Volo/Abp/Identity/IdentityRoleStore.cs | 1 + .../Volo/Abp/Identity/IdentityUserManager.cs | 15 ++++++ .../Volo/Abp/Identity/IdentityUserStore.cs | 1 + 7 files changed, 100 insertions(+), 41 deletions(-) create mode 100644 modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityStoreAutoSaveChanges.cs diff --git a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs index 939d9739d2..a56b78ca2a 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs @@ -41,44 +41,54 @@ namespace Volo.Abp.Identity [Authorize(IdentityPermissions.Roles.Create)] public async Task CreateAsync(IdentityRoleCreateDto input) { - var role = new IdentityRole(GuidGenerator.Create(), input.Name, CurrentTenant.Id); + using (_roleManager.AutoSaveRoleChanges(false)) + { + 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(role); + return ObjectMapper.Map(role); + } } [Authorize(IdentityPermissions.Roles.Update)] public async Task UpdateAsync(Guid id, IdentityRoleUpdateDto input) { - var role = await _roleManager.GetByIdAsync(id); - role.ConcurrencyStamp = input.ConcurrencyStamp; + using (_roleManager.AutoSaveRoleChanges(false)) + { + 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(role); + return ObjectMapper.Map(role); + } } [Authorize(IdentityPermissions.Roles.Delete)] public async Task DeleteAsync(Guid id) { - var role = await _roleManager.FindByIdAsync(id.ToString()); - if (role == null) + using (_roleManager.AutoSaveRoleChanges(false)) { - return; + var role = await _roleManager.FindByIdAsync(id.ToString()); + if (role == null) + { + return; + } + + (await _roleManager.DeleteAsync(role)).CheckErrors(); + await CurrentUnitOfWork.SaveChangesAsync(); } - - (await _roleManager.DeleteAsync(role)).CheckErrors(); } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs index ad87b0041f..df22e1b985 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs @@ -53,45 +53,55 @@ namespace Volo.Abp.Identity [Authorize(IdentityPermissions.Users.Create)] public async Task CreateAsync(IdentityUserCreateDto input) { - var user = new IdentityUser(GuidGenerator.Create(), input.UserName, input.Email, CurrentTenant.Id); + using (_userManager.AutoSaveUserChanges(false)) + { + 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(user); + return ObjectMapper.Map(user); + } } [Authorize(IdentityPermissions.Users.Update)] public async Task UpdateAsync(Guid id, IdentityUserUpdateDto input) { - var user = await _userManager.GetByIdAsync(id); - user.ConcurrencyStamp = input.ConcurrencyStamp; + using (_userManager.AutoSaveUserChanges(false)) + { + 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(user); + return ObjectMapper.Map(user); + } } [Authorize(IdentityPermissions.Users.Delete)] public async Task DeleteAsync(Guid id) { - if (CurrentUser.Id == id) + using (_userManager.AutoSaveUserChanges(false)) { - throw new BusinessException(code: IdentityErrorCodes.UserSelfDeletion); + 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(); } - - var user = await _userManager.FindByIdAsync(id.ToString()); - if (user == null) - { - return; - } - - (await _userManager.DeleteAsync(user)).CheckErrors(); } [Authorize(IdentityPermissions.Users.Update)] diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityStoreAutoSaveChanges.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityStoreAutoSaveChanges.cs new file mode 100644 index 0000000000..af4cb3362f --- /dev/null +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityStoreAutoSaveChanges.cs @@ -0,0 +1,7 @@ +namespace Volo.Abp.Identity +{ + public interface IIdentityStoreAutoSaveChanges + { + bool AutoSaveChanges { get; set; } + } +} \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleManager.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleManager.cs index c66d501146..429012bfca 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleManager.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleManager.cs @@ -69,5 +69,20 @@ 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; + }); + } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleStore.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleStore.cs index 175b051a48..60c41ab0a8 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleStore.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleStore.cs @@ -20,6 +20,7 @@ namespace Volo.Abp.Identity public class IdentityRoleStore : IRoleStore, IRoleClaimStore, + IIdentityStoreAutoSaveChanges, ITransientDependency { private readonly IIdentityRoleRepository _roleRepository; diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs index dc4b2fe4b2..7212b8f0d2 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs @@ -75,5 +75,20 @@ 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; + }); + } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs index bac63a0c11..9e302ef6c9 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs @@ -31,6 +31,7 @@ namespace Volo.Abp.Identity IUserAuthenticationTokenStore, IUserAuthenticatorKeyStore, IUserTwoFactorRecoveryCodeStore, + IIdentityStoreAutoSaveChanges, ITransientDependency { private const string InternalLoginProvider = "[AspNetUserStore]"; From 143a34e2440dc222158a8d5de8b831c13c2625af Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Fri, 20 Sep 2019 14:46:28 +0300 Subject: [PATCH 2/6] fix(setting-management): fix permisson problem --- .../services/setting-management.service.ts | 43 +++++++++++++------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/npm/ng-packs/packages/setting-management/src/lib/services/setting-management.service.ts b/npm/ng-packs/packages/setting-management/src/lib/services/setting-management.service.ts index 14f7a35a75..c7d9e15620 100644 --- a/npm/ng-packs/packages/setting-management/src/lib/services/setting-management.service.ts +++ b/npm/ng-packs/packages/setting-management/src/lib/services/setting-management.service.ts @@ -2,9 +2,11 @@ import { SettingTab } from '@abp/ng.theme.shared'; import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; import { Navigate } from '@ngxs/router-plugin'; -import { Store } from '@ngxs/store'; +import { Store, Actions, ofActionSuccessful } from '@ngxs/store'; import { Subject } from 'rxjs'; -import { ConfigState } from '@abp/ng.core'; +import { ConfigState, GetAppConfiguration } from '@abp/ng.core'; +import { OAuthService } from 'angular-oauth2-oidc'; +import { takeUntil } from 'rxjs/operators'; @Injectable({ providedIn: 'root' }) export class SettingManagementService { @@ -14,10 +16,27 @@ export class SettingManagementService { private destroy$ = new Subject(); - constructor(private router: Router, private store: Store) { - setTimeout(() => { - this.setSettings(); - }, 0); + constructor( + private actions: Actions, + private router: Router, + private store: Store, + private oAuthService: OAuthService, + ) { + if (this.oAuthService.hasValidAccessToken()) { + setTimeout(() => { + this.setSettings(); + }, 0); + } else { + this.actions + .pipe(ofActionSuccessful(GetAppConfiguration)) + .pipe(takeUntil(this.destroy$)) + .subscribe(() => { + if (this.oAuthService.hasValidAccessToken()) { + this.setSettings(); + this.destroy$.next(); + } + }); + } } ngOnDestroy() { @@ -25,13 +44,11 @@ export class SettingManagementService { } setSettings() { - setTimeout(() => { - const route = this.router.config.find(r => r.path === 'setting-management'); - this.settings = (route.data.settings as SettingTab[]) - .filter(setting => this.store.selectSnapshot(ConfigState.getGrantedPolicy(setting.requiredPolicy))) - .sort((a, b) => a.order - b.order); - this.checkSelected(); - }, 0); + const route = this.router.config.find(r => r.path === 'setting-management'); + this.settings = (route.data.settings as SettingTab[]) + .filter(setting => this.store.selectSnapshot(ConfigState.getGrantedPolicy(setting.requiredPolicy))) + .sort((a, b) => a.order - b.order); + this.checkSelected(); } checkSelected() { From ef796645d96bc6968565497995049314ce2039e8 Mon Sep 17 00:00:00 2001 From: TheDiaval Date: Fri, 20 Sep 2019 15:01:32 +0300 Subject: [PATCH 3/6] fix(theme-shared): change abpButton class from fa-spin to fa-pulse --- .../theme-shared/src/lib/components/button/button.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/npm/ng-packs/packages/theme-shared/src/lib/components/button/button.component.ts b/npm/ng-packs/packages/theme-shared/src/lib/components/button/button.component.ts index 0196ad19ec..7a915d667c 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/components/button/button.component.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/components/button/button.component.ts @@ -25,6 +25,6 @@ export class ButtonComponent { disabled: boolean = false; get icon(): string { - return `${this.loading ? 'fa fa-spin fa-spinner' : this.iconClass || 'd-none'}`; + return `${this.loading ? 'fa fa-pulse fa-spinner' : this.iconClass || 'd-none'}`; } } From 38f5f320147dcaf781a905b0d67d8634cd89173d Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Fri, 20 Sep 2019 15:28:32 +0300 Subject: [PATCH 4/6] fix(theme-shared): loader bar turning back problem --- .../services/setting-management.service.ts | 25 ++++++++----------- .../src/lib/animations/fade.animations.ts | 6 +++++ .../loader-bar/loader-bar.component.ts | 5 ++-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/npm/ng-packs/packages/setting-management/src/lib/services/setting-management.service.ts b/npm/ng-packs/packages/setting-management/src/lib/services/setting-management.service.ts index c7d9e15620..79878b1717 100644 --- a/npm/ng-packs/packages/setting-management/src/lib/services/setting-management.service.ts +++ b/npm/ng-packs/packages/setting-management/src/lib/services/setting-management.service.ts @@ -22,21 +22,16 @@ export class SettingManagementService { private store: Store, private oAuthService: OAuthService, ) { - if (this.oAuthService.hasValidAccessToken()) { - setTimeout(() => { - this.setSettings(); - }, 0); - } else { - this.actions - .pipe(ofActionSuccessful(GetAppConfiguration)) - .pipe(takeUntil(this.destroy$)) - .subscribe(() => { - if (this.oAuthService.hasValidAccessToken()) { - this.setSettings(); - this.destroy$.next(); - } - }); - } + setTimeout(() => this.setSettings(), 0); + + this.actions + .pipe(ofActionSuccessful(GetAppConfiguration)) + .pipe(takeUntil(this.destroy$)) + .subscribe(() => { + if (this.oAuthService.hasValidAccessToken()) { + this.setSettings(); + } + }); } ngOnDestroy() { diff --git a/npm/ng-packs/packages/theme-shared/src/lib/animations/fade.animations.ts b/npm/ng-packs/packages/theme-shared/src/lib/animations/fade.animations.ts index 906e6fb526..d5180f35ea 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/animations/fade.animations.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/animations/fade.animations.ts @@ -6,6 +6,12 @@ export const fade = trigger('fade', [ transition(':leave', animate(250, style({ opacity: 0 }))), ]); +export const fadeInOut = trigger('fadeInOut', [ + state('out', style({ opacity: 0 })), + state('in', style({ opacity: 1 })), + transition('in <=> out', [animate(250)]), +]); + export const fadeIn = trigger('fadeIn', [ state('*', style({ opacity: 1 })), transition('* => *', [style({ opacity: 0 }), animate(250)]), diff --git a/npm/ng-packs/packages/theme-shared/src/lib/components/loader-bar/loader-bar.component.ts b/npm/ng-packs/packages/theme-shared/src/lib/components/loader-bar/loader-bar.component.ts index 8200642e26..d52b9faffc 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/components/loader-bar/loader-bar.component.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/components/loader-bar/loader-bar.component.ts @@ -4,6 +4,7 @@ import { NavigationEnd, NavigationStart, Router, NavigationError } from '@angula import { takeUntilDestroy } from '@ngx-validate/core'; import { Actions, ofActionSuccessful } from '@ngxs/store'; import { filter } from 'rxjs/operators'; +import { timer } from 'rxjs'; @Component({ selector: 'abp-loader-bar', @@ -92,8 +93,6 @@ export class LoaderBarComponent implements OnDestroy { this.progressLevel = 100; this.isLoading = false; - setTimeout(() => { - this.progressLevel = 0; - }, 800); + timer(810).subscribe(() => (this.progressLevel = 0)); } } From 683337f6b45442fd8d2edb19fd978aa1bd47170f Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Fri, 20 Sep 2019 15:28:57 +0300 Subject: [PATCH 5/6] fix(theme-shared): change fade animation name --- .../packages/theme-shared/src/lib/animations/fade.animations.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/npm/ng-packs/packages/theme-shared/src/lib/animations/fade.animations.ts b/npm/ng-packs/packages/theme-shared/src/lib/animations/fade.animations.ts index d5180f35ea..fb523e0d56 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/animations/fade.animations.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/animations/fade.animations.ts @@ -6,7 +6,7 @@ export const fade = trigger('fade', [ transition(':leave', animate(250, style({ opacity: 0 }))), ]); -export const fadeInOut = trigger('fadeInOut', [ +export const fadeWithStates = trigger('fadeInOut', [ state('out', style({ opacity: 0 })), state('in', style({ opacity: 1 })), transition('in <=> out', [animate(250)]), From 92f3cc02a774b32299c98c340fc913a8b662fe5b Mon Sep 17 00:00:00 2001 From: maliming Date: Fri, 20 Sep 2019 20:44:14 +0800 Subject: [PATCH 6/6] Revert "Add IIdentityStoreAutoSaveChanges." --- .../Abp/Identity/IdentityRoleAppService.cs | 48 +++++++---------- .../Abp/Identity/IdentityUserAppService.cs | 54 ++++++++----------- .../Identity/IIdentityStoreAutoSaveChanges.cs | 7 --- .../Volo/Abp/Identity/IdentityRoleManager.cs | 15 ------ .../Volo/Abp/Identity/IdentityRoleStore.cs | 1 - .../Volo/Abp/Identity/IdentityUserManager.cs | 15 ------ .../Volo/Abp/Identity/IdentityUserStore.cs | 1 - 7 files changed, 41 insertions(+), 100 deletions(-) delete mode 100644 modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityStoreAutoSaveChanges.cs diff --git a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs index a56b78ca2a..939d9739d2 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs @@ -41,54 +41,44 @@ namespace Volo.Abp.Identity [Authorize(IdentityPermissions.Roles.Create)] public async Task 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(role); - } + return ObjectMapper.Map(role); } [Authorize(IdentityPermissions.Roles.Update)] public async Task 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(role); - } + return ObjectMapper.Map(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(); } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs index df22e1b985..ad87b0041f 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs @@ -53,55 +53,45 @@ namespace Volo.Abp.Identity [Authorize(IdentityPermissions.Users.Create)] public async Task 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(user); - } + return ObjectMapper.Map(user); } [Authorize(IdentityPermissions.Users.Update)] public async Task 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(user); - } + return ObjectMapper.Map(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)] diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityStoreAutoSaveChanges.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityStoreAutoSaveChanges.cs deleted file mode 100644 index af4cb3362f..0000000000 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityStoreAutoSaveChanges.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Volo.Abp.Identity -{ - public interface IIdentityStoreAutoSaveChanges - { - bool AutoSaveChanges { get; set; } - } -} \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleManager.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleManager.cs index 429012bfca..c66d501146 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleManager.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleManager.cs @@ -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; - }); - } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleStore.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleStore.cs index 60c41ab0a8..175b051a48 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleStore.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleStore.cs @@ -20,7 +20,6 @@ namespace Volo.Abp.Identity public class IdentityRoleStore : IRoleStore, IRoleClaimStore, - IIdentityStoreAutoSaveChanges, ITransientDependency { private readonly IIdentityRoleRepository _roleRepository; diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs index 7212b8f0d2..dc4b2fe4b2 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs @@ -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; - }); - } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs index 9e302ef6c9..bac63a0c11 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs @@ -31,7 +31,6 @@ namespace Volo.Abp.Identity IUserAuthenticationTokenStore, IUserAuthenticatorKeyStore, IUserTwoFactorRecoveryCodeStore, - IIdentityStoreAutoSaveChanges, ITransientDependency { private const string InternalLoginProvider = "[AspNetUserStore]";