Browse Source

Merge branch 'master' into User-Personal-settings

pull/578/head
Yunus Emre Kalkan 8 years ago
parent
commit
74f388a342
  1. 4
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityRoleCreateOrUpdateDtoBase.cs
  2. 6
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityRoleDto.cs
  3. 6
      modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs
  4. 4
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDataSeeder.cs
  5. 15
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRole.cs
  6. 28
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleManager.cs
  7. 4
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/Localization/Domain/en.json
  8. 3
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContextModelBuilderExtensions.cs
  9. 3
      modules/identity/src/Volo.Abp.Identity.Web/Localization/Resources/AbpIdentity/en.json
  10. 7
      modules/identity/src/Volo.Abp.Identity.Web/Localization/Resources/AbpIdentity/tr.json
  11. 8
      modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/CreateModal.cshtml
  12. 6
      modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/CreateModal.cshtml.cs
  13. 16
      modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/EditModal.cshtml
  14. 8
      modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/EditModal.cshtml.cs
  15. 4
      modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/index.js
  16. 13
      modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/CreateModal.cshtml.cs

4
modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityRoleCreateOrUpdateDtoBase.cs

@ -7,5 +7,9 @@ namespace Volo.Abp.Identity
[Required]
[StringLength(IdentityRoleConsts.MaxNameLength)]
public string Name { get; set; }
public bool IsDefault { get; set; }
public bool IsPublic { get; set; }
}
}

6
modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityRoleDto.cs

@ -6,5 +6,11 @@ namespace Volo.Abp.Identity
public class IdentityRoleDto : EntityDto<Guid>
{
public string Name { get; set; }
public bool IsDefault { get; set; }
public bool IsStatic { get; set; }
public bool IsPublic { get; set; }
}
}

6
modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs

@ -71,6 +71,9 @@ namespace Volo.Abp.Identity
{
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();
@ -84,6 +87,9 @@ namespace Volo.Abp.Identity
(await _roleManager.SetRoleNameAsync(role, input.Name)).CheckErrors();
role.IsDefault = input.IsDefault;
role.IsPublic = input.IsPublic;
(await _roleManager.UpdateAsync(role)).CheckErrors();
await CurrentUnitOfWork.SaveChangesAsync();

4
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDataSeeder.cs

@ -63,6 +63,10 @@ namespace Volo.Abp.Identity
if (adminRole == null)
{
adminRole = new IdentityRole(_guidGenerator.Create(), adminRoleName, tenantId);
adminRole.IsStatic = true;
adminRole.IsPublic = true;
CheckIdentityErrors(await _roleManager.CreateAsync(adminRole));
if (adminRolePermissions != null)

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

@ -39,6 +39,21 @@ namespace Volo.Abp.Identity
[DisableAuditing]
public virtual string ConcurrencyStamp { get; set; }
/// <summary>
/// A default role is automatically assigned to a new user
/// </summary>
public virtual bool IsDefault { get; set; }
/// <summary>
/// A static role can not be deleted/renamed
/// </summary>
public virtual bool IsStatic { get; set; }
/// <summary>
/// A user can see other user's public roles
/// </summary>
public virtual bool IsPublic { get; set; }
/// <summary>
/// Initializes a new instance of <see cref="IdentityRole"/>.
/// </summary>

28
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleManager.cs

@ -1,11 +1,14 @@
using System;
using System.Collections.Generic;
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
@ -14,6 +17,7 @@ namespace Volo.Abp.Identity
{
protected override CancellationToken CancellationToken => _cancellationTokenProvider.Token;
private readonly IStringLocalizer<IdentityResource> _localizer;
private readonly ICancellationTokenProvider _cancellationTokenProvider;
public IdentityRoleManager(
@ -21,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,
@ -30,6 +35,7 @@ namespace Volo.Abp.Identity
errors,
logger)
{
_localizer = localizer;
_cancellationTokenProvider = cancellationTokenProvider;
}
@ -43,5 +49,25 @@ namespace Volo.Abp.Identity
return role;
}
public override async Task<IdentityResult> SetRoleNameAsync(IdentityRole role, string name)
{
if (role.IsStatic && role.Name != name)
{
throw new BusinessException(_localizer["Identity.StaticRoleRenamingErrorMessage"]); // TODO: localize & change exception type
}
return await base.SetRoleNameAsync(role,name);
}
public override async Task<IdentityResult> DeleteAsync(IdentityRole role)
{
if (role.IsStatic)
{
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."
}
}

3
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContextModelBuilderExtensions.cs

@ -97,6 +97,9 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
b.Property(r => r.Name).IsRequired().HasMaxLength(IdentityRoleConsts.MaxNameLength);
b.Property(r => r.NormalizedName).IsRequired().HasMaxLength(IdentityRoleConsts.MaxNormalizedNameLength);
b.Property(r => r.IsDefault).HasColumnName(nameof(IdentityRole.IsDefault));
b.Property(r => r.IsStatic).HasColumnName(nameof(IdentityRole.IsStatic));
b.Property(r => r.IsPublic).HasColumnName(nameof(IdentityRole.IsPublic));
b.HasMany(r => r.Claims).WithOne().HasForeignKey(rc => rc.RoleId).IsRequired();

3
modules/identity/src/Volo.Abp.Identity.Web/Localization/Resources/AbpIdentity/en.json

@ -8,6 +8,9 @@
"EmailAddress": "Email address",
"PhoneNumber": "Phone number",
"UserInformations": "User informations",
"DisplayName:IsDefault": "Default",
"DisplayName:IsStatic": "Static",
"DisplayName:IsPublic": "Public",
"Roles": "Roles",
"Password": "Password",
"PersonalInfo": "Personal Info",

7
modules/identity/src/Volo.Abp.Identity.Web/Localization/Resources/AbpIdentity/tr.json

@ -6,6 +6,9 @@
"NewUser": "Yeni kullanıcı",
"UserName": "Kullanıcı adı",
"EmailAddress": "E-posta adresi",
"DisplayName:IsDefault": "Varsayılan",
"DisplayName:IsStatic": "Sabit",
"DisplayName:IsPublic": "Herkese Açık",
"PhoneNumber": "Telefon numarası",
"UserInformations": "Kullanıcı bilgileri",
"Roles": "Roller",
@ -31,6 +34,8 @@
"DisplayName:NewPassword": "Yeni şifre",
"DisplayName:NewPasswordConfirm": "Yeni şifre (tekrar)",
"PasswordChangedMessage": "Şifreniz başarıyla değiştirildi.",
"PersonalSettingsSavedMessage": "Kişisel bilgileriniz başarıyla kaydedildi."
"PersonalSettingsSavedMessage": "Kişisel bilgileriniz başarıyla kaydedildi.",
"Identity.StaticRoleRenamingErrorMessage": "Bir Sabit rolün ismi değiştirilemez.",
"Identity.StaticRoleDeletionErrorMessage": "Bir Sabit rol silinemez."
}
}

