feat: 增加角色对应用授权功能
This commit is contained in:
parent
570775ad1b
commit
77f1f2e0d9
|
@ -1,9 +1,15 @@
|
||||||
using BootstrapAdmin.Web.Core;
|
using BootstrapAdmin.Web.Core;
|
||||||
|
using BootstrapBlazor.Components;
|
||||||
|
|
||||||
namespace BootstrapAdmin.DataAccess.EFCore.Services
|
namespace BootstrapAdmin.DataAccess.EFCore.Services
|
||||||
{
|
{
|
||||||
class DictsService : IDict
|
class DictsService : IDict
|
||||||
{
|
{
|
||||||
|
public List<SelectedItem> GetApps()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
public string GetWebFooter()
|
public string GetWebFooter()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
|
|
|
@ -40,6 +40,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||||
services.AddSingleton<ILogin, LoginService>();
|
services.AddSingleton<ILogin, LoginService>();
|
||||||
services.AddSingleton<IRole, RoleService>();
|
services.AddSingleton<IRole, RoleService>();
|
||||||
services.AddSingleton<IGroup, GroupService>();
|
services.AddSingleton<IGroup, GroupService>();
|
||||||
|
services.AddSingleton<IApp, AppService>();
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
using BootstrapAdmin.DataAccess.Models;
|
||||||
|
using BootstrapAdmin.Web.Core;
|
||||||
|
using BootstrapBlazor.Components;
|
||||||
|
using PetaPoco;
|
||||||
|
|
||||||
|
namespace BootstrapAdmin.DataAccess.PetaPoco.Services;
|
||||||
|
|
||||||
|
class AppService : BaseDatabase, IApp
|
||||||
|
{
|
||||||
|
private List<SelectedItem> Apps { get; set; }
|
||||||
|
|
||||||
|
public AppService(IDatabase db, IDict dict)
|
||||||
|
{
|
||||||
|
Database = db;
|
||||||
|
Apps = dict.GetApps();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<SelectedItem> GetAll() => Apps;
|
||||||
|
|
||||||
|
public List<string> GetAppsByRoleId(string? roleId) => Database.Fetch<string>("select AppID from RoleApp where RoleID = @0", roleId);
|
||||||
|
|
||||||
|
public bool SaveAppsByRoleId(string? roleId, IEnumerable<string> appIds)
|
||||||
|
{
|
||||||
|
var ret = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Database.BeginTransaction();
|
||||||
|
Database.Execute("delete from RoleApp where RoleID = @0", roleId);
|
||||||
|
Database.InsertBatch("RoleApp", appIds.Select(g => new { AppID = g, RoleID = roleId }));
|
||||||
|
Database.CompleteTransaction();
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
Database.AbortTransaction();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,59 +1,65 @@
|
||||||
using BootstrapAdmin.DataAccess.Models;
|
using BootstrapAdmin.DataAccess.Models;
|
||||||
using BootstrapAdmin.Web.Core;
|
using BootstrapAdmin.Web.Core;
|
||||||
|
using BootstrapBlazor.Components;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using PetaPoco;
|
using PetaPoco;
|
||||||
|
|
||||||
namespace BootstrapAdmin.DataAccess.PetaPoco.Services
|
namespace BootstrapAdmin.DataAccess.PetaPoco.Services;
|
||||||
|
|
||||||
|
class DictService : BaseDatabase, IDict
|
||||||
{
|
{
|
||||||
class DictService : BaseDatabase, IDict
|
private string AppId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="db"></param>
|
||||||
|
/// <param name="configuration"></param>
|
||||||
|
public DictService(IDatabase db, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
private string AppId { get; set; }
|
Database = db;
|
||||||
|
AppId = configuration.GetValue("AppId", "BA");
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
private List<Dict> GetAll() => Database.Fetch<Dict>();
|
||||||
///
|
|
||||||
/// </summary>
|
public List<SelectedItem> GetApps()
|
||||||
/// <param name="db"></param>
|
{
|
||||||
/// <param name="configuration"></param>
|
var dicts = GetAll();
|
||||||
public DictService(IDatabase db, IConfiguration configuration)
|
return dicts.Where(d => d.Category == "应用程序").Select(d => new SelectedItem(d.Code, d.Name)).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取 站点 Title 配置信息
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public string GetWebTitle()
|
||||||
|
{
|
||||||
|
var dicts = GetAll();
|
||||||
|
var title = "网站标题";
|
||||||
|
var name = dicts.FirstOrDefault(d => d.Category == "应用程序" && d.Code == AppId)?.Name;
|
||||||
|
if (!string.IsNullOrEmpty(name))
|
||||||
{
|
{
|
||||||
Database = db;
|
var dict = dicts.FirstOrDefault(d => d.Category == name && d.Name == "网站标题") ?? dicts.FirstOrDefault(d => d.Category == "网站设置" && d.Name == "网站标题");
|
||||||
AppId = configuration.GetValue("AppId", "BA");
|
title = dict?.Code ?? "网站标题";
|
||||||
}
|
}
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
private List<Dict> GetAll() => Database.Fetch<Dict>();
|
/// <summary>
|
||||||
|
/// 获取站点 Footer 配置信息
|
||||||
/// <summary>
|
/// </summary>
|
||||||
/// 获取 站点 Title 配置信息
|
/// <returns></returns>
|
||||||
/// </summary>
|
public string GetWebFooter()
|
||||||
/// <returns></returns>
|
{
|
||||||
public string GetWebTitle()
|
var dicts = GetAll();
|
||||||
|
var title = "网站页脚";
|
||||||
|
var name = dicts.FirstOrDefault(d => d.Category == "应用程序" && d.Code == AppId)?.Name;
|
||||||
|
if (!string.IsNullOrEmpty(name))
|
||||||
{
|
{
|
||||||
var dicts = GetAll();
|
var dict = dicts.FirstOrDefault(d => d.Category == name && d.Name == "网站页脚") ?? dicts.FirstOrDefault(d => d.Category == "网站设置" && d.Name == "网站页脚");
|
||||||
var title = "网站标题";
|
title = dict?.Code ?? "网站标题";
|
||||||
var name = dicts.FirstOrDefault(d => d.Category == "应用程序" && d.Code == AppId)?.Name;
|
|
||||||
if (!string.IsNullOrEmpty(name))
|
|
||||||
{
|
|
||||||
var dict = dicts.FirstOrDefault(d => d.Category == name && d.Name == "网站标题") ?? dicts.FirstOrDefault(d => d.Category == "网站设置" && d.Name == "网站标题");
|
|
||||||
title = dict?.Code ?? "网站标题";
|
|
||||||
}
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取站点 Footer 配置信息
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public string GetWebFooter()
|
|
||||||
{
|
|
||||||
var dicts = GetAll();
|
|
||||||
var title = "网站页脚";
|
|
||||||
var name = dicts.FirstOrDefault(d => d.Category == "应用程序" && d.Code == AppId)?.Name;
|
|
||||||
if (!string.IsNullOrEmpty(name))
|
|
||||||
{
|
|
||||||
var dict = dicts.FirstOrDefault(d => d.Category == name && d.Name == "网站页脚") ?? dicts.FirstOrDefault(d => d.Category == "网站设置" && d.Name == "网站页脚");
|
|
||||||
title = dict?.Code ?? "网站标题";
|
|
||||||
}
|
|
||||||
return title;
|
|
||||||
}
|
}
|
||||||
|
return title;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ class GroupService : BaseDatabase, IGroup
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="roleId"></param>
|
/// <param name="roleId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public List<string> GetGroupsByRoleId(string? roleId) => Database.Fetch<string>("select GroupID from RoleGroup where RoleGroup = @0", roleId);
|
public List<string> GetGroupsByRoleId(string? roleId) => Database.Fetch<string>("select GroupID from RoleGroup where RoleID = @0", roleId);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
|
@ -69,7 +69,7 @@ class GroupService : BaseDatabase, IGroup
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Database.BeginTransaction();
|
Database.BeginTransaction();
|
||||||
Database.Execute("delete from RoleGroup where RoleGroup = @0", roleId);
|
Database.Execute("delete from RoleGroup where RoleID = @0", roleId);
|
||||||
Database.InsertBatch("RoleGroup", groupIds.Select(g => new { GroupID = g, RoleID = roleId }));
|
Database.InsertBatch("RoleGroup", groupIds.Select(g => new { GroupID = g, RoleID = roleId }));
|
||||||
Database.CompleteTransaction();
|
Database.CompleteTransaction();
|
||||||
ret = true;
|
ret = true;
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
using BootstrapBlazor.Components;
|
||||||
|
|
||||||
|
namespace BootstrapAdmin.Web.Core;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public interface IApp
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 获得所有用户
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
List<SelectedItem> GetAll();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
List<string> GetAppsByRoleId(string? roleId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleId"></param>
|
||||||
|
/// <param name="appIds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
bool SaveAppsByRoleId(string? roleId, IEnumerable<string> appIds);
|
||||||
|
}
|
|
@ -1,10 +1,14 @@
|
||||||
namespace BootstrapAdmin.Web.Core
|
using BootstrapBlazor.Components;
|
||||||
|
|
||||||
|
namespace BootstrapAdmin.Web.Core
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Dict 字典表接口
|
/// Dict 字典表接口
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IDict
|
public interface IDict
|
||||||
{
|
{
|
||||||
|
List<SelectedItem> GetApps();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取 站点 Title 配置信息
|
/// 获取 站点 Title 配置信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -7,7 +7,6 @@ namespace BootstrapAdmin.Web.Core;
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IGroup
|
public interface IGroup
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获得所有用户
|
/// 获得所有用户
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -22,12 +22,16 @@ public partial class Roles
|
||||||
[NotNull]
|
[NotNull]
|
||||||
private IUser? UserService { get; set; }
|
private IUser? UserService { get; set; }
|
||||||
|
|
||||||
|
[Inject]
|
||||||
|
[NotNull]
|
||||||
|
private IApp? AppService { get; set; }
|
||||||
|
|
||||||
private async Task OnAssignmentUsers(Role role)
|
private async Task OnAssignmentUsers(Role role)
|
||||||
{
|
{
|
||||||
var users = UserService.GetAll().ToSelectedItemList();
|
var users = UserService.GetAll().ToSelectedItemList();
|
||||||
var values = UserService.GetUsersByRoleId(role.Id);
|
var values = UserService.GetUsersByRoleId(role.Id);
|
||||||
|
|
||||||
await DialogService.ShowAssignmentDialog($"分配部门 - {role.RoleName}", users, values, () =>
|
await DialogService.ShowAssignmentDialog($"分配用户 - {role.RoleName}", users, values, () =>
|
||||||
{
|
{
|
||||||
var ret = UserService.SaveUsersByRoleId(role.Id, values);
|
var ret = UserService.SaveUsersByRoleId(role.Id, values);
|
||||||
return Task.FromResult(ret);
|
return Task.FromResult(ret);
|
||||||
|
@ -58,12 +62,13 @@ public partial class Roles
|
||||||
|
|
||||||
private async Task OnAssignmentApps(Role role)
|
private async Task OnAssignmentApps(Role role)
|
||||||
{
|
{
|
||||||
var option = new DialogOption()
|
var apps = AppService.GetAll();
|
||||||
|
var values = AppService.GetAppsByRoleId(role.Id);
|
||||||
|
|
||||||
|
await DialogService.ShowAssignmentDialog($"分配应用 - {role.RoleName}", apps, values, () =>
|
||||||
{
|
{
|
||||||
Title = $"分配应用 - {role}",
|
var ret = AppService.SaveAppsByRoleId(role.Id, values);
|
||||||
};
|
return Task.FromResult(ret);
|
||||||
|
}, ToastService);
|
||||||
await DialogService.Show(option);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue