Browse Source

Resolved Prevent deleting the current user #889

pull/897/head
Yunus Emre Kalkan 7 years ago
parent
commit
cfd2d984dd
  1. 6
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/AbpIdentityApplicationContractsModule.cs
  2. 11
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityErrorCodes.cs
  3. 1
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/Localization/ApplicationContracts/en.json
  4. 1
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/Localization/ApplicationContracts/tr.json
  5. 5
      modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs

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

@ -7,6 +7,7 @@ using Volo.Abp.Modularity;
using Volo.Abp.PermissionManagement;
using Volo.Abp.Users;
using Volo.Abp.VirtualFileSystem;
using Volo.Abp.Localization.ExceptionHandling;
namespace Volo.Abp.Identity
{
@ -32,6 +33,11 @@ namespace Volo.Abp.Identity
.Get<IdentityResource>()
.AddVirtualJson("/Volo/Abp/Identity/Localization/ApplicationContracts");
});
Configure<ExceptionLocalizationOptions>(options =>
{
options.MapCodeNamespace("Volo.Abp.Identity", typeof(IdentityResource));
});
}
}
}

11
modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityErrorCodes.cs

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Volo.Abp.Identity
{
public static class IdentityErrorCodes
{
public const string UserSelfDeletion = "Volo.Abp.Identity:010001";
}
}

1
modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/Localization/ApplicationContracts/en.json

@ -1,6 +1,7 @@
{
"culture": "en",
"texts": {
"Volo.Abp.Identity:010001": "You can not delete your own account!",
"Permission:IdentityManagement": "Identity management",
"Permission:RoleManagement": "Role management",
"Permission:Create": "Create",

1
modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/Localization/ApplicationContracts/tr.json

@ -1,6 +1,7 @@
{
"culture": "tr",
"texts": {
"Volo.Abp.Identity:010001": "Kendi hesabınızı silemezsiniz!",
"Permission:IdentityManagement": "Kimlik yönetimi",
"Permission:RoleManagement": "Rol yönetimi",
"Permission:Create": "Oluşturma",

5
modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs

@ -80,6 +80,11 @@ namespace Volo.Abp.Identity
[Authorize(IdentityPermissions.Users.Delete)]
public async Task DeleteAsync(Guid id)
{
if (CurrentUser.Id.Value == id)
{
throw new BusinessException(code: IdentityErrorCodes.UserSelfDeletion);
}
var user = await _userManager.FindByIdAsync(id.ToString());
if (user == null)
{

Loading…
Cancel
Save