feat: 添加数据权限过滤

This commit is contained in:
陈淳
2024-01-18 16:28:09 +08:00
parent 666f5a10d3
commit 7475a683cc
13 changed files with 162 additions and 55 deletions

View File

@@ -0,0 +1,39 @@
using Newtonsoft.Json;
using Volo.Abp.Users;
using Yi.Framework.Rbac.Domain.Shared.Consts;
using Yi.Framework.Rbac.Domain.Shared.Model;
namespace Yi.Framework.Rbac.Domain.Extensions
{
public static class CurrestUserExtensions
{
/// <summary>
/// 获取用户权限codes
/// </summary>
/// <param name="currentUser"></param>
/// <returns></returns>
public static List<string> GetPermissions(this ICurrentUser currentUser)
{
return currentUser.FindClaims(TokenTypeConst.Permission).Select(x => x.Value).ToList();
}
/// <summary>
/// 获取用户权限岗位id
/// </summary>
/// <param name="currentUser"></param>
/// <returns></returns>
public static Guid? GetDeptId(this ICurrentUser currentUser)
{
var deptIdOrNull = currentUser.FindClaims(TokenTypeConst.DeptId).Select(x => x.Value).FirstOrDefault();
return deptIdOrNull is null ? null : Guid.Parse(deptIdOrNull);
}
public static List<RoleTokenInfoModel>? GetRoleInfo(this ICurrentUser currentUser)
{
var roleOrNull = currentUser.FindClaims(TokenTypeConst.RoleInfo).Select(x => x.Value).FirstOrDefault();
return roleOrNull is null ? null : JsonConvert.DeserializeObject<List<RoleTokenInfoModel>>(roleOrNull);
}
}
}