|
|
|
@ -7,37 +7,39 @@ using Volo.Abp.Identity;
|
|
|
|
|
|
|
|
|
|
namespace Volo.Abp.PermissionManagement.Identity
|
|
|
|
|
{
|
|
|
|
|
public class RoleUpdateEventHandler :
|
|
|
|
|
ILocalEventHandler<IdentityRoleNameChangedEvent>,
|
|
|
|
|
ITransientDependency
|
|
|
|
|
{
|
|
|
|
|
protected IIdentityRoleRepository RoleRepository { get; }
|
|
|
|
|
protected IPermissionManager PermissionManager { get; }
|
|
|
|
|
protected IPermissionGrantRepository PermissionGrantRepository { get; }
|
|
|
|
|
//TODO: This code can not be here!
|
|
|
|
|
|
|
|
|
|
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 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);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|