You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.4 KiB
C#

using NPin.Framework.SqlSugarCore;
using NPin.Framework.Upms.Domain.Authorization;
using NPin.Framework.Upms.Domain.Shared.Consts;
using SqlSugar;
using Volo.Abp.DependencyInjection;
namespace NPin.Framework.Upms.SqlSugarCore;
public class NPinUpmsDbContext : SqlSugarDbContext
{
public NPinUpmsDbContext(IAbpLazyServiceProvider lazyServiceProvider) : base(lazyServiceProvider)
{
}
protected override void CustomDataFilter(ISqlSugarClient sqlSugarClient)
{
if (DataFilter.IsEnabled<IDataPermission>())
{
DataPermissionFilter(sqlSugarClient);
}
base.CustomDataFilter(sqlSugarClient);
}
/// <summary>
/// 数据权限过滤
/// </summary>
/// <param name="sqlSugarClient"></param>
protected void DataPermissionFilter(ISqlSugarClient sqlSugarClient)
{
// 当前无登录用户,无需过滤
if (CurrentUser.Id == null) return;
// 管理员角色 不进行过滤
if (CurrentUser.UserName.Equals(UserConst.Admin) ||
CurrentUser.Roles.Any(r => r.Equals(UserConst.AdminRoleCode)))
{
return;
}
// var expUser = Expressionable.Create<>();
// var expRole = Expressionable.Create<>();
// 无岗位 or 无角色 只能看自己
// sqlSugarClient.QueryFilter.AddTableFilter()
}
}