committed by
GitHub
19 changed files with 196 additions and 40 deletions
@ -0,0 +1,2 @@ |
|||
nodeSelector: |
|||
agentpool: demopool |
|||
@ -0,0 +1,2 @@ |
|||
nodeSelector: |
|||
agentpool: demopool |
|||
@ -0,0 +1,2 @@ |
|||
nodeSelector: |
|||
agentpool: demopool |
|||
@ -0,0 +1,2 @@ |
|||
nodeSelector: |
|||
agentpool: demopool |
|||
@ -0,0 +1,29 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Entities.Events.Distributed; |
|||
using Volo.Abp.EventBus.Distributed; |
|||
using Volo.Abp.Identity; |
|||
using Volo.Abp.PermissionManagement; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace EShopOnAbp.AdministrationService.Handlers; |
|||
|
|||
public class CustomerRoleCreationHandler : IDistributedEventHandler<EntityCreatedEto<IdentityRoleEto>>, |
|||
ITransientDependency |
|||
{ |
|||
private readonly IPermissionManager _permissionManager; |
|||
protected const string CustomerRole = "customer"; |
|||
protected const string OrderPermission = "OrderingService.Orders"; |
|||
|
|||
public CustomerRoleCreationHandler(IPermissionManager permissionManager) |
|||
{ |
|||
_permissionManager = permissionManager; |
|||
} |
|||
|
|||
[UnitOfWork] |
|||
public virtual async Task HandleEventAsync(EntityCreatedEto<IdentityRoleEto> eventData) |
|||
{ |
|||
// Assign initial permissions for the customer role
|
|||
await _permissionManager.SetForRoleAsync(CustomerRole, OrderPermission, true); |
|||
} |
|||
} |
|||
@ -0,0 +1,51 @@ |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Identity; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Guids; |
|||
using Volo.Abp.Identity; |
|||
using IdentityRole = Volo.Abp.Identity.IdentityRole; |
|||
|
|||
namespace EShopOnAbp.IdentityService.DbMigrations; |
|||
|
|||
public class IdentityPublicRoleDataSeeder : IDataSeedContributor, ITransientDependency |
|||
{ |
|||
private readonly IIdentityRoleRepository _roleRepository; |
|||
private readonly ILookupNormalizer _lookupNormalizer; |
|||
private readonly IGuidGenerator _guidGenerator; |
|||
private readonly IdentityRoleManager _roleManager; |
|||
|
|||
public IdentityPublicRoleDataSeeder( |
|||
IIdentityRoleRepository roleRepository, |
|||
ILookupNormalizer lookupNormalizer, |
|||
IGuidGenerator guidGenerator, |
|||
IdentityRoleManager roleManager) |
|||
{ |
|||
_roleRepository = roleRepository; |
|||
_lookupNormalizer = lookupNormalizer; |
|||
_guidGenerator = guidGenerator; |
|||
_roleManager = roleManager; |
|||
} |
|||
|
|||
public async Task SeedAsync(DataSeedContext context) |
|||
{ |
|||
await CreateCustomerRoleAsync(); |
|||
} |
|||
|
|||
private async Task CreateCustomerRoleAsync() |
|||
{ |
|||
//"customer" role
|
|||
var customerRole = |
|||
await _roleRepository.FindByNormalizedNameAsync(_lookupNormalizer.NormalizeName(IdentityServiceDbProperties.CustomerRoleName)); |
|||
if (customerRole == null) |
|||
{ |
|||
customerRole = new IdentityRole(_guidGenerator.Create(), IdentityServiceDbProperties.CustomerRoleName) |
|||
{ |
|||
IsStatic = true, |
|||
IsPublic = true |
|||
}; |
|||
|
|||
(await _roleManager.CreateAsync(customerRole)).CheckErrors(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Entities.Events.Distributed; |
|||
using Volo.Abp.EventBus.Distributed; |
|||
using Volo.Abp.Identity; |
|||
using Volo.Abp.Uow; |
|||
using Volo.Abp.Users; |
|||
|
|||
namespace EShopOnAbp.IdentityService.Handlers; |
|||
|
|||
public class IdentityUserCreationHandler : IDistributedEventHandler<EntityCreatedEto<UserEto>>, ITransientDependency |
|||
{ |
|||
private readonly IdentityUserManager _identityUserManager; |
|||
|
|||
public IdentityUserCreationHandler(IdentityUserManager identityUserManager) |
|||
{ |
|||
_identityUserManager = identityUserManager; |
|||
} |
|||
|
|||
[UnitOfWork] |
|||
public virtual async Task HandleEventAsync(EntityCreatedEto<UserEto> eventData) |
|||
{ |
|||
if (eventData.Entity.Email != IdentityServiceDbProperties.DefaultAdminEmailAddress) |
|||
{ |
|||
var identityUser = await _identityUserManager.FindByIdAsync(eventData.Entity.Id.ToString()); |
|||
await _identityUserManager.AddToRoleAsync(identityUser, IdentityServiceDbProperties.CustomerRoleName); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue