0
如何獲得具有特定權限的所有用戶?例如,我們需要枚舉允許特定權限的所有用戶。這樣的代碼獲取具有特定權限的所有用戶?
var v=_userManager.GetAllUserWithSpecificPermission("ISO.Report.ReportV1");
foreach(var t in v)
{
Logger.Info(t.UserName);
}
如何獲得具有特定權限的所有用戶?例如,我們需要枚舉允許特定權限的所有用戶。這樣的代碼獲取具有特定權限的所有用戶?
var v=_userManager.GetAllUserWithSpecificPermission("ISO.Report.ReportV1");
foreach(var t in v)
{
Logger.Info(t.UserName);
}
您需要編寫一個查詢,以通過權限篩選用戶。這可以引導你:
var query = from user in UserManager.Users
join ur in _userRoleRepository.GetAll() on user.Id equals ur.UserId into urJoined
from ur in urJoined.DefaultIfEmpty()
join up in _userPermissionRepository.GetAll() on new {UserId = user.Id, Name = input.Permission} equals
new {up.UserId, up.Name} into upJoined
from up in upJoined.DefaultIfEmpty()
join rp in _rolePermissionRepository.GetAll() on new {RoleId = ur.RoleId, Name = input.Permission}
equals new {rp.RoleId, rp.Name} into rpJoined
from rp in rpJoined.DefaultIfEmpty()
where (up != null && up.IsGranted) || (up == null && rp != null)
group user by user
into userGrouped
select userGrouped.Key;
var users = await query.ToListAsync();
有沒有這樣的方法。您應該使用存儲庫直接從AbpPermissions表中查詢自己(請參閱表列以瞭解它) – hikalkan
@hikalkan如果將這樣的方法放到userManager或permissionManager中,它可能很有用。感謝這個真棒框架 –