feat: 增加角色对用户授权功能
This commit is contained in:
parent
f2095cac40
commit
570775ad1b
|
@ -2,84 +2,83 @@
|
||||||
using BootstrapAdmin.Web.Core;
|
using BootstrapAdmin.Web.Core;
|
||||||
using PetaPoco;
|
using PetaPoco;
|
||||||
|
|
||||||
namespace BootstrapAdmin.DataAccess.PetaPoco.Services
|
namespace BootstrapAdmin.DataAccess.PetaPoco.Services;
|
||||||
|
|
||||||
|
class GroupService : BaseDatabase, IGroup
|
||||||
{
|
{
|
||||||
class GroupService : BaseDatabase, IGroup
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="db"></param>
|
||||||
|
public GroupService(IDatabase db) => Database = db;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public List<Group> GetAll() => Database.Fetch<Group>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public List<string> GetGroupsByUserId(string? userId) => Database.Fetch<string>("select GroupID from UserGroup where UserID = @0", userId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userId"></param>
|
||||||
|
/// <param name="groupIds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool SaveGroupsByUserId(string? userId, IEnumerable<string> groupIds)
|
||||||
{
|
{
|
||||||
/// <summary>
|
var ret = false;
|
||||||
///
|
try
|
||||||
/// </summary>
|
|
||||||
/// <param name="db"></param>
|
|
||||||
public GroupService(IDatabase db) => Database = db;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public List<Group> GetAll() => Database.Fetch<Group>();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="userId"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public List<string> GetGroupsByUserId(string? userId) => Database.Fetch<string>("select GroupID from UserGroup where UserID = @0", userId);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="userId"></param>
|
|
||||||
/// <param name="groupIds"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public bool SaveGroupsByUserId(string? userId, IEnumerable<string> groupIds)
|
|
||||||
{
|
{
|
||||||
var ret = false;
|
Database.BeginTransaction();
|
||||||
try
|
Database.Execute("delete from UserGroup where UserID = @0", userId);
|
||||||
{
|
Database.InsertBatch("UserGroup", groupIds.Select(g => new { GroupID = g, UserID = userId }));
|
||||||
Database.BeginTransaction();
|
Database.CompleteTransaction();
|
||||||
Database.Execute("delete from UserGroup where UserID = @0", userId);
|
ret = true;
|
||||||
Database.InsertBatch("UserGroup", groupIds.Select(g => new { GroupID = g, UserID = userId }));
|
|
||||||
Database.CompleteTransaction();
|
|
||||||
ret = true;
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
Database.AbortTransaction();
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
catch (Exception)
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="roleId"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public List<string> GetGroupsByRoleId(string? roleId) => Database.Fetch<string>("select GroupID from RoleGroup where RoleGroup = @0", roleId);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="roleId"></param>
|
|
||||||
/// <param name="groupIds"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public bool SaveGroupsByRoleId(string? roleId, IEnumerable<string> groupIds)
|
|
||||||
{
|
{
|
||||||
var ret = false;
|
Database.AbortTransaction();
|
||||||
try
|
throw;
|
||||||
{
|
|
||||||
Database.BeginTransaction();
|
|
||||||
Database.Execute("delete from RoleGroup where RoleGroup = @0", roleId);
|
|
||||||
Database.InsertBatch("RoleGroup", groupIds.Select(g => new { GroupID = g, RoleID = roleId }));
|
|
||||||
Database.CompleteTransaction();
|
|
||||||
ret = true;
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
Database.AbortTransaction();
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public List<string> GetGroupsByRoleId(string? roleId) => Database.Fetch<string>("select GroupID from RoleGroup where RoleGroup = @0", roleId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleId"></param>
|
||||||
|
/// <param name="groupIds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool SaveGroupsByRoleId(string? roleId, IEnumerable<string> groupIds)
|
||||||
|
{
|
||||||
|
var ret = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Database.BeginTransaction();
|
||||||
|
Database.Execute("delete from RoleGroup where RoleGroup = @0", roleId);
|
||||||
|
Database.InsertBatch("RoleGroup", groupIds.Select(g => new { GroupID = g, RoleID = roleId }));
|
||||||
|
Database.CompleteTransaction();
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
Database.AbortTransaction();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,96 +3,127 @@ using BootstrapAdmin.Web.Core;
|
||||||
using Longbow.Security.Cryptography;
|
using Longbow.Security.Cryptography;
|
||||||
using PetaPoco;
|
using PetaPoco;
|
||||||
|
|
||||||
namespace BootstrapAdmin.DataAccess.PetaPoco.Services
|
namespace BootstrapAdmin.DataAccess.PetaPoco.Services;
|
||||||
|
|
||||||
|
class UserService : BaseDatabase, IUser
|
||||||
{
|
{
|
||||||
class UserService : BaseDatabase, IUser
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="db"></param>
|
||||||
|
public UserService(IDatabase db) => Database = db;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public List<User> GetAll() => Database.Fetch<User>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <param name="password"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
|
public bool Authenticate(string userName, string password)
|
||||||
{
|
{
|
||||||
/// <summary>
|
var user = Database.SingleOrDefault<User>("select DisplayName, Password, PassSalt from Users where ApprovedTime is not null and UserName = @0", userName);
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="db"></param>
|
|
||||||
public UserService(IDatabase db) => Database = db;
|
|
||||||
|
|
||||||
/// <summary>
|
var isAuth = false;
|
||||||
///
|
if (user != null && !string.IsNullOrEmpty(user.PassSalt))
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public List<User> GetAll() => Database.Fetch<User>();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="userName"></param>
|
|
||||||
/// <param name="password"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
/// <exception cref="NotImplementedException"></exception>
|
|
||||||
public bool Authenticate(string userName, string password)
|
|
||||||
{
|
{
|
||||||
var user = Database.SingleOrDefault<User>("select DisplayName, Password, PassSalt from Users where ApprovedTime is not null and UserName = @0", userName);
|
isAuth = user.Password == LgbCryptography.ComputeHash(password, user.PassSalt);
|
||||||
|
|
||||||
var isAuth = false;
|
|
||||||
if (user != null && !string.IsNullOrEmpty(user.PassSalt))
|
|
||||||
{
|
|
||||||
isAuth = user.Password == LgbCryptography.ComputeHash(password, user.PassSalt);
|
|
||||||
}
|
|
||||||
return isAuth;
|
|
||||||
}
|
}
|
||||||
|
return isAuth;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userName"></param>
|
/// <param name="userName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string? GetDisplayName(string? userName) => string.IsNullOrEmpty(userName) ? "" : Database.ExecuteScalar<string>("select DisplayName from Users where UserName = @0", userName);
|
public string? GetDisplayName(string? userName) => string.IsNullOrEmpty(userName) ? "" : Database.ExecuteScalar<string>("select DisplayName from Users where UserName = @0", userName);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userName"></param>
|
/// <param name="userName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="NotImplementedException"></exception>
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
public List<string> GetApps(string userName) => Database.Fetch<string>($"select d.Code from Dicts d inner join RoleApp ra on d.Code = ra.AppId inner join (select r.Id from Roles r inner join UserRole ur on r.ID = ur.RoleID inner join Users u on ur.UserID = u.ID where u.UserName = @0 union select r.Id from Roles r inner join RoleGroup rg on r.ID = rg.RoleID inner join {Database.Provider.EscapeSqlIdentifier("Groups")} g on rg.GroupID = g.ID inner join UserGroup ug on ug.GroupID = g.ID inner join Users u on ug.UserID = u.ID where u.UserName = @0) r on ra.RoleId = r.ID union select Code from Dicts where Category = @1 and exists(select r.ID from Roles r inner join UserRole ur on r.ID = ur.RoleID inner join Users u on ur.UserID = u.ID where u.UserName = @0 and r.RoleName = @2 union select r.ID from Roles r inner join RoleGroup rg on r.ID = rg.RoleID inner join {Database.Provider.EscapeSqlIdentifier("Groups")} g on rg.GroupID = g.ID inner join UserGroup ug on ug.GroupID = g.ID inner join Users u on ug.UserID = u.ID where u.UserName = @0 and r.RoleName = @2)", userName, "应用程序", "Administrators");
|
public List<string> GetApps(string userName) => Database.Fetch<string>($"select d.Code from Dicts d inner join RoleApp ra on d.Code = ra.AppId inner join (select r.Id from Roles r inner join UserRole ur on r.ID = ur.RoleID inner join Users u on ur.UserID = u.ID where u.UserName = @0 union select r.Id from Roles r inner join RoleGroup rg on r.ID = rg.RoleID inner join {Database.Provider.EscapeSqlIdentifier("Groups")} g on rg.GroupID = g.ID inner join UserGroup ug on ug.GroupID = g.ID inner join Users u on ug.UserID = u.ID where u.UserName = @0) r on ra.RoleId = r.ID union select Code from Dicts where Category = @1 and exists(select r.ID from Roles r inner join UserRole ur on r.ID = ur.RoleID inner join Users u on ur.UserID = u.ID where u.UserName = @0 and r.RoleName = @2 union select r.ID from Roles r inner join RoleGroup rg on r.ID = rg.RoleID inner join {Database.Provider.EscapeSqlIdentifier("Groups")} g on rg.GroupID = g.ID inner join UserGroup ug on ug.GroupID = g.ID inner join Users u on ug.UserID = u.ID where u.UserName = @0 and r.RoleName = @2)", userName, "应用程序", "Administrators");
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userName"></param>
|
/// <param name="userName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="NotImplementedException"></exception>
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
public List<string> GetRoles(string userName) => Database.Fetch<string>($"select r.RoleName from Roles r inner join UserRole ur on r.ID=ur.RoleID inner join Users u on ur.UserID = u.ID and u.UserName = @0 union select r.RoleName from Roles r inner join RoleGroup rg on r.ID = rg.RoleID inner join {Database.Provider.EscapeSqlIdentifier("Groups")} g on rg.GroupID = g.ID inner join UserGroup ug on ug.GroupID = g.ID inner join Users u on ug.UserID = u.ID and u.UserName=@0", userName);
|
public List<string> GetRoles(string userName) => Database.Fetch<string>($"select r.RoleName from Roles r inner join UserRole ur on r.ID=ur.RoleID inner join Users u on ur.UserID = u.ID and u.UserName = @0 union select r.RoleName from Roles r inner join RoleGroup rg on r.ID = rg.RoleID inner join {Database.Provider.EscapeSqlIdentifier("Groups")} g on rg.GroupID = g.ID inner join UserGroup ug on ug.GroupID = g.ID inner join Users u on ug.UserID = u.ID and u.UserName=@0", userName);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="NotImplementedException"></exception>
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
public List<string> GetUsersByGroupId(string? id) => Database.Fetch<string>("select UserID from UserGroup where GroupID = @0", id);
|
public List<string> GetUsersByGroupId(string? id) => Database.Fetch<string>("select UserID from UserGroup where GroupID = @0", id);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="userIds"></param>
|
/// <param name="userIds"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="NotImplementedException"></exception>
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
public bool SaveUsersByGroupId(string? id, IEnumerable<string> userIds)
|
public bool SaveUsersByGroupId(string? id, IEnumerable<string> userIds)
|
||||||
|
{
|
||||||
|
var ret = false;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var ret = false;
|
Database.BeginTransaction();
|
||||||
try
|
Database.Execute("delete from UserGroup where GroupId = @0", id);
|
||||||
{
|
Database.InsertBatch("UserGroup", userIds.Select(g => new { UserID = g, GroupID = id }));
|
||||||
Database.BeginTransaction();
|
Database.CompleteTransaction();
|
||||||
Database.Execute("delete from UserGroup where GroupId = @0", id);
|
ret = true;
|
||||||
Database.InsertBatch("UserGroup", userIds.Select(g => new { UserID = g, GroupID = id }));
|
|
||||||
Database.CompleteTransaction();
|
|
||||||
ret = true;
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
Database.AbortTransaction();
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
Database.AbortTransaction();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public List<string> GetUsersByRoleId(string? roleId) => Database.Fetch<string>("select UserID from UserRole where RoleID = @0", roleId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleId"></param>
|
||||||
|
/// <param name="userIds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool SaveUsersByRoleId(string? roleId, IEnumerable<string> userIds)
|
||||||
|
{
|
||||||
|
var ret = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Database.BeginTransaction();
|
||||||
|
Database.Execute("delete from UserRole where RoleID = @0", roleId);
|
||||||
|
Database.InsertBatch("UserRole", userIds.Select(g => new { UserID = g, RoleID = roleId }));
|
||||||
|
Database.CompleteTransaction();
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
Database.AbortTransaction();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,60 +1,74 @@
|
||||||
using BootstrapAdmin.DataAccess.Models;
|
using BootstrapAdmin.DataAccess.Models;
|
||||||
using BootstrapBlazor.Components;
|
|
||||||
|
|
||||||
namespace BootstrapAdmin.Web.Core
|
namespace BootstrapAdmin.Web.Core;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public interface IUser
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IUser
|
/// <param name="userName"></param>
|
||||||
{
|
/// <returns></returns>
|
||||||
/// <summary>
|
string? GetDisplayName(string? userName);
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="userName"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
string? GetDisplayName(string? userName);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 通过用户名获取角色列表
|
/// 通过用户名获取角色列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userName"></param>
|
/// <param name="userName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
List<string> GetRoles(string userName);
|
List<string> GetRoles(string userName);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 通过用户名获得授权 App 集合
|
/// 通过用户名获得授权 App 集合
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userName"></param>
|
/// <param name="userName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
List<string> GetApps(string userName);
|
List<string> GetApps(string userName);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="groupId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
List<string> GetUsersByGroupId(string? id);
|
List<string> GetUsersByGroupId(string? groupId);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="groupId"></param>
|
||||||
/// <returns></returns>
|
/// <param name="userIds"></param>
|
||||||
bool SaveUsersByGroupId(string? id, IEnumerable<string> userIds);
|
/// <returns></returns>
|
||||||
|
bool SaveUsersByGroupId(string? groupId, IEnumerable<string> userIds);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获得所有用户
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <param name="roleId"></param>
|
||||||
List<User> GetAll();
|
/// <returns></returns>
|
||||||
|
List<string> GetUsersByRoleId(string? roleId);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 认证方法
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userName"></param>
|
/// <param name="roleId"></param>
|
||||||
/// <param name="password"></param>
|
/// <param name="userIds"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
bool Authenticate(string userName, string password);
|
bool SaveUsersByRoleId(string? roleId, IEnumerable<string> userIds);
|
||||||
}
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获得所有用户
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
List<User> GetAll();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 认证方法
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <param name="password"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
bool Authenticate(string userName, string password);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,65 +1,69 @@
|
||||||
using BootstrapAdmin.DataAccess.Models;
|
using BootstrapAdmin.DataAccess.Models;
|
||||||
using BootstrapAdmin.Web.Components;
|
|
||||||
using BootstrapAdmin.Web.Core;
|
using BootstrapAdmin.Web.Core;
|
||||||
using BootstrapAdmin.Web.Extensions;
|
using BootstrapAdmin.Web.Extensions;
|
||||||
|
|
||||||
namespace BootstrapAdmin.Web.Pages.Admin
|
namespace BootstrapAdmin.Web.Pages.Admin;
|
||||||
|
|
||||||
|
public partial class Roles
|
||||||
{
|
{
|
||||||
public partial class Roles
|
[Inject]
|
||||||
|
[NotNull]
|
||||||
|
private DialogService? DialogService { get; set; }
|
||||||
|
|
||||||
|
[Inject]
|
||||||
|
[NotNull]
|
||||||
|
private ToastService? ToastService { get; set; }
|
||||||
|
|
||||||
|
[Inject]
|
||||||
|
[NotNull]
|
||||||
|
private IGroup? GroupService { get; set; }
|
||||||
|
|
||||||
|
[Inject]
|
||||||
|
[NotNull]
|
||||||
|
private IUser? UserService { get; set; }
|
||||||
|
|
||||||
|
private async Task OnAssignmentUsers(Role role)
|
||||||
{
|
{
|
||||||
[Inject]
|
var users = UserService.GetAll().ToSelectedItemList();
|
||||||
[NotNull]
|
var values = UserService.GetUsersByRoleId(role.Id);
|
||||||
private DialogService? DialogService { get; set; }
|
|
||||||
|
|
||||||
[Inject]
|
await DialogService.ShowAssignmentDialog($"分配部门 - {role.RoleName}", users, values, () =>
|
||||||
[NotNull]
|
|
||||||
private ToastService? ToastService { get; set; }
|
|
||||||
|
|
||||||
[Inject]
|
|
||||||
[NotNull]
|
|
||||||
private IGroup? GroupService { get; set; }
|
|
||||||
|
|
||||||
private async Task OnAssignmentUsers(Role role)
|
|
||||||
{
|
{
|
||||||
var option = new DialogOption()
|
var ret = UserService.SaveUsersByRoleId(role.Id, values);
|
||||||
{
|
return Task.FromResult(ret);
|
||||||
Title = $"分配用户 - {role}",
|
}, ToastService);
|
||||||
};
|
|
||||||
|
|
||||||
await DialogService.Show(option);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task OnAssignmentGroups(Role role)
|
|
||||||
{
|
|
||||||
var groups = GroupService.GetAll().ToSelectedItemList();
|
|
||||||
var values = GroupService.GetGroupsByRoleId(role.Id);
|
|
||||||
|
|
||||||
await DialogService.ShowAssignmentDialog($"分配部门 - {role.RoleName}", groups, values, () =>
|
|
||||||
{
|
|
||||||
var ret = GroupService.SaveGroupsByRoleId(role.Id, values);
|
|
||||||
return Task.FromResult(ret);
|
|
||||||
}, ToastService);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task OnAssignmentMenus(Role role)
|
|
||||||
{
|
|
||||||
var option = new DialogOption()
|
|
||||||
{
|
|
||||||
Title = $"分配菜单 - {role}",
|
|
||||||
};
|
|
||||||
|
|
||||||
await DialogService.Show(option);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task OnAssignmentApps(Role role)
|
|
||||||
{
|
|
||||||
var option = new DialogOption()
|
|
||||||
{
|
|
||||||
Title = $"分配应用 - {role}",
|
|
||||||
};
|
|
||||||
|
|
||||||
await DialogService.Show(option);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task OnAssignmentGroups(Role role)
|
||||||
|
{
|
||||||
|
var groups = GroupService.GetAll().ToSelectedItemList();
|
||||||
|
var values = GroupService.GetGroupsByRoleId(role.Id);
|
||||||
|
|
||||||
|
await DialogService.ShowAssignmentDialog($"分配部门 - {role.RoleName}", groups, values, () =>
|
||||||
|
{
|
||||||
|
var ret = GroupService.SaveGroupsByRoleId(role.Id, values);
|
||||||
|
return Task.FromResult(ret);
|
||||||
|
}, ToastService);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task OnAssignmentMenus(Role role)
|
||||||
|
{
|
||||||
|
var option = new DialogOption()
|
||||||
|
{
|
||||||
|
Title = $"分配菜单 - {role}",
|
||||||
|
};
|
||||||
|
|
||||||
|
await DialogService.Show(option);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task OnAssignmentApps(Role role)
|
||||||
|
{
|
||||||
|
var option = new DialogOption()
|
||||||
|
{
|
||||||
|
Title = $"分配应用 - {role}",
|
||||||
|
};
|
||||||
|
|
||||||
|
await DialogService.Show(option);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,51 +2,50 @@
|
||||||
using BootstrapAdmin.Web.Core;
|
using BootstrapAdmin.Web.Core;
|
||||||
using BootstrapAdmin.Web.Extensions;
|
using BootstrapAdmin.Web.Extensions;
|
||||||
|
|
||||||
namespace BootstrapAdmin.Web.Pages.Admin
|
namespace BootstrapAdmin.Web.Pages.Admin;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public partial class Users
|
||||||
{
|
{
|
||||||
/// <summary>
|
[Inject]
|
||||||
///
|
[NotNull]
|
||||||
/// </summary>
|
private DialogService? DialogService { get; set; }
|
||||||
public partial class Users
|
|
||||||
|
[Inject]
|
||||||
|
[NotNull]
|
||||||
|
private ToastService? ToastService { get; set; }
|
||||||
|
|
||||||
|
[Inject]
|
||||||
|
[NotNull]
|
||||||
|
private IGroup? GroupService { get; set; }
|
||||||
|
|
||||||
|
[Inject]
|
||||||
|
[NotNull]
|
||||||
|
private IRole? RoleService { get; set; }
|
||||||
|
|
||||||
|
private async Task OnAssignmentGroups(User user)
|
||||||
{
|
{
|
||||||
[Inject]
|
var groups = GroupService.GetAll().ToSelectedItemList();
|
||||||
[NotNull]
|
var values = GroupService.GetGroupsByUserId(user.Id);
|
||||||
private DialogService? DialogService { get; set; }
|
|
||||||
|
|
||||||
[Inject]
|
await DialogService.ShowAssignmentDialog($"分配部门 - {user}", groups, values, () =>
|
||||||
[NotNull]
|
|
||||||
private ToastService? ToastService { get; set; }
|
|
||||||
|
|
||||||
[Inject]
|
|
||||||
[NotNull]
|
|
||||||
private IGroup? GroupService { get; set; }
|
|
||||||
|
|
||||||
[Inject]
|
|
||||||
[NotNull]
|
|
||||||
private IRole? RoleService { get; set; }
|
|
||||||
|
|
||||||
private async Task OnAssignmentGroups(User user)
|
|
||||||
{
|
{
|
||||||
var groups = GroupService.GetAll().ToSelectedItemList();
|
var ret = GroupService.SaveGroupsByUserId(user.Id, values);
|
||||||
var values = GroupService.GetGroupsByUserId(user.Id);
|
return Task.FromResult(ret);
|
||||||
|
}, ToastService);
|
||||||
|
}
|
||||||
|
|
||||||
await DialogService.ShowAssignmentDialog($"分配部门 - {user}", groups, values, () =>
|
private async Task OnAssignmentRoles(User user)
|
||||||
{
|
{
|
||||||
var ret = GroupService.SaveGroupsByUserId(user.Id, values);
|
var groups = RoleService.GetAll().ToSelectedItemList();
|
||||||
return Task.FromResult(ret);
|
var values = RoleService.GetRolesByUserId(user.Id);
|
||||||
}, ToastService);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task OnAssignmentRoles(User user)
|
await DialogService.ShowAssignmentDialog($"分配角色 - {user}", groups, values, () =>
|
||||||
{
|
{
|
||||||
var groups = RoleService.GetAll().ToSelectedItemList();
|
var ret = RoleService.SaveRolesByUserId(user.Id, values);
|
||||||
var values = RoleService.GetRolesByUserId(user.Id);
|
return Task.FromResult(ret);
|
||||||
|
}, ToastService);
|
||||||
await DialogService.ShowAssignmentDialog($"分配角色 - {user}", groups, values, () =>
|
|
||||||
{
|
|
||||||
var ret = RoleService.SaveRolesByUserId(user.Id, values);
|
|
||||||
return Task.FromResult(ret);
|
|
||||||
}, ToastService);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue