From 9fb4d037d99f42fdb0d294ce2ed2e59d232232fd Mon Sep 17 00:00:00 2001
From: 李曜臣
Date: Fri, 13 Nov 2026 17:53:09 +0800
Subject: [PATCH] 2026-11-13
---
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/DashboardScopeHelper.cs | 2 +-
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelMultipleOptionManagePermissionHelper.cs | 76 ++++++----------------------------------------------------------------------
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelRegionScopeHelper.cs | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelTemplateManagePermissionHelper.cs | 50 +++++++++++++++++++++++++++++++++++++++++---------
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/PartnerScopedManagePermissionHelper.cs | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/ProductCategoryImportHelper.cs | 42 ++++++++++++++++++++++++++++++++++++++++++
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/ProductCategoryNameMatchHelper.cs | 60 +++++++++++++++++++++++++++++++++++++-----------------------
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/TeamMemberListAccessHelper.cs | 13 ++++++++++---
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/TeamMemberListScopeHelper.cs | 2 +-
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/TeamMemberRoleHelper.cs | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelAppService.cs | 19 ++++++++++++++-----
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelCategoryAppService.cs | 9 +++++++--
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelMultipleOptionAppService.cs | 23 +++++++++++++++++------
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelTemplateAppService.cs | 13 ++++++++-----
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelTypeAppService.cs | 15 ++++++++++-----
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/ProductAppService.cs | 4 +++-
16 files changed, 401 insertions(+), 178 deletions(-)
create mode 100644 美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/ProductCategoryImportHelper.cs
diff --git a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/DashboardScopeHelper.cs b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/DashboardScopeHelper.cs
index d2e3a4f..47263f3 100644
--- a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/DashboardScopeHelper.cs
+++ b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/DashboardScopeHelper.cs
@@ -203,7 +203,7 @@ public static class DashboardScopeHelper
db, labelQuery, regionSchema);
}
- return LabelRegionScopeHelper.ApplyLabelLocationListFilter(
+ return await LabelRegionScopeHelper.ApplyLabelLocationListFilterAsync(
db, labelQuery, scopedLocationIds, regionSchema);
}
diff --git a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelMultipleOptionManagePermissionHelper.cs b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelMultipleOptionManagePermissionHelper.cs
index f1255db..c7e50fb 100644
--- a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelMultipleOptionManagePermissionHelper.cs
+++ b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelMultipleOptionManagePermissionHelper.cs
@@ -6,85 +6,21 @@ using Yi.Framework.SqlSugarCore.Abstractions;
namespace FoodLabeling.Application.Helpers;
///
-/// Multiple Option 编辑/删除权限:
-/// System Admin 可管理全部;
-/// Company Admin 仅可管理「非 System Admin 创建」且「适用本公司」的多选项。
+/// Multiple Option 编辑/删除权限,与 / 标签分类等规则一致。
///
public static class LabelMultipleOptionManagePermissionHelper
{
- private const string ScopeAll = "ALL";
-
- public static async Task CanManageAsync(
- ICurrentUser currentUser,
- ISqlSugarDbContext dbContext,
- IReadOnlyList? partnerIds,
- bool createdBySystemAdmin)
- {
- if (ReportsRoleHelper.IsAdminRole(currentUser))
- {
- return true;
- }
-
- if (!await TeamMemberRoleHelper.IsScopedAdminUserAsync(dbContext.SqlSugarClient, currentUser))
- {
- return false;
- }
-
- if (createdBySystemAdmin)
- {
- return false;
- }
-
- var optionPartnerIds = (partnerIds ?? Array.Empty())
- .Select(x => x?.Trim())
- .Where(x => !string.IsNullOrWhiteSpace(x))
- .Select(x => x!)
- .ToList();
-
- if (optionPartnerIds.Count == 0 ||
- optionPartnerIds.Any(id =>
- string.Equals(id, ScopeAll, StringComparison.OrdinalIgnoreCase)))
- {
- return false;
- }
-
- var scope = await PartnerScopeHelper.ResolvePartnerScopeAsync(currentUser, dbContext);
- if (scope.IsUnrestricted)
- {
- return true;
- }
-
- var allowed = scope.AllowedPartnerIds ?? Array.Empty();
- return optionPartnerIds.Any(pid =>
- allowed.Any(a => string.Equals(a, pid, StringComparison.OrdinalIgnoreCase)));
- }
-
public static async Task EnsureCanManageAsync(
ICurrentUser currentUser,
ISqlSugarDbContext dbContext,
FlLabelMultipleOptionDbEntity entity)
{
- var createdBySystemAdmin = false;
- if (!string.IsNullOrWhiteSpace(entity.CreatorId) &&
- Guid.TryParse(entity.CreatorId.Trim(), out var creatorGuid))
- {
- createdBySystemAdmin = await TeamMemberRoleHelper.IsSystemAdminUserAsync(
- dbContext.SqlSugarClient, creatorGuid);
- }
-
- var scopeMap = await LabelEntityPartnerScopeHelper.BuildPartnerScopeDisplayMapAsync(
- dbContext.SqlSugarClient,
+ await PartnerScopedManagePermissionHelper.EnsureCanManagePartnerEntityAsync(
+ currentUser,
+ dbContext,
LabelEntityPartnerScopeHelper.LabelEntityPartnerKind.MultipleOption,
- new List { entity.Id });
- scopeMap.TryGetValue(entity.Id, out var scope);
- var partnerIds = scope?.PartnerIds ?? new List();
-
- if (await CanManageAsync(currentUser, dbContext, partnerIds, createdBySystemAdmin))
- {
- return;
- }
-
- throw new UserFriendlyException(
+ entity.Id,
+ entity.CreatorId,
"You are not authorized to edit or delete this Multiple Option Set.");
}
}
diff --git a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelRegionScopeHelper.cs b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelRegionScopeHelper.cs
index 60cf025..6569b0f 100644
--- a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelRegionScopeHelper.cs
+++ b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelRegionScopeHelper.cs
@@ -617,7 +617,7 @@ public static class LabelRegionScopeHelper
///
/// ??? Region?fl_group.Id?? scoped ?????
///
- public static ISugarQueryable ApplyLabelRegionListFilter(
+ public static async Task> ApplyLabelRegionListFilterAsync(
ISqlSugarClient db,
ISugarQueryable query,
string groupId,
@@ -630,14 +630,18 @@ public static class LabelRegionScopeHelper
return query.Where(_ => false);
}
+ var scopedGroupIds = schema.HasLabelRegionTable
+ ? await LocationScopeBindingHelper.ResolveGroupIdsFromLocationIdsAsync(db, scopedLocationIds)
+ : new List();
+
if (!schema.HasLabelRegionTable && !schema.HasAppliedRegionTypeColumn)
{
- return ApplyLabelLocationMatchFilter(query, scopedLocationIds, schema);
+ return ApplyLabelLocationMatchFilter(query, scopedLocationIds, scopedGroupIds, schema);
}
if (!schema.HasLabelRegionTable)
{
- return ApplyLabelLocationMatchFilter(query, scopedLocationIds, schema);
+ return ApplyLabelLocationMatchFilter(query, scopedLocationIds, scopedGroupIds, schema);
}
if (!schema.HasAppliedRegionTypeColumn)
@@ -772,7 +776,7 @@ public static class LabelRegionScopeHelper
/// 按 scoped 门店过滤。
/// AppliedRegionType=ALL 且无门店快照时为全局;有快照时须与 scoped 门店有交集(对齐 )。
///
- public static ISugarQueryable ApplyLabelLocationListFilter(
+ public static async Task> ApplyLabelLocationListFilterAsync(
ISqlSugarClient db,
ISugarQueryable query,
List scopedLocationIds,
@@ -783,7 +787,11 @@ public static class LabelRegionScopeHelper
return ApplyLabelAllRegionOnlyFilter(db, query, schema);
}
- return ApplyLabelLocationMatchFilter(query, scopedLocationIds, schema);
+ var scopedGroupIds = schema.HasLabelRegionTable
+ ? await LocationScopeBindingHelper.ResolveGroupIdsFromLocationIdsAsync(db, scopedLocationIds)
+ : new List();
+
+ return ApplyLabelLocationMatchFilter(query, scopedLocationIds, scopedGroupIds, schema);
}
///
@@ -981,58 +989,92 @@ public static class LabelRegionScopeHelper
private static ISugarQueryable ApplyLabelLocationMatchFilter(
ISugarQueryable query,
List scopedLocationIds,
+ IReadOnlyList scopedGroupIds,
LabelRegionSchemaHelper.LabelRegionSchemaStatus schema)
{
+ var includeRegionMatch = schema.HasLabelRegionTable && scopedGroupIds.Count > 0;
+ var specifiedBranch = BuildSpecifiedLocationRegionMatchSql(
+ schema.HasLabelLocationTable,
+ includeRegionMatch);
+
// 对齐 BuildAppLabelingTreeStoreFilterSql / LabelAppliesToLocationAsync:
// ALL 无门店快照 → 全局;ALL 有快照 → 须命中 scoped 门店(不可无条件放行,否则跨公司泄漏)。
+ // SPECIFIED 仅 fl_label_region、无门店快照(Scoped ALL)→ 按 scoped 门店所属 Region 命中。
if (schema.HasAppliedRegionTypeColumn && schema.HasLabelLocationTable)
{
return query.Where(
- """
- (
- (AppliedRegionType = @all AND (
- ((LocationId IS NULL OR LocationId = '')
- AND NOT EXISTS (SELECT 1 FROM fl_label_location ll0 WHERE ll0.LabelId = fl_label.Id))
- OR LocationId IN (@locs)
- OR EXISTS (SELECT 1 FROM fl_label_location ll WHERE ll.LabelId = fl_label.Id AND ll.LocationId IN (@locs))
- ))
- OR (AppliedRegionType <> @all AND (
- LocationId IN (@locs)
- OR EXISTS (SELECT 1 FROM fl_label_location ll WHERE ll.LabelId = fl_label.Id AND ll.LocationId IN (@locs))
- ))
- )
- """,
- new { all = AppliedRegionAll, locs = scopedLocationIds });
+ $"""
+ (
+ (AppliedRegionType = @all AND (
+ ((LocationId IS NULL OR LocationId = '')
+ AND NOT EXISTS (SELECT 1 FROM fl_label_location ll0 WHERE ll0.LabelId = fl_label.Id))
+ OR LocationId IN (@locs)
+ OR EXISTS (SELECT 1 FROM fl_label_location ll WHERE ll.LabelId = fl_label.Id AND ll.LocationId IN (@locs))
+ ))
+ OR (AppliedRegionType <> @all AND ({specifiedBranch}))
+ )
+ """,
+ new
+ {
+ all = AppliedRegionAll,
+ locs = scopedLocationIds,
+ scopedGroupIds
+ });
}
if (schema.HasAppliedRegionTypeColumn)
{
+ var specifiedOnlyLocations = includeRegionMatch
+ ? specifiedBranch
+ : "LocationId IN (@locs)";
return query.Where(
- """
- (
- (AppliedRegionType = @all AND (
- (LocationId IS NULL OR LocationId = '')
- OR LocationId IN (@locs)
- ))
- OR (AppliedRegionType <> @all AND LocationId IN (@locs))
- )
- """,
- new { all = AppliedRegionAll, locs = scopedLocationIds });
+ $"""
+ (
+ (AppliedRegionType = @all AND (
+ (LocationId IS NULL OR LocationId = '')
+ OR LocationId IN (@locs)
+ ))
+ OR (AppliedRegionType <> @all AND ({specifiedOnlyLocations}))
+ )
+ """,
+ new
+ {
+ all = AppliedRegionAll,
+ locs = scopedLocationIds,
+ scopedGroupIds
+ });
}
if (schema.HasLabelLocationTable)
{
return query.Where(
- """
- (LocationId IN (@locs)
- OR EXISTS (SELECT 1 FROM fl_label_location ll WHERE ll.LabelId = fl_label.Id AND ll.LocationId IN (@locs)))
+ $"""
+ ({specifiedBranch})
""",
- new { locs = scopedLocationIds });
+ new { locs = scopedLocationIds, scopedGroupIds });
}
return query.Where(l => scopedLocationIds.Contains(l.LocationId));
}
+ private static string BuildSpecifiedLocationRegionMatchSql(bool hasLabelLocationTable, bool includeRegionMatch)
+ {
+ var parts = new List { "LocationId IN (@locs)" };
+ if (hasLabelLocationTable)
+ {
+ parts.Add(
+ "EXISTS (SELECT 1 FROM fl_label_location ll WHERE ll.LabelId = fl_label.Id AND ll.LocationId IN (@locs))");
+ }
+
+ if (includeRegionMatch)
+ {
+ parts.Add(
+ "EXISTS (SELECT 1 FROM fl_label_region lr WHERE lr.LabelId = fl_label.Id AND lr.GroupId IN (@scopedGroupIds))");
+ }
+
+ return string.Join(" OR ", parts);
+ }
+
private static List MergeExplicitLocationIds(string? locationId, IReadOnlyList? locationIds)
{
var merged = LocationScopeBindingHelper.NormalizeIds(locationIds);
diff --git a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelTemplateManagePermissionHelper.cs b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelTemplateManagePermissionHelper.cs
index 4b53f4d..ed6db3e 100644
--- a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelTemplateManagePermissionHelper.cs
+++ b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelTemplateManagePermissionHelper.cs
@@ -61,7 +61,8 @@ public static class LabelTemplateManagePermissionHelper
creatorPartners,
template.CreatorId,
viewerTier,
- creatorTier);
+ creatorTier,
+ allowSelfCreatedWithoutConcretePartner: true);
}
///
@@ -103,23 +104,37 @@ public static class LabelTemplateManagePermissionHelper
return false;
}
+ // 创建者角色更高(System/Company 相对 Regional/Location)→ 下级不可管。
if (IsCreatorRoleSuperiorToViewer(creatorRoleTier, viewerRoleTier))
{
return false;
}
+ var creatorPartners = NormalizeIds(creatorPartnerIds);
+ var allowed = NormalizeIds(allowedPartnerIds);
+
+ // 上级编辑下级创建:只要创建人落在查看者公司范围内即可。
+ // 下级常把 Region/Location 设为 ALL,权限用 partnerIds 会被算成空而误拒。
+ if (IsViewerRoleSuperiorToCreator(viewerRoleTier, creatorRoleTier))
+ {
+ if (creatorPartners.Count == 0 || allowed.Count == 0)
+ {
+ return false;
+ }
+
+ return creatorPartners.Any(pid => ContainsId(allowed, pid));
+ }
+
if (!MeetsPartnerScopeForManage(partnerIds, allowedPartnerIds, allowEmptyPartnerIds: false))
{
return false;
}
- var creatorPartners = NormalizeIds(creatorPartnerIds);
if (creatorPartners.Count == 0)
{
return false;
}
- var allowed = NormalizeIds(allowedPartnerIds);
return creatorPartners.Any(pid => ContainsId(allowed, pid));
}
@@ -161,6 +176,19 @@ public static class LabelTemplateManagePermissionHelper
return creatorRoleTier.Value < viewerRoleTier.Value;
}
+ /// 查看者层级更高(数值更小)于创建者 → 上级可管下级创建的项目。
+ private static bool IsViewerRoleSuperiorToCreator(
+ TeamMemberListAccessHelper.MemberRoleTier? viewerRoleTier,
+ TeamMemberListAccessHelper.MemberRoleTier? creatorRoleTier)
+ {
+ if (creatorRoleTier is null || viewerRoleTier is null)
+ {
+ return false;
+ }
+
+ return viewerRoleTier.Value < creatorRoleTier.Value;
+ }
+
private static bool MeetsPartnerScopeForManage(
IReadOnlyList? partnerIds,
IReadOnlyList? allowedPartnerIds,
@@ -197,9 +225,12 @@ public static class LabelTemplateManagePermissionHelper
ISqlSugarDbContext dbContext,
FlLabelTemplateDbEntity template)
{
+ var creatorIdForManage = PartnerScopedManagePermissionHelper.ResolveCreatorIdForPermission(
+ template.Id, template.CreatorId, template.LastModifierId);
+
var createdBySystemAdmin = false;
- if (!string.IsNullOrWhiteSpace(template.CreatorId) &&
- Guid.TryParse(template.CreatorId.Trim(), out var creatorGuid))
+ if (!string.IsNullOrWhiteSpace(creatorIdForManage) &&
+ Guid.TryParse(creatorIdForManage.Trim(), out var creatorGuid))
{
createdBySystemAdmin = await TeamMemberRoleHelper.IsSystemAdminUserAsync(
dbContext.SqlSugarClient, creatorGuid);
@@ -212,14 +243,14 @@ public static class LabelTemplateManagePermissionHelper
var partnerIds = scope?.PartnerIds ?? new List();
var (viewerTier, creatorTier) = await ResolveManageRoleTiersAsync(
- dbContext.SqlSugarClient, currentUser, template.CreatorId);
+ dbContext.SqlSugarClient, currentUser, creatorIdForManage);
var isScopedAdmin = await TeamMemberRoleHelper.IsScopedAdminUserAsync(
dbContext.SqlSugarClient, currentUser);
var partnerScope = await PartnerScopeHelper.ResolvePartnerScopeAsync(currentUser, dbContext);
IReadOnlyList? creatorPartnerIds = null;
if (!createdBySystemAdmin &&
- Guid.TryParse(template.CreatorId?.Trim(), out var ownerGuid))
+ Guid.TryParse(creatorIdForManage?.Trim(), out var ownerGuid))
{
creatorPartnerIds = await PartnerScopeHelper.ResolvePartnerIdsForUserAsync(
dbContext.SqlSugarClient, ownerGuid);
@@ -232,9 +263,10 @@ public static class LabelTemplateManagePermissionHelper
createdBySystemAdmin,
partnerScope.AllowedPartnerIds,
creatorPartnerIds,
- template.CreatorId,
+ creatorIdForManage,
viewerTier,
- creatorTier))
+ creatorTier,
+ allowSelfCreatedWithoutConcretePartner: true))
{
return;
}
diff --git a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/PartnerScopedManagePermissionHelper.cs b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/PartnerScopedManagePermissionHelper.cs
index ef726ad..b22b629 100644
--- a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/PartnerScopedManagePermissionHelper.cs
+++ b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/PartnerScopedManagePermissionHelper.cs
@@ -29,16 +29,22 @@ public static class PartnerScopedManagePermissionHelper
public static async Task BuildListContextAsync(
ICurrentUser currentUser,
ISqlSugarDbContext dbContext,
- IEnumerable creatorIds)
+ IEnumerable creatorIds,
+ IEnumerable? fallbackUserIds = null)
{
+ // 合并 CreatorId + LastModifierId:脏数据 CreatorId=实体Id 时,矫正后仍能命中公司/层级 map。
+ var allUserIds = (creatorIds ?? Array.Empty())
+ .Concat(fallbackUserIds ?? Array.Empty())
+ .ToList();
+
var isScopedAdmin = await TeamMemberRoleHelper.IsScopedAdminUserAsync(
dbContext.SqlSugarClient, currentUser);
var currentPartnerScope = await PartnerScopeHelper.ResolvePartnerScopeAsync(currentUser, dbContext);
var systemAdminCreatorIds = await TeamMemberRoleHelper.ResolveSystemAdminCreatorIdSetAsync(
- dbContext.SqlSugarClient, creatorIds);
+ dbContext.SqlSugarClient, allUserIds);
var creatorPartnerMap = new Dictionary>();
- foreach (var creatorId in creatorIds
+ foreach (var creatorId in allUserIds
.Select(id => Guid.TryParse(id?.Trim(), out var g) ? g : (Guid?)null)
.Where(g => g.HasValue)
.Select(g => g!.Value)
@@ -53,7 +59,7 @@ public static class PartnerScopedManagePermissionHelper
dbContext.SqlSugarClient, creatorId);
}
- var creatorGuids = creatorIds
+ var creatorGuids = allUserIds
.Select(id => Guid.TryParse(id?.Trim(), out var g) ? g : (Guid?)null)
.Where(g => g.HasValue)
.Select(g => g!.Value)
@@ -80,12 +86,44 @@ public static class PartnerScopedManagePermissionHelper
};
}
+ ///
+ /// 当库里误将 CreatorId 写成实体主键时,用 LastModifierId 参与权限判定(常见于历史脏数据)。
+ ///
+ public static string? ResolveCreatorIdForPermission(
+ string? entityId,
+ string? creatorId,
+ string? lastModifierId)
+ {
+ if (string.IsNullOrWhiteSpace(creatorId))
+ {
+ return creatorId;
+ }
+
+ var normalizedCreator = creatorId.Trim();
+ if (string.IsNullOrWhiteSpace(entityId)
+ || !string.Equals(normalizedCreator, entityId.Trim(), StringComparison.OrdinalIgnoreCase))
+ {
+ return normalizedCreator;
+ }
+
+ if (!string.IsNullOrWhiteSpace(lastModifierId)
+ && !string.Equals(lastModifierId.Trim(), entityId.Trim(), StringComparison.OrdinalIgnoreCase))
+ {
+ return lastModifierId.Trim();
+ }
+
+ return normalizedCreator;
+ }
+
public static bool EvaluateCanManage(
ICurrentUser currentUser,
ListEvaluationContext context,
string? creatorId,
- IReadOnlyList? partnerIds)
+ IReadOnlyList? partnerIds,
+ string? entityId = null,
+ string? lastModifierId = null)
{
+ creatorId = ResolveCreatorIdForPermission(entityId, creatorId, lastModifierId);
var createdBySystemAdmin =
Guid.TryParse(creatorId?.Trim(), out var creatorGuid) &&
context.SystemAdminCreatorIds.Contains(creatorGuid);
@@ -198,10 +236,15 @@ public static class PartnerScopedManagePermissionHelper
locationIdsForEcho: null,
partnerIdsForEcho);
+ var creatorForManage = ResolveCreatorIdForPermission(
+ entityId,
+ entityScope.CreatorId ?? creatorId,
+ entityScope.LastModifierId);
+
await EnsureCanManageAsync(
currentUser,
dbContext,
- entityScope.CreatorId ?? creatorId,
+ creatorForManage,
partnerIdsForManage,
unauthorizedMessage);
}
@@ -322,6 +365,8 @@ public static class PartnerScopedManagePermissionHelper
public string AppliedPartnerType { get; init; } = AllScopeBindingHelper.ScopeAll;
public string? CreatorId { get; init; }
+
+ public string? LastModifierId { get; init; }
}
private static async Task LoadPartnerScopedEntityScopeAsync(
@@ -339,7 +384,8 @@ public static class PartnerScopedManagePermissionHelper
AvailabilityType = x.AvailabilityType,
AppliedRegionType = x.AppliedRegionType,
AppliedPartnerType = x.AppliedPartnerType,
- CreatorId = x.CreatorId
+ CreatorId = x.CreatorId,
+ LastModifierId = x.LastModifierId
})
.FirstAsync();
return productCategory;
@@ -351,7 +397,8 @@ public static class PartnerScopedManagePermissionHelper
AvailabilityType = x.AvailabilityType,
AppliedRegionType = x.AppliedRegionType,
AppliedPartnerType = x.AppliedPartnerType,
- CreatorId = x.CreatorId
+ CreatorId = x.CreatorId,
+ LastModifierId = x.LastModifierId
})
.FirstAsync();
return labelCategory;
@@ -363,10 +410,24 @@ public static class PartnerScopedManagePermissionHelper
AvailabilityType = x.AvailabilityType,
AppliedRegionType = x.AppliedRegionType,
AppliedPartnerType = x.AppliedPartnerType,
- CreatorId = x.CreatorId
+ CreatorId = x.CreatorId,
+ LastModifierId = x.LastModifierId
})
.FirstAsync();
return labelType;
+ case LabelEntityPartnerScopeHelper.LabelEntityPartnerKind.MultipleOption:
+ var multipleOption = await db.Queryable()
+ .Where(x => x.Id == entityId && !x.IsDeleted)
+ .Select(x => new PartnerScopedEntityScopeRow
+ {
+ AvailabilityType = x.AvailabilityType,
+ AppliedRegionType = x.AppliedRegionType,
+ AppliedPartnerType = x.AppliedPartnerType,
+ CreatorId = x.CreatorId,
+ LastModifierId = x.LastModifierId
+ })
+ .FirstAsync();
+ return multipleOption;
default:
return null;
}
@@ -394,6 +455,11 @@ public static class PartnerScopedManagePermissionHelper
.Where(x => x.LabelTypeId == entityId)
.Select(x => x.LocationId)
.ToListAsync();
+ case LabelEntityPartnerScopeHelper.LabelEntityPartnerKind.MultipleOption:
+ return await db.Queryable()
+ .Where(x => x.MultipleOptionId == entityId)
+ .Select(x => x.LocationId)
+ .ToListAsync();
default:
return new List();
}
diff --git a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/ProductCategoryImportHelper.cs b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/ProductCategoryImportHelper.cs
new file mode 100644
index 0000000..04813ad
--- /dev/null
+++ b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/ProductCategoryImportHelper.cs
@@ -0,0 +1,42 @@
+using FoodLabeling.Application.Services.DbModels;
+using SqlSugar;
+
+namespace FoodLabeling.Application.Helpers;
+
+///
+/// 产品批量导入:分类解析与空 CategoryCode 回填(产品仅落库 CategoryId)。
+///
+public static class ProductCategoryImportHelper
+{
+ ///
+ /// 分类 CategoryCode 为空时,按主键生成稳定编码,避免列表/报表仅展示空编码而关联实际已通过 Id 建立。
+ ///
+ public static async Task EnsureImportableCategoryCodeAsync(ISqlSugarClient db, FlProductCategoryDbEntity category)
+ {
+ if (category is null || !string.IsNullOrWhiteSpace(category.CategoryCode))
+ {
+ return;
+ }
+
+ var code = BuildStableCategoryCode(category.Id);
+ var exists = await db.Queryable()
+ .AnyAsync(x => !x.IsDeleted && x.Id != category.Id && x.CategoryCode == code);
+ if (exists)
+ {
+ code = $"CAT_{category.Id.Replace("-", string.Empty, StringComparison.Ordinal).ToLowerInvariant()}";
+ }
+
+ await db.Updateable()
+ .SetColumns(x => new FlProductCategoryDbEntity { CategoryCode = code })
+ .Where(x => x.Id == category.Id)
+ .ExecuteCommandAsync();
+ category.CategoryCode = code;
+ }
+
+ private static string BuildStableCategoryCode(string categoryId)
+ {
+ var compact = categoryId.Replace("-", string.Empty, StringComparison.Ordinal).ToLowerInvariant();
+ var suffix = compact.Length <= 16 ? compact : compact[..16];
+ return $"CAT_{suffix}";
+ }
+}
diff --git a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/ProductCategoryNameMatchHelper.cs b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/ProductCategoryNameMatchHelper.cs
index bb8fd5d..142d2b2 100644
--- a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/ProductCategoryNameMatchHelper.cs
+++ b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/ProductCategoryNameMatchHelper.cs
@@ -5,7 +5,7 @@ using SqlSugar;
namespace FoodLabeling.Application.Helpers;
///
-/// 产品分类名称匹配(导入 Excel 与库中简繁/空格差异)。
+/// 产品分类名称匹配(导入 Excel 与库中简繁/空格差异;支持名称、编码、展示文案)。
///
public static class ProductCategoryNameMatchHelper
{
@@ -20,15 +20,11 @@ public static class ProductCategoryNameMatchHelper
return new List();
}
- var categories = await db.Queryable()
- .Where(x => !x.IsDeleted)
- .ToListAsync();
-
- categories = await NarrowCategoriesByPartnerAsync(db, categories, partnerId);
-
+ var categories = await LoadPartnerScopedCategoriesAsync(db, partnerId);
var key = NormalizeNameKey(n);
+
var exact = categories
- .Where(c => NormalizeNameKey(c.CategoryName) == key)
+ .Where(c => MatchesImportCategoryCell(c, key, n))
.ToList();
if (exact.Count > 0)
{
@@ -47,28 +43,46 @@ public static class ProductCategoryNameMatchHelper
.ToList();
}
- private static async Task> NarrowCategoriesByPartnerAsync(
+ private static async Task> LoadPartnerScopedCategoriesAsync(
ISqlSugarClient db,
- List categories,
string? partnerId)
{
- var pid = partnerId?.Trim();
- if (string.IsNullOrWhiteSpace(pid))
+ var query = db.Queryable().Where(x => !x.IsDeleted);
+ var scopedPartnerIds = await LabelEntityPartnerScopeHelper.ResolveScopedPartnerIdsForListAsync(db, partnerId);
+ if (scopedPartnerIds is not null)
{
- return categories;
+ query = await LabelEntityPartnerScopeHelper.ApplyProductCategoryPartnerListFilterAsync(
+ db, query, scopedPartnerIds);
}
- var linkedIds = await db.Queryable()
- .Where(x => x.PartnerId == pid)
- .Select(x => x.CategoryId)
- .ToListAsync();
- var linkedSet = new HashSet(linkedIds, StringComparer.OrdinalIgnoreCase);
+ return await query.ToListAsync();
+ }
- return categories
- .Where(c =>
- AllScopeBindingHelper.IsDeclaredAll(c.AppliedPartnerType)
- || linkedSet.Contains(c.Id))
- .ToList();
+ private static bool MatchesImportCategoryCell(FlProductCategoryDbEntity category, string normalizedKey, string rawCell)
+ {
+ if (NormalizeNameKey(category.CategoryName) == normalizedKey)
+ {
+ return true;
+ }
+
+ if (!string.IsNullOrWhiteSpace(category.DisplayText)
+ && NormalizeNameKey(category.DisplayText) == normalizedKey)
+ {
+ return true;
+ }
+
+ var code = category.CategoryCode?.Trim();
+ if (string.IsNullOrWhiteSpace(code))
+ {
+ return false;
+ }
+
+ if (NormalizeNameKey(code) == normalizedKey)
+ {
+ return true;
+ }
+
+ return string.Equals(code, rawCell.Trim(), StringComparison.OrdinalIgnoreCase);
}
private static string NormalizeNameKey(string? raw)
diff --git a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/TeamMemberListAccessHelper.cs b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/TeamMemberListAccessHelper.cs
index 9bb4727..7a4c738 100644
--- a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/TeamMemberListAccessHelper.cs
+++ b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/TeamMemberListAccessHelper.cs
@@ -45,6 +45,11 @@ public static class TeamMemberListAccessHelper
return MemberRoleTier.Staff;
}
+ if (await TeamMemberRoleHelper.IsSystemAdminUserAsync(db, currentUser.Id.Value))
+ {
+ return null;
+ }
+
if (await TeamMemberRoleHelper.IsCompanyAdminUserAsync(db, currentUser))
{
return MemberRoleTier.System;
@@ -56,8 +61,8 @@ public static class TeamMemberListAccessHelper
return MemberRoleTier.Company;
}
- // Location Admin:仅可见比 Regional 更低的角色(不含 Regional / Company / System)。
- if (await TeamMemberRoleHelper.IsLocationAdminUserAsync(db, currentUser))
+ // Location Admin / Location Manager:仅可见比 Regional 更低的角色。
+ if (await TeamMemberRoleHelper.IsLocationTierUserAsync(db, currentUser))
{
return MemberRoleTier.Regional;
}
@@ -218,7 +223,9 @@ public static class TeamMemberListAccessHelper
if (roleRows.Any(r =>
TeamMemberRoleHelper.IsLocationAdminRoleToken(r.RoleName)
- || TeamMemberRoleHelper.IsLocationAdminRoleToken(r.RoleCode)))
+ || TeamMemberRoleHelper.IsLocationAdminRoleToken(r.RoleCode)
+ || TeamMemberRoleHelper.IsLocationManagerRoleToken(r.RoleName)
+ || TeamMemberRoleHelper.IsLocationManagerRoleToken(r.RoleCode)))
{
return MemberRoleTier.Location;
}
diff --git a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/TeamMemberListScopeHelper.cs b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/TeamMemberListScopeHelper.cs
index 7fd5f22..4e3d5c2 100644
--- a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/TeamMemberListScopeHelper.cs
+++ b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/TeamMemberListScopeHelper.cs
@@ -75,7 +75,7 @@ public static class TeamMemberListScopeHelper
var isRegionalOrLocationAdmin =
currentUser.Id.HasValue &&
(await TeamMemberRoleHelper.IsRegionalAdminUserAsync(db, currentUser)
- || await TeamMemberRoleHelper.IsLocationAdminUserAsync(db, currentUser));
+ || await TeamMemberRoleHelper.IsLocationTierUserAsync(db, currentUser));
var allowedLocIds = isRegionalOrLocationAdmin
? await LocationScopeBindingHelper.ResolveAppAccessibleLocationIdsForUserAsync(
diff --git a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/TeamMemberRoleHelper.cs b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/TeamMemberRoleHelper.cs
index 18521db..71853c4 100644
--- a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/TeamMemberRoleHelper.cs
+++ b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/TeamMemberRoleHelper.cs
@@ -70,7 +70,8 @@ public static class TeamMemberRoleHelper
}
if (IsCompanyAdminRoleName(roleName) || IsCompanyAdminRoleToken(roleName)
- || IsRegionalAdminRoleToken(roleName) || IsLocationAdminRoleToken(roleName))
+ || IsRegionalAdminRoleToken(roleName) || IsLocationAdminRoleToken(roleName)
+ || IsLocationManagerRoleToken(roleName))
{
return false;
}
@@ -202,6 +203,54 @@ public static class TeamMemberRoleHelper
|| string.Equals(name, FoodLabelingRoleCodes.LocationAdmin, StringComparison.OrdinalIgnoreCase);
}
+ ///
+ /// RoleCode / RoleName 是否 Location Manager(库内常见 RoleCode Manager,与 Location Admin 数据范围同级)。
+ ///
+ public static bool IsLocationManagerRoleToken(string? value)
+ {
+ if (string.IsNullOrWhiteSpace(value) || IsCompanyAdminRoleToken(value) || IsLocationAdminRoleToken(value))
+ {
+ return false;
+ }
+
+ var key = NormalizeRoleKey(value);
+ if (key == "manager" || key.Contains("locationmanager", StringComparison.Ordinal))
+ {
+ return true;
+ }
+
+ var name = value.Trim();
+ return string.Equals(name, "Location Manager", StringComparison.OrdinalIgnoreCase);
+ }
+
+ /// Location Admin 或 Location Manager(Team Member 列表可见性 / 门店范围,不含保存时 Location Admin 专属规则)。
+ public static bool IsLocationTierRoleToken(string? value) =>
+ IsLocationAdminRoleToken(value) || IsLocationManagerRoleToken(value);
+
+ /// 当前用户是否为 Location Admin / Location Manager(JWT + 库内 Role)。
+ public static async Task IsLocationTierUserAsync(ISqlSugarClient db, ICurrentUser currentUser)
+ {
+ if (currentUser.Id is null)
+ {
+ return false;
+ }
+
+ if (IsRoleFromClaims(currentUser, IsLocationTierRoleToken))
+ {
+ return true;
+ }
+
+ return await IsLocationTierUserAsync(db, currentUser.Id.Value);
+ }
+
+ /// 指定用户是否为 Location Admin / Location Manager。
+ public static async Task IsLocationTierUserAsync(ISqlSugarClient db, Guid userId)
+ {
+ var roleRows = await LoadUserRoleRowsAsync(db, userId);
+ return roleRows.Any(r =>
+ IsLocationTierRoleToken(r.RoleName) || IsLocationTierRoleToken(r.RoleCode));
+ }
+
public static async Task IsRegionalAdminUserAsync(ISqlSugarClient db, ICurrentUser currentUser)
{
if (currentUser.Id is null)
@@ -251,12 +300,12 @@ public static class TeamMemberRoleHelper
await RoleMatchesAsync(db, roleId, IsLocationAdminRoleToken);
///
- /// Company / Regional / Location Admin(功能权限可与 Company Admin 对齐,差异在数据范围)。
+ /// Company / Regional / Location Admin / Location Manager(功能权限可与 Company Admin 对齐,差异在数据范围)。
///
public static async Task IsScopedAdminUserAsync(ISqlSugarClient db, ICurrentUser currentUser) =>
await IsCompanyAdminUserAsync(db, currentUser)
|| await IsRegionalAdminUserAsync(db, currentUser)
- || await IsLocationAdminUserAsync(db, currentUser);
+ || await IsLocationTierUserAsync(db, currentUser);
///
/// 解析会话 scopeLevel:system > company > regional > location > staff。
@@ -279,7 +328,7 @@ public static class TeamMemberRoleHelper
return OrgScopeLevels.Regional;
}
- if (await IsLocationAdminUserAsync(db, currentUser))
+ if (await IsLocationTierUserAsync(db, currentUser))
{
return OrgScopeLevels.Location;
}
diff --git a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelAppService.cs b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelAppService.cs
index 9de6a9f..c89f36f 100644
--- a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelAppService.cs
+++ b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelAppService.cs
@@ -88,12 +88,12 @@ public class LabelAppService : ApplicationService, ILabelAppService
}
else if (!string.IsNullOrWhiteSpace(filterGroupId))
{
- labelIdsQuery = LabelRegionScopeHelper.ApplyLabelRegionListFilter(
+ labelIdsQuery = await LabelRegionScopeHelper.ApplyLabelRegionListFilterAsync(
db, labelIdsQuery, filterGroupId, scopedLocationIds, regionSchema);
}
else
{
- labelIdsQuery = LabelRegionScopeHelper.ApplyLabelLocationListFilter(
+ labelIdsQuery = await LabelRegionScopeHelper.ApplyLabelLocationListFilterAsync(
db, labelIdsQuery, scopedLocationIds, regionSchema);
}
}
@@ -111,7 +111,7 @@ public class LabelAppService : ApplicationService, ILabelAppService
}
else
{
- labelIdsQuery = LabelRegionScopeHelper.ApplyLabelLocationListFilter(
+ labelIdsQuery = await LabelRegionScopeHelper.ApplyLabelLocationListFilterAsync(
db, labelIdsQuery, scopedLocationIds, regionSchema);
}
}
@@ -187,6 +187,7 @@ public class LabelAppService : ApplicationService, ILabelAppService
l.LocationId,
l.PartnerId,
l.CreatorId,
+ l.LastModifierId,
LabelCategoryName = c.CategoryName,
LabelTypeName = t.TypeName,
TemplateName = tpl.TemplateName,
@@ -259,7 +260,10 @@ public class LabelAppService : ApplicationService, ILabelAppService
});
var manageCtx = await PartnerScopedManagePermissionHelper.BuildListContextAsync(
- CurrentUser, _dbContext, orderedLabels.Select(x => x.CreatorId));
+ CurrentUser,
+ _dbContext,
+ orderedLabels.Select(x => x.CreatorId),
+ orderedLabels.Select(x => x.LastModifierId));
var items = new List(orderedLabels.Count);
foreach (var x in orderedLabels)
@@ -287,7 +291,12 @@ public class LabelAppService : ApplicationService, ILabelAppService
Guid.TryParse(x.CreatorId?.Trim(), out var creatorGuid) &&
manageCtx.SystemAdminCreatorIds.Contains(creatorGuid);
var canManage = PartnerScopedManagePermissionHelper.EvaluateCanManage(
- CurrentUser, manageCtx, x.CreatorId, partnerIdsForManage);
+ CurrentUser,
+ manageCtx,
+ x.CreatorId,
+ partnerIdsForManage,
+ x.Id,
+ x.LastModifierId);
items.Add(new LabelGetListOutputDto
{
Id = x.LabelCode ?? string.Empty,
diff --git a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelCategoryAppService.cs b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelCategoryAppService.cs
index 7f21c6c..30d42eb 100644
--- a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelCategoryAppService.cs
+++ b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelCategoryAppService.cs
@@ -77,7 +77,7 @@ public class LabelCategoryAppService : ApplicationService, ILabelCategoryAppServ
ids);
var scopeMap = await BuildCategoryScopeMapAsync(entities, partnerScopeMap);
var manageCtx = await PartnerScopedManagePermissionHelper.BuildListContextAsync(
- CurrentUser, _dbContext, entities.Select(x => x.CreatorId));
+ CurrentUser, _dbContext, entities.Select(x => x.CreatorId), entities.Select(x => x.LastModifierId));
var items = entities.Select(x =>
{
@@ -97,7 +97,12 @@ public class LabelCategoryAppService : ApplicationService, ILabelCategoryAppServ
Guid.TryParse(x.CreatorId?.Trim(), out var creatorGuid) &&
manageCtx.SystemAdminCreatorIds.Contains(creatorGuid);
var canManage = PartnerScopedManagePermissionHelper.EvaluateCanManage(
- CurrentUser, manageCtx, x.CreatorId, partnerIdsForManage);
+ CurrentUser,
+ manageCtx,
+ x.CreatorId,
+ partnerIdsForManage,
+ x.Id,
+ x.LastModifierId);
return new LabelCategoryGetListOutputDto
{
Id = x.Id,
diff --git a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelMultipleOptionAppService.cs b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelMultipleOptionAppService.cs
index ed5194e..6a76014 100644
--- a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelMultipleOptionAppService.cs
+++ b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelMultipleOptionAppService.cs
@@ -66,9 +66,8 @@ public class LabelMultipleOptionAppService : ApplicationService, ILabelMultipleO
LabelEntityPartnerScopeHelper.LabelEntityPartnerKind.MultipleOption,
entities.Select(x => x.Id).ToList());
- var systemAdminCreatorIds = await TeamMemberRoleHelper.ResolveSystemAdminCreatorIdSetAsync(
- _dbContext.SqlSugarClient,
- entities.Select(x => x.CreatorId));
+ var manageCtx = await PartnerScopedManagePermissionHelper.BuildListContextAsync(
+ CurrentUser, _dbContext, entities.Select(x => x.CreatorId), entities.Select(x => x.LastModifierId));
var items = new List(entities.Count);
foreach (var x in entities)
@@ -76,11 +75,23 @@ public class LabelMultipleOptionAppService : ApplicationService, ILabelMultipleO
scopeMap.TryGetValue(x.Id, out var scope);
partnerScopeMap.TryGetValue(x.Id, out var partnerScope);
var partnerIds = partnerScope?.PartnerIds ?? new List();
+ var partnerIdsForManage = PartnerScopedManagePermissionHelper.ResolvePartnerScopedEntityPartnerIdsForManageFromEcho(
+ x.AvailabilityType,
+ x.AppliedRegionType,
+ partnerScope?.AppliedPartnerType ?? x.AppliedPartnerType,
+ scope?.RegionIds,
+ scope?.LocationIds,
+ partnerIds);
var createdBySystemAdmin =
Guid.TryParse(x.CreatorId?.Trim(), out var creatorGuid) &&
- systemAdminCreatorIds.Contains(creatorGuid);
- var canManage = await LabelMultipleOptionManagePermissionHelper.CanManageAsync(
- CurrentUser, _dbContext, partnerIds, createdBySystemAdmin);
+ manageCtx.SystemAdminCreatorIds.Contains(creatorGuid);
+ var canManage = PartnerScopedManagePermissionHelper.EvaluateCanManage(
+ CurrentUser,
+ manageCtx,
+ x.CreatorId,
+ partnerIdsForManage,
+ x.Id,
+ x.LastModifierId);
items.Add(new LabelMultipleOptionGetListOutputDto
{
diff --git a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelTemplateAppService.cs b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelTemplateAppService.cs
index 940acae..dae2b6d 100644
--- a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelTemplateAppService.cs
+++ b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelTemplateAppService.cs
@@ -122,19 +122,21 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ
? fromElements!
: (itemsDisplay?.Items ?? FoodLabelingDisplayConsts.NotAvailable);
var partnerIds = scope?.PartnerIds ?? new List();
+ var creatorIdForManage = PartnerScopedManagePermissionHelper.ResolveCreatorIdForPermission(
+ x.Id, x.CreatorId, x.LastModifierId);
var createdBySystemAdmin =
- Guid.TryParse(x.CreatorId?.Trim(), out var creatorGuid) &&
+ Guid.TryParse(creatorIdForManage?.Trim(), out var creatorGuid) &&
systemAdminCreatorIds.Contains(creatorGuid);
IReadOnlyList? creatorPartnerIds = null;
if (!createdBySystemAdmin &&
- Guid.TryParse(x.CreatorId?.Trim(), out var ownerGuid) &&
+ Guid.TryParse(creatorIdForManage?.Trim(), out var ownerGuid) &&
creatorPartnerMap.TryGetValue(ownerGuid, out var mappedCreatorPartners))
{
creatorPartnerIds = mappedCreatorPartners;
}
TeamMemberListAccessHelper.MemberRoleTier? creatorRoleTier = null;
- if (Guid.TryParse(x.CreatorId?.Trim(), out var parsedCreatorGuid)
+ if (Guid.TryParse(creatorIdForManage?.Trim(), out var parsedCreatorGuid)
&& creatorRoleTierMap.TryGetValue(parsedCreatorGuid, out var mappedCreatorTier))
{
creatorRoleTier = mappedCreatorTier;
@@ -147,9 +149,10 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ
createdBySystemAdmin,
currentPartnerScope.AllowedPartnerIds,
creatorPartnerIds,
- x.CreatorId,
+ creatorIdForManage,
viewerRoleTier,
- creatorRoleTier);
+ creatorRoleTier,
+ allowSelfCreatedWithoutConcretePartner: true);
items.Add(new LabelTemplateGetListOutputDto
{
diff --git a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelTypeAppService.cs b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelTypeAppService.cs
index 6ef23d0..b3993bb 100644
--- a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelTypeAppService.cs
+++ b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelTypeAppService.cs
@@ -74,7 +74,7 @@ public class LabelTypeAppService : ApplicationService, ILabelTypeAppService
LabelEntityPartnerScopeHelper.LabelEntityPartnerKind.Type,
ids);
var manageCtx = await PartnerScopedManagePermissionHelper.BuildListContextAsync(
- CurrentUser, _dbContext, entities.Select(x => x.CreatorId));
+ CurrentUser, _dbContext, entities.Select(x => x.CreatorId), entities.Select(x => x.LastModifierId));
var items = entities.Select(x =>
{
@@ -94,7 +94,12 @@ public class LabelTypeAppService : ApplicationService, ILabelTypeAppService
Guid.TryParse(x.CreatorId?.Trim(), out var creatorGuid) &&
manageCtx.SystemAdminCreatorIds.Contains(creatorGuid);
var canManage = PartnerScopedManagePermissionHelper.EvaluateCanManage(
- CurrentUser, manageCtx, x.CreatorId, partnerIdsForManage);
+ CurrentUser,
+ manageCtx,
+ x.CreatorId,
+ partnerIdsForManage,
+ x.Id,
+ x.LastModifierId);
return new LabelTypeGetListOutputDto
{
Id = x.Id,
@@ -532,12 +537,12 @@ public class LabelTypeAppService : ApplicationService, ILabelTypeAppService
}
else if (!string.IsNullOrWhiteSpace(filterGroupId))
{
- labelQuery = LabelRegionScopeHelper.ApplyLabelRegionListFilter(
+ labelQuery = await LabelRegionScopeHelper.ApplyLabelRegionListFilterAsync(
db, labelQuery, filterGroupId, scopedLocationIds, regionSchema);
}
else
{
- labelQuery = LabelRegionScopeHelper.ApplyLabelLocationListFilter(
+ labelQuery = await LabelRegionScopeHelper.ApplyLabelLocationListFilterAsync(
db, labelQuery, scopedLocationIds, regionSchema);
}
}
@@ -554,7 +559,7 @@ public class LabelTypeAppService : ApplicationService, ILabelTypeAppService
}
else
{
- labelQuery = LabelRegionScopeHelper.ApplyLabelLocationListFilter(
+ labelQuery = await LabelRegionScopeHelper.ApplyLabelLocationListFilterAsync(
db, labelQuery, scopedLocationIds, regionSchema);
}
}
diff --git a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/ProductAppService.cs b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/ProductAppService.cs
index dc5d889..f84a4f4 100644
--- a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/ProductAppService.cs
+++ b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/ProductAppService.cs
@@ -1115,7 +1115,9 @@ public class ProductAppService : ApplicationService, IProductAppService
throw new UserFriendlyException($"Multiple product categories match \"{n}\". Use a unique name in the system.");
}
- return matches[0].Id;
+ var matched = matches[0];
+ await ProductCategoryImportHelper.EnsureImportableCategoryCodeAsync(_dbContext.SqlSugarClient, matched);
+ return matched.Id;
}
private async Task ResolvePartnerIdFromImportCellAsync(string cell)
--
libgit2 0.21.4