Skip to content

Commit

Permalink
新增会员过滤器
Browse files Browse the repository at this point in the history
  • Loading branch information
zhontai committed Nov 16, 2022
1 parent a9d56e1 commit fd60021
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/platform/ZhonTai.Admin/Core/Consts/FilterNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ public static partial class FilterNames
/// </summary>
[Description("数据权限")]
public const string Data = "Data";

/// <summary>
/// 会员
/// </summary>
[Description("会员")]
public const string Member = "Member";
}
3 changes: 2 additions & 1 deletion src/platform/ZhonTai.Admin/Core/Db/Data/SyncData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using FreeSql.DataAnnotations;
using ZhonTai.Common.Helpers;
using ZhonTai.Admin.Core.Configs;
using ZhonTai.Admin.Core.Consts;

namespace ZhonTai.Admin.Core.Db.Data;

Expand Down Expand Up @@ -56,7 +57,7 @@ protected virtual async Task InitDataAsync<T>(

try
{
if (await db.Queryable<T>().AnyAsync())
if (await db.Queryable<T>().DisableGlobalFilter(FilterNames.Tenant, FilterNames.Member).AnyAsync())
{
Console.WriteLine($" table: {tableName} record already exists");
return;
Expand Down
5 changes: 4 additions & 1 deletion src/platform/ZhonTai.Admin/Core/Db/DbHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,12 @@ HostAppOptions hostAppOptions
//租户过滤器
if (appConfig.Tenant)
{
fsql.GlobalFilter.ApplyOnlyIf<ITenant>(FilterNames.Tenant, () => user?.Id > 0, a => a.TenantId == user.TenantId);
fsql.GlobalFilter.ApplyOnly<ITenant>(FilterNames.Tenant, a => a.TenantId == user.TenantId);
}
//会员过滤器
fsql.GlobalFilter.ApplyOnly<IMember>(FilterNames.Member, a => a.MemberId == user.MemberId);
//数据权限过滤器
fsql.GlobalFilter.ApplyOnlyIf<IData>(FilterNames.Self,
() =>
Expand Down
10 changes: 10 additions & 0 deletions src/platform/ZhonTai.Admin/ZhonTai.Admin.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fd60021

Please sign in to comment.