修改User模块

This commit is contained in:
chfei committed 2026-10-23 19:01:28 +08:00
1 parent d6471f97d3
commit bb7162aaf6
21 files changed
+278 -336

No files matched your search

@@ -1,3 +1,4 @@
using Store.Users.Contracts.Enums;
using Store.Users.Entities;
namespace Store.Users.Services;
@@ -5,14 +6,19 @@ namespace Store.Users.Services;
/// <summary>统一账户管理范围:管理员管理全部,主账号管理本人及直属子账号。</summary>
internal static class UserAccessPolicy
{
public static bool IsAdmin(UserEntity actor) => actor.SaLevel == 1;
public static bool IsAdmin(UserEntity actor) => actor.SaLevel == UserAdminLevel.SuperAdmin;
public static bool Owns(UserEntity actor, UserEntity target) => actor.IsMainUser
&& string.Equals(target.ParentUserName, actor.UserName, StringComparison.OrdinalIgnoreCase);
public static bool CanRead(UserEntity actor, UserEntity target) =>
IsAdmin(actor) || actor.Id == target.Id || Owns(actor, target);
CanUseSelfService(actor, target);
/// <summary>子账号可查询本人、修改本人密码、提交充值备注和为本人店铺续费。</summary>
public static bool CanUseSelfService(UserEntity actor, UserEntity target) =>
actor.Id == target.Id || CanManage(actor, target);
/// <summary>管理员不受归属限制;普通主账号不能接管具有管理员身份的子账号。</summary>
public static bool CanManage(UserEntity actor, UserEntity target) =>
IsAdmin(actor) || (!IsAdmin(target) && actor.IsMainUser && (actor.Id == target.Id || Owns(actor, target)));
}