mirror of https://github.com/abpframework/abp.git
6 changed files with 76 additions and 54 deletions
@ -0,0 +1,16 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.Identity |
|||
{ |
|||
[Serializable] |
|||
public class IdentityRoleNameChangedEto |
|||
{ |
|||
public Guid Id { get; set; } |
|||
|
|||
public Guid? TenantId { get; set; } |
|||
|
|||
public string Name { get; set; } |
|||
|
|||
public string OldName { get; set; } |
|||
} |
|||
} |
|||
@ -1,26 +1,26 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Authorization.Permissions; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Entities.Events; |
|||
using Volo.Abp.Domain.Entities.Events.Distributed; |
|||
using Volo.Abp.EventBus; |
|||
using Volo.Abp.Identity; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.Identity |
|||
{ |
|||
// public class RoleDeletedEventHandler :
|
|||
// ILocalEventHandler<EntityDeletedEventData<IdentityRole>>,
|
|||
// ITransientDependency
|
|||
// {
|
|||
// protected IPermissionManager PermissionManager { get; }
|
|||
//
|
|||
// public RoleDeletedEventHandler(IPermissionManager permissionManager)
|
|||
// {
|
|||
// PermissionManager = permissionManager;
|
|||
// }
|
|||
//
|
|||
// public virtual async Task HandleEventAsync(EntityDeletedEventData<IdentityRole> eventData)
|
|||
// {
|
|||
// await PermissionManager.DeleteAsync(RolePermissionValueProvider.ProviderName, eventData.Entity.Name);
|
|||
// }
|
|||
// }
|
|||
public class RoleDeletedEventHandler : |
|||
ILocalEventHandler<EntityDeletedEto<IdentityRoleEto>>, |
|||
ITransientDependency |
|||
{ |
|||
protected IPermissionManager PermissionManager { get; } |
|||
|
|||
public RoleDeletedEventHandler(IPermissionManager permissionManager) |
|||
{ |
|||
PermissionManager = permissionManager; |
|||
} |
|||
|
|||
public async Task HandleEventAsync(EntityDeletedEto<IdentityRoleEto> eventData) |
|||
{ |
|||
await PermissionManager.DeleteAsync(RolePermissionValueProvider.ProviderName, eventData.Entity.Name); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,45 +1,33 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Authorization.Permissions; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Entities.Events; |
|||
using Volo.Abp.EventBus; |
|||
using Volo.Abp.EventBus.Distributed; |
|||
using Volo.Abp.Identity; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.Identity |
|||
{ |
|||
//TODO: This code can not be here!
|
|||
public class RoleUpdateEventHandler : |
|||
IDistributedEventHandler<IdentityRoleNameChangedEto>, |
|||
ITransientDependency |
|||
{ |
|||
protected IPermissionManager PermissionManager { get; } |
|||
protected IPermissionGrantRepository PermissionGrantRepository { get; } |
|||
|
|||
public RoleUpdateEventHandler( |
|||
IPermissionManager permissionManager, |
|||
IPermissionGrantRepository permissionGrantRepository) |
|||
{ |
|||
PermissionManager = permissionManager; |
|||
PermissionGrantRepository = permissionGrantRepository; |
|||
} |
|||
|
|||
// public class RoleUpdateEventHandler :
|
|||
// ILocalEventHandler<IdentityRoleNameChangedEvent>,
|
|||
// ITransientDependency
|
|||
// {
|
|||
// protected IIdentityRoleRepository RoleRepository { get; }
|
|||
// protected IPermissionManager PermissionManager { get; }
|
|||
// protected IPermissionGrantRepository PermissionGrantRepository { get; }
|
|||
//
|
|||
// public RoleUpdateEventHandler(
|
|||
// IIdentityRoleRepository roleRepository,
|
|||
// IPermissionManager permissionManager,
|
|||
// IPermissionGrantRepository permissionGrantRepository)
|
|||
// {
|
|||
// RoleRepository = roleRepository;
|
|||
// PermissionManager = permissionManager;
|
|||
// PermissionGrantRepository = permissionGrantRepository;
|
|||
// }
|
|||
//
|
|||
// public virtual async Task HandleEventAsync(IdentityRoleNameChangedEvent eventData)
|
|||
// {
|
|||
// var role = await RoleRepository.FindAsync(eventData.IdentityRole.Id, false);
|
|||
// if (role == null)
|
|||
// {
|
|||
// return;
|
|||
// }
|
|||
//
|
|||
// var permissionGrantsInRole = await PermissionGrantRepository.GetListAsync(RolePermissionValueProvider.ProviderName, eventData.OldName);
|
|||
// foreach (var permissionGrant in permissionGrantsInRole)
|
|||
// {
|
|||
// await PermissionManager.UpdateProviderKeyAsync(permissionGrant, eventData.IdentityRole.Name);
|
|||
// }
|
|||
// }
|
|||
// }
|
|||
public async Task HandleEventAsync(IdentityRoleNameChangedEto eventData) |
|||
{ |
|||
var permissionGrantsInRole = await PermissionGrantRepository.GetListAsync(RolePermissionValueProvider.ProviderName, eventData.OldName); |
|||
foreach (var permissionGrant in permissionGrantsInRole) |
|||
{ |
|||
await PermissionManager.UpdateProviderKeyAsync(permissionGrant, eventData.Name); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
Loading…
Reference in new issue