Browse Source

refactor #574

pull/574/head
Yunus Emre Kalkan 8 years ago
parent
commit
46fa7d0aa6
  1. 5
      modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs
  2. 6
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDataSeeder.cs
  3. 7
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRole.cs
  4. 21
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleManager.cs
  5. 4
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/Localization/Domain/en.json
  6. 4
      modules/identity/src/Volo.Abp.Identity.Web/Localization/Resources/AbpIdentity/tr.json
  7. 9
      modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/EditModal.cshtml
  8. 12
      modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/CreateModal.cshtml.cs

5
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<IdentityRoleDto> 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();

6
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)

7
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRole.cs

@ -47,7 +47,7 @@ namespace Volo.Abp.Identity
/// <summary>
/// A static role can not be deleted/renamed
/// </summary>
public virtual bool IsStatic { get; protected set; }
public virtual bool IsStatic { get; set; }
/// <summary>
/// A user can see other user's public roles
@ -59,7 +59,7 @@ namespace Volo.Abp.Identity
/// </summary>
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<IdentityRoleClaim>();
}

21
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<IdentityResource> _localizer;
private readonly ICancellationTokenProvider _cancellationTokenProvider;
public IdentityRoleManager(
@ -22,7 +25,8 @@ namespace Volo.Abp.Identity
IEnumerable<IRoleValidator<IdentityRole>> roleValidators,
ILookupNormalizer keyNormalizer,
IdentityErrorDescriber errors,
ILogger<IdentityRoleManager> logger,
ILogger<IdentityRoleManager> logger,
IStringLocalizer<IdentityResource> 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<IdentityRole> GetDefaultRoles()
{
if (Roles == null)
{
return new List<IdentityRole>();
}
return Roles.Where(r => r.IsDefault).ToList();
}
public override async Task<IdentityResult> 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);

4
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."
}
}

4
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."
}
}

9
modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/EditModal.cshtml

@ -12,7 +12,14 @@
<abp-modal-header title="@L["Edit"].Value"></abp-modal-header>
<abp-modal-body>
<abp-input asp-for="Role.Id" />
<abp-input asp-for="Role.Name" readonly="@(Model.Role.IsStatic?" readonly":"")" />
@if (Model.Role.IsStatic)
{
<abp-input asp-for="Role.Name" readonly="readonly" />
}
else
{
<abp-input asp-for="Role.Name" />
}
<abp-input asp-for="Role.IsDefault" />
<abp-input asp-for="Role.IsPublic" />
</abp-modal-body>

12
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<List<IdentityRoleDto>, AssignedRoleViewModel[]>(
await _identityRoleAppService.GetAllListAsync()
);
Roles = ObjectMapper.Map<List<IdentityRoleDto>, 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; }
}
}
}

Loading…
Cancel
Save