8
modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/CreateModal.cshtml

@ -7,12 +7,14 @@
@{
Layout = null;
}
<abp-dynamic-form abp-model="@Model.Role" asp-page="/Identity/Roles/CreateModal">
<form asp-page="/Identity/Roles/CreateModal">
<abp-modal>
<abp-modal-header title="@L["NewRole"].Value"></abp-modal-header>
<abp-modal-body>
<abp-form-content />
<abp-input asp-for="Role.Name" />
<abp-input asp-for="Role.IsDefault" />
<abp-input asp-for="Role.IsPublic" />
</abp-modal-body>
<abp-modal-footer buttons="@(AbpModalButtons.Cancel|AbpModalButtons.Save)"></abp-modal-footer>
</abp-modal>
</abp-dynamic-form>
</form>

6
modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/CreateModal.cshtml.cs

@ -33,6 +33,12 @@ namespace Volo.Abp.Identity.Web.Pages.Identity.Roles
[StringLength(IdentityRoleConsts.MaxNameLength)]
[Display(Name = "DisplayName:RoleName")]
public string Name { get; set; }
[Display(Name = "DisplayName:IsDefault")]
public bool IsDefault { get; set; }
[Display(Name = "DisplayName:IsPublic")]
public bool IsPublic { get; set; }
}
}
}

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

@ -7,12 +7,22 @@
@{
Layout = null;
}
<abp-dynamic-form abp-model="@Model.Role" asp-page="/Identity/Roles/EditModal">
<form asp-page="/Identity/Roles/EditModal">
<abp-modal>
<abp-modal-header title="@L["Edit"].Value"></abp-modal-header>
<abp-modal-body>
<abp-form-content/>
<abp-input asp-for="Role.Id" />
@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>
<abp-modal-footer buttons="@(AbpModalButtons.Cancel|AbpModalButtons.Save)"></abp-modal-footer>
</abp-modal>
</abp-dynamic-form>
</form>

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

@ -44,6 +44,14 @@ namespace Volo.Abp.Identity.Web.Pages.Identity.Roles
[StringLength(IdentityRoleConsts.MaxNameLength)]
[Display(Name = "DisplayName:RoleName")]
public string Name { get; set; }
[Display(Name = "DisplayName:IsDefault")]
public bool IsDefault { get; set; }
public bool IsStatic { get; set; }
[Display(Name = "DisplayName:IsPublic")]
public bool IsPublic { get; set; }
}
}
}

4
modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/index.js

@ -45,8 +45,8 @@
},
{
text: l('Delete'),
visible: function () {
return true; //TODO: Check permission
visible: function (data) {
return !data.isStatic; //TODO: Check permission
},
confirmMessage: function (data) { return l('RoleDeletionConfirmationMessage', data.record.name)},
action: function (data) {

13
modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/CreateModal.cshtml.cs

@ -28,9 +28,14 @@ namespace Volo.Abp.Identity.Web.Pages.Identity.Users
{
UserInfo = new UserInfoViewModel();
Roles = ObjectMapper.Map<List<IdentityRoleDto>, AssignedRoleViewModel[]>(
await _identityRoleAppService.GetAllListAsync()
);
var roleDtoList = await _identityRoleAppService.GetAllListAsync();
Roles = ObjectMapper.Map<List<IdentityRoleDto>, AssignedRoleViewModel[]>(roleDtoList);
foreach (var role in Roles)
{
role.IsAssigned = role.IsDefault;
}
}
public async Task<NoContentResult> OnPostAsync()
@ -82,6 +87,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