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 0d3b883c05..f3ad2f880a 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 @@ -69,7 +69,10 @@ namespace Volo.Abp.Identity [Authorize(IdentityPermissions.Roles.Create)] public async Task CreateAsync(IdentityRoleCreateDto input) { - var role = new IdentityRole(GuidGenerator.Create(), input.Name, input.IsDefault, false, input.IsPublic, CurrentTenant.Id); + var role = new IdentityRole(GuidGenerator.Create(), input.Name, CurrentTenant.Id); + + role.IsDefault = input.IsDefault; + role.IsPublic = input.IsPublic; (await _roleManager.CreateAsync(role)).CheckErrors(); await CurrentUnitOfWork.SaveChangesAsync(); diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDataSeeder.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDataSeeder.cs index cff165a1be..1aa90b8b5f 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDataSeeder.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDataSeeder.cs @@ -62,7 +62,11 @@ namespace Volo.Abp.Identity var adminRole = await _roleRepository.FindByNormalizedNameAsync(_lookupNormalizer.Normalize(adminRoleName)); if (adminRole == null) { - adminRole = new IdentityRole(_guidGenerator.Create(), adminRoleName, false, true, true, tenantId); + adminRole = new IdentityRole(_guidGenerator.Create(), adminRoleName, tenantId); + + adminRole.IsStatic = true; + adminRole.IsPublic = true; + CheckIdentityErrors(await _roleManager.CreateAsync(adminRole)); if (adminRolePermissions != null) diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRole.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRole.cs index 33e2188032..8d87bf8788 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRole.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRole.cs @@ -47,7 +47,7 @@ namespace Volo.Abp.Identity /// /// A static role can not be deleted/renamed /// - public virtual bool IsStatic { get; protected set; } + public virtual bool IsStatic { get; set; } /// /// A user can see other user's public roles @@ -59,7 +59,7 @@ namespace Volo.Abp.Identity /// protected IdentityRole() { } - public IdentityRole(Guid id, [NotNull] string name, bool isDefault = false, bool isStatic = false, bool isPublic = false, Guid? tenantId = null) + public IdentityRole(Guid id, [NotNull] string name, Guid? tenantId = null) { Check.NotNull(name, nameof(name)); @@ -68,9 +68,6 @@ namespace Volo.Abp.Identity TenantId = tenantId; NormalizedName = name.ToUpperInvariant(); ConcurrencyStamp = Guid.NewGuid().ToString(); - IsDefault = isDefault; - IsStatic = isStatic; - IsPublic = isPublic; Claims = new Collection(); } 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 25f4214147..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 @@ -4,9 +4,11 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Localization; using Microsoft.Extensions.Logging; using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Services; +using Volo.Abp.Identity.Localization; using Volo.Abp.Threading; namespace Volo.Abp.Identity @@ -15,6 +17,7 @@ namespace Volo.Abp.Identity { protected override CancellationToken CancellationToken => _cancellationTokenProvider.Token; + private readonly IStringLocalizer _localizer; private readonly ICancellationTokenProvider _cancellationTokenProvider; public IdentityRoleManager( @@ -22,7 +25,8 @@ namespace Volo.Abp.Identity IEnumerable> roleValidators, ILookupNormalizer keyNormalizer, IdentityErrorDescriber errors, - ILogger logger, + ILogger logger, + IStringLocalizer localizer, ICancellationTokenProvider cancellationTokenProvider) : base( store, @@ -31,6 +35,7 @@ namespace Volo.Abp.Identity errors, logger) { + _localizer = localizer; _cancellationTokenProvider = cancellationTokenProvider; } @@ -45,21 +50,11 @@ namespace Volo.Abp.Identity return role; } - public List GetDefaultRoles() - { - if (Roles == null) - { - return new List(); - } - - return Roles.Where(r => r.IsDefault).ToList(); - } - public override async Task SetRoleNameAsync(IdentityRole role, string name) { if (role.IsStatic && role.Name != name) { - throw new AbpException("Static roles can not be renamed."); // TODO: localize & change exception type + throw new BusinessException(_localizer["Identity.StaticRoleRenamingErrorMessage"]); // TODO: localize & change exception type } return await base.SetRoleNameAsync(role,name); @@ -69,7 +64,7 @@ namespace Volo.Abp.Identity { if (role.IsStatic) { - throw new AbpException("Static roles can not be deleted."); // TODO: localize & change exception type + throw new BusinessException(_localizer["Identity.StaticRoleDeletionErrorMessage"]); // TODO: localize & change exception type } return await base.DeleteAsync(role); diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/Localization/Domain/en.json b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/Localization/Domain/en.json index c906f523b1..6ecf7122c6 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/Localization/Domain/en.json +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/Localization/Domain/en.json @@ -26,6 +26,8 @@ "Identity.UserLockoutNotEnabled": "Lockout is not enabled for this user.", "Identity.UserNameNotFound": "User {0} does not exist.", "Identity.UserNotInRole": "User is not in role '{0}'.", - "Identity.PasswordConfirmationFailed": "Password does not match the confirm password." + "Identity.PasswordConfirmationFailed": "Password does not match the confirm password.", + "Identity.StaticRoleRenamingErrorMessage": "Static roles can not be renamed.", + "Identity.StaticRoleDeletionErrorMessage": "Static roles can not be deleted." } } \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Localization/Resources/AbpIdentity/tr.json b/modules/identity/src/Volo.Abp.Identity.Web/Localization/Resources/AbpIdentity/tr.json index c9a730f9a2..e0ecf1b5cb 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/Localization/Resources/AbpIdentity/tr.json +++ b/modules/identity/src/Volo.Abp.Identity.Web/Localization/Resources/AbpIdentity/tr.json @@ -29,6 +29,8 @@ "DisplayName:CurrentPassword": "Mevcut şifre", "DisplayName:NewPassword": "Yeni şifre", "DisplayName:NewPasswordConfirm": "Yeni şifre (tekrar)", - "PasswordChangedMessage": "Şifreniz başarıyla değiştirildi." + "PasswordChangedMessage": "Şifreniz başarıyla değiştirildi.", + "Identity.StaticRoleRenamingErrorMessage": "Bir Sabit rolün ismi değiştirilemez.", + "Identity.StaticRoleDeletionErrorMessage": "Bir Sabit rol silinemez." } } \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/EditModal.cshtml b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/EditModal.cshtml index c32671ca62..b09cfe2dcb 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/EditModal.cshtml +++ b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/EditModal.cshtml @@ -12,7 +12,14 @@ - + @if (Model.Role.IsStatic) + { + + } + else + { + + } diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/CreateModal.cshtml.cs b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/CreateModal.cshtml.cs index ed80295c35..15eb60a0b6 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/CreateModal.cshtml.cs +++ b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/CreateModal.cshtml.cs @@ -30,17 +30,11 @@ namespace Volo.Abp.Identity.Web.Pages.Identity.Users var roleDtoList = await _identityRoleAppService.GetAllListAsync(); - Roles = ObjectMapper.Map, AssignedRoleViewModel[]>( - await _identityRoleAppService.GetAllListAsync() - ); + Roles = ObjectMapper.Map, AssignedRoleViewModel[]>(roleDtoList); - var defaultRoles = roleDtoList.Where(r => r.IsDefault).ToList(); foreach (var role in Roles) { - if (defaultRoles.Any(r => r.Name == role.Name)) - { - role.IsAssigned = true; - } + role.IsAssigned = role.IsDefault; } } @@ -87,6 +81,8 @@ namespace Volo.Abp.Identity.Web.Pages.Identity.Users public string Name { get; set; } public bool IsAssigned { get; set; } + + public bool IsDefault { get; set; } } } }