Files
Yi.Framework/Yi.Abp.Net8/test/Yi.Framework.Rbac.Test/YiFrameworkRbacTestModule.cs
2024-04-29 17:50:51 +08:00

58 lines
2.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Auditing;
using Volo.Abp.Autofac;
using Volo.Abp.BackgroundWorkers;
using Volo.Abp.BackgroundWorkers.Quartz;
using Volo.Abp.Domain.Repositories;
using Yi.Framework.Rbac.Application;
using Yi.Framework.Rbac.Domain.Entities;
using Yi.Framework.Rbac.Domain.Managers;
using Yi.Framework.Rbac.Domain.Shared.Consts;
using Yi.Framework.Rbac.SqlSugarCore;
using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.Rbac.Test
{
[DependsOn(
typeof(YiFrameworkRbacApplicationModule),
typeof(YiFrameworkRbacSqlSugarCoreModule),
typeof(AbpAutofacModule),
typeof(AbpAuditingModule)
)]
public class YiFrameworkRbacTestModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpBackgroundWorkerQuartzOptions>(options =>
{
options.IsAutoRegisterEnabled = false;
});
Configure<AbpBackgroundWorkerOptions> (options =>
{
options.IsEnabled = false; //禁用作业执行
});
Configure<DbConnOptions>(options =>
{
options.Url = $"DataSource=yi-rbac-test-{DateTime.Now.ToString("yyyyMMdd_HHmmss")}.db";
});
}
public override async Task OnPostApplicationInitializationAsync(ApplicationInitializationContext context)
{
var services = context.ServiceProvider;
#region
var roleManager = services.GetRequiredService<RoleManager>();
var roleRep = services.GetRequiredService<ISqlSugarRepository<RoleEntity>>();
var menuRep = services.GetRequiredService<ISqlSugarRepository<MenuEntity>>();
var defaultRoleEntity = await roleRep._DbQueryable.Where(x => x.RoleCode == UserConst.DefaultRoleCode).FirstAsync();
var menuIds = await menuRep._DbQueryable.Where(x => x.PermissionCode.Contains("user")).Select(x => x.Id).ToListAsync();
await roleManager.GiveRoleSetMenuAsync(new List<Guid> { defaultRoleEntity.Id }, menuIds);
#endregion
}
}
}