Commit 9fb4d037d99f42fdb0d294ce2ed2e59d232232fd
1 parent
f7260db4
2026-11-13
Showing
16 changed files
with
401 additions
and
178 deletions
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/DashboardScopeHelper.cs
| @@ -203,7 +203,7 @@ public static class DashboardScopeHelper | @@ -203,7 +203,7 @@ public static class DashboardScopeHelper | ||
| 203 | db, labelQuery, regionSchema); | 203 | db, labelQuery, regionSchema); |
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | - return LabelRegionScopeHelper.ApplyLabelLocationListFilter( | 206 | + return await LabelRegionScopeHelper.ApplyLabelLocationListFilterAsync( |
| 207 | db, labelQuery, scopedLocationIds, regionSchema); | 207 | db, labelQuery, scopedLocationIds, regionSchema); |
| 208 | } | 208 | } |
| 209 | 209 |
美国版/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; | @@ -6,85 +6,21 @@ using Yi.Framework.SqlSugarCore.Abstractions; | ||
| 6 | namespace FoodLabeling.Application.Helpers; | 6 | namespace FoodLabeling.Application.Helpers; |
| 7 | 7 | ||
| 8 | /// <summary> | 8 | /// <summary> |
| 9 | -/// Multiple Option 编辑/删除权限: | ||
| 10 | -/// System Admin 可管理全部; | ||
| 11 | -/// Company Admin 仅可管理「非 System Admin 创建」且「适用本公司」的多选项。 | 9 | +/// Multiple Option 编辑/删除权限,与 <see cref="LabelTemplateManagePermissionHelper"/> / 标签分类等规则一致。 |
| 12 | /// </summary> | 10 | /// </summary> |
| 13 | public static class LabelMultipleOptionManagePermissionHelper | 11 | public static class LabelMultipleOptionManagePermissionHelper |
| 14 | { | 12 | { |
| 15 | - private const string ScopeAll = "ALL"; | ||
| 16 | - | ||
| 17 | - public static async Task<bool> CanManageAsync( | ||
| 18 | - ICurrentUser currentUser, | ||
| 19 | - ISqlSugarDbContext dbContext, | ||
| 20 | - IReadOnlyList<string>? partnerIds, | ||
| 21 | - bool createdBySystemAdmin) | ||
| 22 | - { | ||
| 23 | - if (ReportsRoleHelper.IsAdminRole(currentUser)) | ||
| 24 | - { | ||
| 25 | - return true; | ||
| 26 | - } | ||
| 27 | - | ||
| 28 | - if (!await TeamMemberRoleHelper.IsScopedAdminUserAsync(dbContext.SqlSugarClient, currentUser)) | ||
| 29 | - { | ||
| 30 | - return false; | ||
| 31 | - } | ||
| 32 | - | ||
| 33 | - if (createdBySystemAdmin) | ||
| 34 | - { | ||
| 35 | - return false; | ||
| 36 | - } | ||
| 37 | - | ||
| 38 | - var optionPartnerIds = (partnerIds ?? Array.Empty<string>()) | ||
| 39 | - .Select(x => x?.Trim()) | ||
| 40 | - .Where(x => !string.IsNullOrWhiteSpace(x)) | ||
| 41 | - .Select(x => x!) | ||
| 42 | - .ToList(); | ||
| 43 | - | ||
| 44 | - if (optionPartnerIds.Count == 0 || | ||
| 45 | - optionPartnerIds.Any(id => | ||
| 46 | - string.Equals(id, ScopeAll, StringComparison.OrdinalIgnoreCase))) | ||
| 47 | - { | ||
| 48 | - return false; | ||
| 49 | - } | ||
| 50 | - | ||
| 51 | - var scope = await PartnerScopeHelper.ResolvePartnerScopeAsync(currentUser, dbContext); | ||
| 52 | - if (scope.IsUnrestricted) | ||
| 53 | - { | ||
| 54 | - return true; | ||
| 55 | - } | ||
| 56 | - | ||
| 57 | - var allowed = scope.AllowedPartnerIds ?? Array.Empty<string>(); | ||
| 58 | - return optionPartnerIds.Any(pid => | ||
| 59 | - allowed.Any(a => string.Equals(a, pid, StringComparison.OrdinalIgnoreCase))); | ||
| 60 | - } | ||
| 61 | - | ||
| 62 | public static async Task EnsureCanManageAsync( | 13 | public static async Task EnsureCanManageAsync( |
| 63 | ICurrentUser currentUser, | 14 | ICurrentUser currentUser, |
| 64 | ISqlSugarDbContext dbContext, | 15 | ISqlSugarDbContext dbContext, |
| 65 | FlLabelMultipleOptionDbEntity entity) | 16 | FlLabelMultipleOptionDbEntity entity) |
| 66 | { | 17 | { |
| 67 | - var createdBySystemAdmin = false; | ||
| 68 | - if (!string.IsNullOrWhiteSpace(entity.CreatorId) && | ||
| 69 | - Guid.TryParse(entity.CreatorId.Trim(), out var creatorGuid)) | ||
| 70 | - { | ||
| 71 | - createdBySystemAdmin = await TeamMemberRoleHelper.IsSystemAdminUserAsync( | ||
| 72 | - dbContext.SqlSugarClient, creatorGuid); | ||
| 73 | - } | ||
| 74 | - | ||
| 75 | - var scopeMap = await LabelEntityPartnerScopeHelper.BuildPartnerScopeDisplayMapAsync( | ||
| 76 | - dbContext.SqlSugarClient, | 18 | + await PartnerScopedManagePermissionHelper.EnsureCanManagePartnerEntityAsync( |
| 19 | + currentUser, | ||
| 20 | + dbContext, | ||
| 77 | LabelEntityPartnerScopeHelper.LabelEntityPartnerKind.MultipleOption, | 21 | LabelEntityPartnerScopeHelper.LabelEntityPartnerKind.MultipleOption, |
| 78 | - new List<string> { entity.Id }); | ||
| 79 | - scopeMap.TryGetValue(entity.Id, out var scope); | ||
| 80 | - var partnerIds = scope?.PartnerIds ?? new List<string>(); | ||
| 81 | - | ||
| 82 | - if (await CanManageAsync(currentUser, dbContext, partnerIds, createdBySystemAdmin)) | ||
| 83 | - { | ||
| 84 | - return; | ||
| 85 | - } | ||
| 86 | - | ||
| 87 | - throw new UserFriendlyException( | 22 | + entity.Id, |
| 23 | + entity.CreatorId, | ||
| 88 | "You are not authorized to edit or delete this Multiple Option Set."); | 24 | "You are not authorized to edit or delete this Multiple Option Set."); |
| 89 | } | 25 | } |
| 90 | } | 26 | } |
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelRegionScopeHelper.cs
| @@ -617,7 +617,7 @@ public static class LabelRegionScopeHelper | @@ -617,7 +617,7 @@ public static class LabelRegionScopeHelper | ||
| 617 | /// <summary> | 617 | /// <summary> |
| 618 | /// ??? Region?<c>fl_group.Id</c>?? scoped ????? | 618 | /// ??? Region?<c>fl_group.Id</c>?? scoped ????? |
| 619 | /// </summary> | 619 | /// </summary> |
| 620 | - public static ISugarQueryable<FlLabelDbEntity> ApplyLabelRegionListFilter( | 620 | + public static async Task<ISugarQueryable<FlLabelDbEntity>> ApplyLabelRegionListFilterAsync( |
| 621 | ISqlSugarClient db, | 621 | ISqlSugarClient db, |
| 622 | ISugarQueryable<FlLabelDbEntity> query, | 622 | ISugarQueryable<FlLabelDbEntity> query, |
| 623 | string groupId, | 623 | string groupId, |
| @@ -630,14 +630,18 @@ public static class LabelRegionScopeHelper | @@ -630,14 +630,18 @@ public static class LabelRegionScopeHelper | ||
| 630 | return query.Where(_ => false); | 630 | return query.Where(_ => false); |
| 631 | } | 631 | } |
| 632 | 632 | ||
| 633 | + var scopedGroupIds = schema.HasLabelRegionTable | ||
| 634 | + ? await LocationScopeBindingHelper.ResolveGroupIdsFromLocationIdsAsync(db, scopedLocationIds) | ||
| 635 | + : new List<string>(); | ||
| 636 | + | ||
| 633 | if (!schema.HasLabelRegionTable && !schema.HasAppliedRegionTypeColumn) | 637 | if (!schema.HasLabelRegionTable && !schema.HasAppliedRegionTypeColumn) |
| 634 | { | 638 | { |
| 635 | - return ApplyLabelLocationMatchFilter(query, scopedLocationIds, schema); | 639 | + return ApplyLabelLocationMatchFilter(query, scopedLocationIds, scopedGroupIds, schema); |
| 636 | } | 640 | } |
| 637 | 641 | ||
| 638 | if (!schema.HasLabelRegionTable) | 642 | if (!schema.HasLabelRegionTable) |
| 639 | { | 643 | { |
| 640 | - return ApplyLabelLocationMatchFilter(query, scopedLocationIds, schema); | 644 | + return ApplyLabelLocationMatchFilter(query, scopedLocationIds, scopedGroupIds, schema); |
| 641 | } | 645 | } |
| 642 | 646 | ||
| 643 | if (!schema.HasAppliedRegionTypeColumn) | 647 | if (!schema.HasAppliedRegionTypeColumn) |
| @@ -772,7 +776,7 @@ public static class LabelRegionScopeHelper | @@ -772,7 +776,7 @@ public static class LabelRegionScopeHelper | ||
| 772 | /// 按 scoped 门店过滤。 | 776 | /// 按 scoped 门店过滤。 |
| 773 | /// <c>AppliedRegionType=ALL</c> 且无门店快照时为全局;有快照时须与 scoped 门店有交集(对齐 <see cref="LabelAppliesToLocationAsync"/>)。 | 777 | /// <c>AppliedRegionType=ALL</c> 且无门店快照时为全局;有快照时须与 scoped 门店有交集(对齐 <see cref="LabelAppliesToLocationAsync"/>)。 |
| 774 | /// </summary> | 778 | /// </summary> |
| 775 | - public static ISugarQueryable<FlLabelDbEntity> ApplyLabelLocationListFilter( | 779 | + public static async Task<ISugarQueryable<FlLabelDbEntity>> ApplyLabelLocationListFilterAsync( |
| 776 | ISqlSugarClient db, | 780 | ISqlSugarClient db, |
| 777 | ISugarQueryable<FlLabelDbEntity> query, | 781 | ISugarQueryable<FlLabelDbEntity> query, |
| 778 | List<string> scopedLocationIds, | 782 | List<string> scopedLocationIds, |
| @@ -783,7 +787,11 @@ public static class LabelRegionScopeHelper | @@ -783,7 +787,11 @@ public static class LabelRegionScopeHelper | ||
| 783 | return ApplyLabelAllRegionOnlyFilter(db, query, schema); | 787 | return ApplyLabelAllRegionOnlyFilter(db, query, schema); |
| 784 | } | 788 | } |
| 785 | 789 | ||
| 786 | - return ApplyLabelLocationMatchFilter(query, scopedLocationIds, schema); | 790 | + var scopedGroupIds = schema.HasLabelRegionTable |
| 791 | + ? await LocationScopeBindingHelper.ResolveGroupIdsFromLocationIdsAsync(db, scopedLocationIds) | ||
| 792 | + : new List<string>(); | ||
| 793 | + | ||
| 794 | + return ApplyLabelLocationMatchFilter(query, scopedLocationIds, scopedGroupIds, schema); | ||
| 787 | } | 795 | } |
| 788 | 796 | ||
| 789 | /// <summary> | 797 | /// <summary> |
| @@ -981,58 +989,92 @@ public static class LabelRegionScopeHelper | @@ -981,58 +989,92 @@ public static class LabelRegionScopeHelper | ||
| 981 | private static ISugarQueryable<FlLabelDbEntity> ApplyLabelLocationMatchFilter( | 989 | private static ISugarQueryable<FlLabelDbEntity> ApplyLabelLocationMatchFilter( |
| 982 | ISugarQueryable<FlLabelDbEntity> query, | 990 | ISugarQueryable<FlLabelDbEntity> query, |
| 983 | List<string> scopedLocationIds, | 991 | List<string> scopedLocationIds, |
| 992 | + IReadOnlyList<string> scopedGroupIds, | ||
| 984 | LabelRegionSchemaHelper.LabelRegionSchemaStatus schema) | 993 | LabelRegionSchemaHelper.LabelRegionSchemaStatus schema) |
| 985 | { | 994 | { |
| 995 | + var includeRegionMatch = schema.HasLabelRegionTable && scopedGroupIds.Count > 0; | ||
| 996 | + var specifiedBranch = BuildSpecifiedLocationRegionMatchSql( | ||
| 997 | + schema.HasLabelLocationTable, | ||
| 998 | + includeRegionMatch); | ||
| 999 | + | ||
| 986 | // 对齐 BuildAppLabelingTreeStoreFilterSql / LabelAppliesToLocationAsync: | 1000 | // 对齐 BuildAppLabelingTreeStoreFilterSql / LabelAppliesToLocationAsync: |
| 987 | // ALL 无门店快照 → 全局;ALL 有快照 → 须命中 scoped 门店(不可无条件放行,否则跨公司泄漏)。 | 1001 | // ALL 无门店快照 → 全局;ALL 有快照 → 须命中 scoped 门店(不可无条件放行,否则跨公司泄漏)。 |
| 1002 | + // SPECIFIED 仅 fl_label_region、无门店快照(Scoped ALL)→ 按 scoped 门店所属 Region 命中。 | ||
| 988 | if (schema.HasAppliedRegionTypeColumn && schema.HasLabelLocationTable) | 1003 | if (schema.HasAppliedRegionTypeColumn && schema.HasLabelLocationTable) |
| 989 | { | 1004 | { |
| 990 | return query.Where( | 1005 | return query.Where( |
| 991 | - """ | ||
| 992 | - ( | ||
| 993 | - (AppliedRegionType = @all AND ( | ||
| 994 | - ((LocationId IS NULL OR LocationId = '') | ||
| 995 | - AND NOT EXISTS (SELECT 1 FROM fl_label_location ll0 WHERE ll0.LabelId = fl_label.Id)) | ||
| 996 | - OR LocationId IN (@locs) | ||
| 997 | - OR EXISTS (SELECT 1 FROM fl_label_location ll WHERE ll.LabelId = fl_label.Id AND ll.LocationId IN (@locs)) | ||
| 998 | - )) | ||
| 999 | - OR (AppliedRegionType <> @all AND ( | ||
| 1000 | - LocationId IN (@locs) | ||
| 1001 | - OR EXISTS (SELECT 1 FROM fl_label_location ll WHERE ll.LabelId = fl_label.Id AND ll.LocationId IN (@locs)) | ||
| 1002 | - )) | ||
| 1003 | - ) | ||
| 1004 | - """, | ||
| 1005 | - new { all = AppliedRegionAll, locs = scopedLocationIds }); | 1006 | + $""" |
| 1007 | + ( | ||
| 1008 | + (AppliedRegionType = @all AND ( | ||
| 1009 | + ((LocationId IS NULL OR LocationId = '') | ||
| 1010 | + AND NOT EXISTS (SELECT 1 FROM fl_label_location ll0 WHERE ll0.LabelId = fl_label.Id)) | ||
| 1011 | + OR LocationId IN (@locs) | ||
| 1012 | + OR EXISTS (SELECT 1 FROM fl_label_location ll WHERE ll.LabelId = fl_label.Id AND ll.LocationId IN (@locs)) | ||
| 1013 | + )) | ||
| 1014 | + OR (AppliedRegionType <> @all AND ({specifiedBranch})) | ||
| 1015 | + ) | ||
| 1016 | + """, | ||
| 1017 | + new | ||
| 1018 | + { | ||
| 1019 | + all = AppliedRegionAll, | ||
| 1020 | + locs = scopedLocationIds, | ||
| 1021 | + scopedGroupIds | ||
| 1022 | + }); | ||
| 1006 | } | 1023 | } |
| 1007 | 1024 | ||
| 1008 | if (schema.HasAppliedRegionTypeColumn) | 1025 | if (schema.HasAppliedRegionTypeColumn) |
| 1009 | { | 1026 | { |
| 1027 | + var specifiedOnlyLocations = includeRegionMatch | ||
| 1028 | + ? specifiedBranch | ||
| 1029 | + : "LocationId IN (@locs)"; | ||
| 1010 | return query.Where( | 1030 | return query.Where( |
| 1011 | - """ | ||
| 1012 | - ( | ||
| 1013 | - (AppliedRegionType = @all AND ( | ||
| 1014 | - (LocationId IS NULL OR LocationId = '') | ||
| 1015 | - OR LocationId IN (@locs) | ||
| 1016 | - )) | ||
| 1017 | - OR (AppliedRegionType <> @all AND LocationId IN (@locs)) | ||
| 1018 | - ) | ||
| 1019 | - """, | ||
| 1020 | - new { all = AppliedRegionAll, locs = scopedLocationIds }); | 1031 | + $""" |
| 1032 | + ( | ||
| 1033 | + (AppliedRegionType = @all AND ( | ||
| 1034 | + (LocationId IS NULL OR LocationId = '') | ||
| 1035 | + OR LocationId IN (@locs) | ||
| 1036 | + )) | ||
| 1037 | + OR (AppliedRegionType <> @all AND ({specifiedOnlyLocations})) | ||
| 1038 | + ) | ||
| 1039 | + """, | ||
| 1040 | + new | ||
| 1041 | + { | ||
| 1042 | + all = AppliedRegionAll, | ||
| 1043 | + locs = scopedLocationIds, | ||
| 1044 | + scopedGroupIds | ||
| 1045 | + }); | ||
| 1021 | } | 1046 | } |
| 1022 | 1047 | ||
| 1023 | if (schema.HasLabelLocationTable) | 1048 | if (schema.HasLabelLocationTable) |
| 1024 | { | 1049 | { |
| 1025 | return query.Where( | 1050 | return query.Where( |
| 1026 | - """ | ||
| 1027 | - (LocationId IN (@locs) | ||
| 1028 | - OR EXISTS (SELECT 1 FROM fl_label_location ll WHERE ll.LabelId = fl_label.Id AND ll.LocationId IN (@locs))) | 1051 | + $""" |
| 1052 | + ({specifiedBranch}) | ||
| 1029 | """, | 1053 | """, |
| 1030 | - new { locs = scopedLocationIds }); | 1054 | + new { locs = scopedLocationIds, scopedGroupIds }); |
| 1031 | } | 1055 | } |
| 1032 | 1056 | ||
| 1033 | return query.Where(l => scopedLocationIds.Contains(l.LocationId)); | 1057 | return query.Where(l => scopedLocationIds.Contains(l.LocationId)); |
| 1034 | } | 1058 | } |
| 1035 | 1059 | ||
| 1060 | + private static string BuildSpecifiedLocationRegionMatchSql(bool hasLabelLocationTable, bool includeRegionMatch) | ||
| 1061 | + { | ||
| 1062 | + var parts = new List<string> { "LocationId IN (@locs)" }; | ||
| 1063 | + if (hasLabelLocationTable) | ||
| 1064 | + { | ||
| 1065 | + parts.Add( | ||
| 1066 | + "EXISTS (SELECT 1 FROM fl_label_location ll WHERE ll.LabelId = fl_label.Id AND ll.LocationId IN (@locs))"); | ||
| 1067 | + } | ||
| 1068 | + | ||
| 1069 | + if (includeRegionMatch) | ||
| 1070 | + { | ||
| 1071 | + parts.Add( | ||
| 1072 | + "EXISTS (SELECT 1 FROM fl_label_region lr WHERE lr.LabelId = fl_label.Id AND lr.GroupId IN (@scopedGroupIds))"); | ||
| 1073 | + } | ||
| 1074 | + | ||
| 1075 | + return string.Join(" OR ", parts); | ||
| 1076 | + } | ||
| 1077 | + | ||
| 1036 | private static List<string> MergeExplicitLocationIds(string? locationId, IReadOnlyList<string>? locationIds) | 1078 | private static List<string> MergeExplicitLocationIds(string? locationId, IReadOnlyList<string>? locationIds) |
| 1037 | { | 1079 | { |
| 1038 | var merged = LocationScopeBindingHelper.NormalizeIds(locationIds); | 1080 | var merged = LocationScopeBindingHelper.NormalizeIds(locationIds); |
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelTemplateManagePermissionHelper.cs
| @@ -61,7 +61,8 @@ public static class LabelTemplateManagePermissionHelper | @@ -61,7 +61,8 @@ public static class LabelTemplateManagePermissionHelper | ||
| 61 | creatorPartners, | 61 | creatorPartners, |
| 62 | template.CreatorId, | 62 | template.CreatorId, |
| 63 | viewerTier, | 63 | viewerTier, |
| 64 | - creatorTier); | 64 | + creatorTier, |
| 65 | + allowSelfCreatedWithoutConcretePartner: true); | ||
| 65 | } | 66 | } |
| 66 | 67 | ||
| 67 | /// <summary> | 68 | /// <summary> |
| @@ -103,23 +104,37 @@ public static class LabelTemplateManagePermissionHelper | @@ -103,23 +104,37 @@ public static class LabelTemplateManagePermissionHelper | ||
| 103 | return false; | 104 | return false; |
| 104 | } | 105 | } |
| 105 | 106 | ||
| 107 | + // 创建者角色更高(System/Company 相对 Regional/Location)→ 下级不可管。 | ||
| 106 | if (IsCreatorRoleSuperiorToViewer(creatorRoleTier, viewerRoleTier)) | 108 | if (IsCreatorRoleSuperiorToViewer(creatorRoleTier, viewerRoleTier)) |
| 107 | { | 109 | { |
| 108 | return false; | 110 | return false; |
| 109 | } | 111 | } |
| 110 | 112 | ||
| 113 | + var creatorPartners = NormalizeIds(creatorPartnerIds); | ||
| 114 | + var allowed = NormalizeIds(allowedPartnerIds); | ||
| 115 | + | ||
| 116 | + // 上级编辑下级创建:只要创建人落在查看者公司范围内即可。 | ||
| 117 | + // 下级常把 Region/Location 设为 ALL,权限用 partnerIds 会被算成空而误拒。 | ||
| 118 | + if (IsViewerRoleSuperiorToCreator(viewerRoleTier, creatorRoleTier)) | ||
| 119 | + { | ||
| 120 | + if (creatorPartners.Count == 0 || allowed.Count == 0) | ||
| 121 | + { | ||
| 122 | + return false; | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + return creatorPartners.Any(pid => ContainsId(allowed, pid)); | ||
| 126 | + } | ||
| 127 | + | ||
| 111 | if (!MeetsPartnerScopeForManage(partnerIds, allowedPartnerIds, allowEmptyPartnerIds: false)) | 128 | if (!MeetsPartnerScopeForManage(partnerIds, allowedPartnerIds, allowEmptyPartnerIds: false)) |
| 112 | { | 129 | { |
| 113 | return false; | 130 | return false; |
| 114 | } | 131 | } |
| 115 | 132 | ||
| 116 | - var creatorPartners = NormalizeIds(creatorPartnerIds); | ||
| 117 | if (creatorPartners.Count == 0) | 133 | if (creatorPartners.Count == 0) |
| 118 | { | 134 | { |
| 119 | return false; | 135 | return false; |
| 120 | } | 136 | } |
| 121 | 137 | ||
| 122 | - var allowed = NormalizeIds(allowedPartnerIds); | ||
| 123 | return creatorPartners.Any(pid => ContainsId(allowed, pid)); | 138 | return creatorPartners.Any(pid => ContainsId(allowed, pid)); |
| 124 | } | 139 | } |
| 125 | 140 | ||
| @@ -161,6 +176,19 @@ public static class LabelTemplateManagePermissionHelper | @@ -161,6 +176,19 @@ public static class LabelTemplateManagePermissionHelper | ||
| 161 | return creatorRoleTier.Value < viewerRoleTier.Value; | 176 | return creatorRoleTier.Value < viewerRoleTier.Value; |
| 162 | } | 177 | } |
| 163 | 178 | ||
| 179 | + /// <summary>查看者层级更高(数值更小)于创建者 → 上级可管下级创建的项目。</summary> | ||
| 180 | + private static bool IsViewerRoleSuperiorToCreator( | ||
| 181 | + TeamMemberListAccessHelper.MemberRoleTier? viewerRoleTier, | ||
| 182 | + TeamMemberListAccessHelper.MemberRoleTier? creatorRoleTier) | ||
| 183 | + { | ||
| 184 | + if (creatorRoleTier is null || viewerRoleTier is null) | ||
| 185 | + { | ||
| 186 | + return false; | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + return viewerRoleTier.Value < creatorRoleTier.Value; | ||
| 190 | + } | ||
| 191 | + | ||
| 164 | private static bool MeetsPartnerScopeForManage( | 192 | private static bool MeetsPartnerScopeForManage( |
| 165 | IReadOnlyList<string>? partnerIds, | 193 | IReadOnlyList<string>? partnerIds, |
| 166 | IReadOnlyList<string>? allowedPartnerIds, | 194 | IReadOnlyList<string>? allowedPartnerIds, |
| @@ -197,9 +225,12 @@ public static class LabelTemplateManagePermissionHelper | @@ -197,9 +225,12 @@ public static class LabelTemplateManagePermissionHelper | ||
| 197 | ISqlSugarDbContext dbContext, | 225 | ISqlSugarDbContext dbContext, |
| 198 | FlLabelTemplateDbEntity template) | 226 | FlLabelTemplateDbEntity template) |
| 199 | { | 227 | { |
| 228 | + var creatorIdForManage = PartnerScopedManagePermissionHelper.ResolveCreatorIdForPermission( | ||
| 229 | + template.Id, template.CreatorId, template.LastModifierId); | ||
| 230 | + | ||
| 200 | var createdBySystemAdmin = false; | 231 | var createdBySystemAdmin = false; |
| 201 | - if (!string.IsNullOrWhiteSpace(template.CreatorId) && | ||
| 202 | - Guid.TryParse(template.CreatorId.Trim(), out var creatorGuid)) | 232 | + if (!string.IsNullOrWhiteSpace(creatorIdForManage) && |
| 233 | + Guid.TryParse(creatorIdForManage.Trim(), out var creatorGuid)) | ||
| 203 | { | 234 | { |
| 204 | createdBySystemAdmin = await TeamMemberRoleHelper.IsSystemAdminUserAsync( | 235 | createdBySystemAdmin = await TeamMemberRoleHelper.IsSystemAdminUserAsync( |
| 205 | dbContext.SqlSugarClient, creatorGuid); | 236 | dbContext.SqlSugarClient, creatorGuid); |
| @@ -212,14 +243,14 @@ public static class LabelTemplateManagePermissionHelper | @@ -212,14 +243,14 @@ public static class LabelTemplateManagePermissionHelper | ||
| 212 | var partnerIds = scope?.PartnerIds ?? new List<string>(); | 243 | var partnerIds = scope?.PartnerIds ?? new List<string>(); |
| 213 | 244 | ||
| 214 | var (viewerTier, creatorTier) = await ResolveManageRoleTiersAsync( | 245 | var (viewerTier, creatorTier) = await ResolveManageRoleTiersAsync( |
| 215 | - dbContext.SqlSugarClient, currentUser, template.CreatorId); | 246 | + dbContext.SqlSugarClient, currentUser, creatorIdForManage); |
| 216 | 247 | ||
| 217 | var isScopedAdmin = await TeamMemberRoleHelper.IsScopedAdminUserAsync( | 248 | var isScopedAdmin = await TeamMemberRoleHelper.IsScopedAdminUserAsync( |
| 218 | dbContext.SqlSugarClient, currentUser); | 249 | dbContext.SqlSugarClient, currentUser); |
| 219 | var partnerScope = await PartnerScopeHelper.ResolvePartnerScopeAsync(currentUser, dbContext); | 250 | var partnerScope = await PartnerScopeHelper.ResolvePartnerScopeAsync(currentUser, dbContext); |
| 220 | IReadOnlyList<string>? creatorPartnerIds = null; | 251 | IReadOnlyList<string>? creatorPartnerIds = null; |
| 221 | if (!createdBySystemAdmin && | 252 | if (!createdBySystemAdmin && |
| 222 | - Guid.TryParse(template.CreatorId?.Trim(), out var ownerGuid)) | 253 | + Guid.TryParse(creatorIdForManage?.Trim(), out var ownerGuid)) |
| 223 | { | 254 | { |
| 224 | creatorPartnerIds = await PartnerScopeHelper.ResolvePartnerIdsForUserAsync( | 255 | creatorPartnerIds = await PartnerScopeHelper.ResolvePartnerIdsForUserAsync( |
| 225 | dbContext.SqlSugarClient, ownerGuid); | 256 | dbContext.SqlSugarClient, ownerGuid); |
| @@ -232,9 +263,10 @@ public static class LabelTemplateManagePermissionHelper | @@ -232,9 +263,10 @@ public static class LabelTemplateManagePermissionHelper | ||
| 232 | createdBySystemAdmin, | 263 | createdBySystemAdmin, |
| 233 | partnerScope.AllowedPartnerIds, | 264 | partnerScope.AllowedPartnerIds, |
| 234 | creatorPartnerIds, | 265 | creatorPartnerIds, |
| 235 | - template.CreatorId, | 266 | + creatorIdForManage, |
| 236 | viewerTier, | 267 | viewerTier, |
| 237 | - creatorTier)) | 268 | + creatorTier, |
| 269 | + allowSelfCreatedWithoutConcretePartner: true)) | ||
| 238 | { | 270 | { |
| 239 | return; | 271 | return; |
| 240 | } | 272 | } |
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/PartnerScopedManagePermissionHelper.cs
| @@ -29,16 +29,22 @@ public static class PartnerScopedManagePermissionHelper | @@ -29,16 +29,22 @@ public static class PartnerScopedManagePermissionHelper | ||
| 29 | public static async Task<ListEvaluationContext> BuildListContextAsync( | 29 | public static async Task<ListEvaluationContext> BuildListContextAsync( |
| 30 | ICurrentUser currentUser, | 30 | ICurrentUser currentUser, |
| 31 | ISqlSugarDbContext dbContext, | 31 | ISqlSugarDbContext dbContext, |
| 32 | - IEnumerable<string?> creatorIds) | 32 | + IEnumerable<string?> creatorIds, |
| 33 | + IEnumerable<string?>? fallbackUserIds = null) | ||
| 33 | { | 34 | { |
| 35 | + // 合并 CreatorId + LastModifierId:脏数据 CreatorId=实体Id 时,矫正后仍能命中公司/层级 map。 | ||
| 36 | + var allUserIds = (creatorIds ?? Array.Empty<string?>()) | ||
| 37 | + .Concat(fallbackUserIds ?? Array.Empty<string?>()) | ||
| 38 | + .ToList(); | ||
| 39 | + | ||
| 34 | var isScopedAdmin = await TeamMemberRoleHelper.IsScopedAdminUserAsync( | 40 | var isScopedAdmin = await TeamMemberRoleHelper.IsScopedAdminUserAsync( |
| 35 | dbContext.SqlSugarClient, currentUser); | 41 | dbContext.SqlSugarClient, currentUser); |
| 36 | var currentPartnerScope = await PartnerScopeHelper.ResolvePartnerScopeAsync(currentUser, dbContext); | 42 | var currentPartnerScope = await PartnerScopeHelper.ResolvePartnerScopeAsync(currentUser, dbContext); |
| 37 | var systemAdminCreatorIds = await TeamMemberRoleHelper.ResolveSystemAdminCreatorIdSetAsync( | 43 | var systemAdminCreatorIds = await TeamMemberRoleHelper.ResolveSystemAdminCreatorIdSetAsync( |
| 38 | - dbContext.SqlSugarClient, creatorIds); | 44 | + dbContext.SqlSugarClient, allUserIds); |
| 39 | 45 | ||
| 40 | var creatorPartnerMap = new Dictionary<Guid, IReadOnlyList<string>>(); | 46 | var creatorPartnerMap = new Dictionary<Guid, IReadOnlyList<string>>(); |
| 41 | - foreach (var creatorId in creatorIds | 47 | + foreach (var creatorId in allUserIds |
| 42 | .Select(id => Guid.TryParse(id?.Trim(), out var g) ? g : (Guid?)null) | 48 | .Select(id => Guid.TryParse(id?.Trim(), out var g) ? g : (Guid?)null) |
| 43 | .Where(g => g.HasValue) | 49 | .Where(g => g.HasValue) |
| 44 | .Select(g => g!.Value) | 50 | .Select(g => g!.Value) |
| @@ -53,7 +59,7 @@ public static class PartnerScopedManagePermissionHelper | @@ -53,7 +59,7 @@ public static class PartnerScopedManagePermissionHelper | ||
| 53 | dbContext.SqlSugarClient, creatorId); | 59 | dbContext.SqlSugarClient, creatorId); |
| 54 | } | 60 | } |
| 55 | 61 | ||
| 56 | - var creatorGuids = creatorIds | 62 | + var creatorGuids = allUserIds |
| 57 | .Select(id => Guid.TryParse(id?.Trim(), out var g) ? g : (Guid?)null) | 63 | .Select(id => Guid.TryParse(id?.Trim(), out var g) ? g : (Guid?)null) |
| 58 | .Where(g => g.HasValue) | 64 | .Where(g => g.HasValue) |
| 59 | .Select(g => g!.Value) | 65 | .Select(g => g!.Value) |
| @@ -80,12 +86,44 @@ public static class PartnerScopedManagePermissionHelper | @@ -80,12 +86,44 @@ public static class PartnerScopedManagePermissionHelper | ||
| 80 | }; | 86 | }; |
| 81 | } | 87 | } |
| 82 | 88 | ||
| 89 | + /// <summary> | ||
| 90 | + /// 当库里误将 <c>CreatorId</c> 写成实体主键时,用 <c>LastModifierId</c> 参与权限判定(常见于历史脏数据)。 | ||
| 91 | + /// </summary> | ||
| 92 | + public static string? ResolveCreatorIdForPermission( | ||
| 93 | + string? entityId, | ||
| 94 | + string? creatorId, | ||
| 95 | + string? lastModifierId) | ||
| 96 | + { | ||
| 97 | + if (string.IsNullOrWhiteSpace(creatorId)) | ||
| 98 | + { | ||
| 99 | + return creatorId; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + var normalizedCreator = creatorId.Trim(); | ||
| 103 | + if (string.IsNullOrWhiteSpace(entityId) | ||
| 104 | + || !string.Equals(normalizedCreator, entityId.Trim(), StringComparison.OrdinalIgnoreCase)) | ||
| 105 | + { | ||
| 106 | + return normalizedCreator; | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + if (!string.IsNullOrWhiteSpace(lastModifierId) | ||
| 110 | + && !string.Equals(lastModifierId.Trim(), entityId.Trim(), StringComparison.OrdinalIgnoreCase)) | ||
| 111 | + { | ||
| 112 | + return lastModifierId.Trim(); | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + return normalizedCreator; | ||
| 116 | + } | ||
| 117 | + | ||
| 83 | public static bool EvaluateCanManage( | 118 | public static bool EvaluateCanManage( |
| 84 | ICurrentUser currentUser, | 119 | ICurrentUser currentUser, |
| 85 | ListEvaluationContext context, | 120 | ListEvaluationContext context, |
| 86 | string? creatorId, | 121 | string? creatorId, |
| 87 | - IReadOnlyList<string>? partnerIds) | 122 | + IReadOnlyList<string>? partnerIds, |
| 123 | + string? entityId = null, | ||
| 124 | + string? lastModifierId = null) | ||
| 88 | { | 125 | { |
| 126 | + creatorId = ResolveCreatorIdForPermission(entityId, creatorId, lastModifierId); | ||
| 89 | var createdBySystemAdmin = | 127 | var createdBySystemAdmin = |
| 90 | Guid.TryParse(creatorId?.Trim(), out var creatorGuid) && | 128 | Guid.TryParse(creatorId?.Trim(), out var creatorGuid) && |
| 91 | context.SystemAdminCreatorIds.Contains(creatorGuid); | 129 | context.SystemAdminCreatorIds.Contains(creatorGuid); |
| @@ -198,10 +236,15 @@ public static class PartnerScopedManagePermissionHelper | @@ -198,10 +236,15 @@ public static class PartnerScopedManagePermissionHelper | ||
| 198 | locationIdsForEcho: null, | 236 | locationIdsForEcho: null, |
| 199 | partnerIdsForEcho); | 237 | partnerIdsForEcho); |
| 200 | 238 | ||
| 239 | + var creatorForManage = ResolveCreatorIdForPermission( | ||
| 240 | + entityId, | ||
| 241 | + entityScope.CreatorId ?? creatorId, | ||
| 242 | + entityScope.LastModifierId); | ||
| 243 | + | ||
| 201 | await EnsureCanManageAsync( | 244 | await EnsureCanManageAsync( |
| 202 | currentUser, | 245 | currentUser, |
| 203 | dbContext, | 246 | dbContext, |
| 204 | - entityScope.CreatorId ?? creatorId, | 247 | + creatorForManage, |
| 205 | partnerIdsForManage, | 248 | partnerIdsForManage, |
| 206 | unauthorizedMessage); | 249 | unauthorizedMessage); |
| 207 | } | 250 | } |
| @@ -322,6 +365,8 @@ public static class PartnerScopedManagePermissionHelper | @@ -322,6 +365,8 @@ public static class PartnerScopedManagePermissionHelper | ||
| 322 | public string AppliedPartnerType { get; init; } = AllScopeBindingHelper.ScopeAll; | 365 | public string AppliedPartnerType { get; init; } = AllScopeBindingHelper.ScopeAll; |
| 323 | 366 | ||
| 324 | public string? CreatorId { get; init; } | 367 | public string? CreatorId { get; init; } |
| 368 | + | ||
| 369 | + public string? LastModifierId { get; init; } | ||
| 325 | } | 370 | } |
| 326 | 371 | ||
| 327 | private static async Task<PartnerScopedEntityScopeRow?> LoadPartnerScopedEntityScopeAsync( | 372 | private static async Task<PartnerScopedEntityScopeRow?> LoadPartnerScopedEntityScopeAsync( |
| @@ -339,7 +384,8 @@ public static class PartnerScopedManagePermissionHelper | @@ -339,7 +384,8 @@ public static class PartnerScopedManagePermissionHelper | ||
| 339 | AvailabilityType = x.AvailabilityType, | 384 | AvailabilityType = x.AvailabilityType, |
| 340 | AppliedRegionType = x.AppliedRegionType, | 385 | AppliedRegionType = x.AppliedRegionType, |
| 341 | AppliedPartnerType = x.AppliedPartnerType, | 386 | AppliedPartnerType = x.AppliedPartnerType, |
| 342 | - CreatorId = x.CreatorId | 387 | + CreatorId = x.CreatorId, |
| 388 | + LastModifierId = x.LastModifierId | ||
| 343 | }) | 389 | }) |
| 344 | .FirstAsync(); | 390 | .FirstAsync(); |
| 345 | return productCategory; | 391 | return productCategory; |
| @@ -351,7 +397,8 @@ public static class PartnerScopedManagePermissionHelper | @@ -351,7 +397,8 @@ public static class PartnerScopedManagePermissionHelper | ||
| 351 | AvailabilityType = x.AvailabilityType, | 397 | AvailabilityType = x.AvailabilityType, |
| 352 | AppliedRegionType = x.AppliedRegionType, | 398 | AppliedRegionType = x.AppliedRegionType, |
| 353 | AppliedPartnerType = x.AppliedPartnerType, | 399 | AppliedPartnerType = x.AppliedPartnerType, |
| 354 | - CreatorId = x.CreatorId | 400 | + CreatorId = x.CreatorId, |
| 401 | + LastModifierId = x.LastModifierId | ||
| 355 | }) | 402 | }) |
| 356 | .FirstAsync(); | 403 | .FirstAsync(); |
| 357 | return labelCategory; | 404 | return labelCategory; |
| @@ -363,10 +410,24 @@ public static class PartnerScopedManagePermissionHelper | @@ -363,10 +410,24 @@ public static class PartnerScopedManagePermissionHelper | ||
| 363 | AvailabilityType = x.AvailabilityType, | 410 | AvailabilityType = x.AvailabilityType, |
| 364 | AppliedRegionType = x.AppliedRegionType, | 411 | AppliedRegionType = x.AppliedRegionType, |
| 365 | AppliedPartnerType = x.AppliedPartnerType, | 412 | AppliedPartnerType = x.AppliedPartnerType, |
| 366 | - CreatorId = x.CreatorId | 413 | + CreatorId = x.CreatorId, |
| 414 | + LastModifierId = x.LastModifierId | ||
| 367 | }) | 415 | }) |
| 368 | .FirstAsync(); | 416 | .FirstAsync(); |
| 369 | return labelType; | 417 | return labelType; |
| 418 | + case LabelEntityPartnerScopeHelper.LabelEntityPartnerKind.MultipleOption: | ||
| 419 | + var multipleOption = await db.Queryable<FlLabelMultipleOptionDbEntity>() | ||
| 420 | + .Where(x => x.Id == entityId && !x.IsDeleted) | ||
| 421 | + .Select(x => new PartnerScopedEntityScopeRow | ||
| 422 | + { | ||
| 423 | + AvailabilityType = x.AvailabilityType, | ||
| 424 | + AppliedRegionType = x.AppliedRegionType, | ||
| 425 | + AppliedPartnerType = x.AppliedPartnerType, | ||
| 426 | + CreatorId = x.CreatorId, | ||
| 427 | + LastModifierId = x.LastModifierId | ||
| 428 | + }) | ||
| 429 | + .FirstAsync(); | ||
| 430 | + return multipleOption; | ||
| 370 | default: | 431 | default: |
| 371 | return null; | 432 | return null; |
| 372 | } | 433 | } |
| @@ -394,6 +455,11 @@ public static class PartnerScopedManagePermissionHelper | @@ -394,6 +455,11 @@ public static class PartnerScopedManagePermissionHelper | ||
| 394 | .Where(x => x.LabelTypeId == entityId) | 455 | .Where(x => x.LabelTypeId == entityId) |
| 395 | .Select(x => x.LocationId) | 456 | .Select(x => x.LocationId) |
| 396 | .ToListAsync(); | 457 | .ToListAsync(); |
| 458 | + case LabelEntityPartnerScopeHelper.LabelEntityPartnerKind.MultipleOption: | ||
| 459 | + return await db.Queryable<FlLabelMultipleOptionLocationDbEntity>() | ||
| 460 | + .Where(x => x.MultipleOptionId == entityId) | ||
| 461 | + .Select(x => x.LocationId) | ||
| 462 | + .ToListAsync(); | ||
| 397 | default: | 463 | default: |
| 398 | return new List<string>(); | 464 | return new List<string>(); |
| 399 | } | 465 | } |
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/ProductCategoryImportHelper.cs
0 → 100644
| 1 | +using FoodLabeling.Application.Services.DbModels; | ||
| 2 | +using SqlSugar; | ||
| 3 | + | ||
| 4 | +namespace FoodLabeling.Application.Helpers; | ||
| 5 | + | ||
| 6 | +/// <summary> | ||
| 7 | +/// 产品批量导入:分类解析与空 <c>CategoryCode</c> 回填(产品仅落库 <c>CategoryId</c>)。 | ||
| 8 | +/// </summary> | ||
| 9 | +public static class ProductCategoryImportHelper | ||
| 10 | +{ | ||
| 11 | + /// <summary> | ||
| 12 | + /// 分类 <c>CategoryCode</c> 为空时,按主键生成稳定编码,避免列表/报表仅展示空编码而关联实际已通过 Id 建立。 | ||
| 13 | + /// </summary> | ||
| 14 | + public static async Task EnsureImportableCategoryCodeAsync(ISqlSugarClient db, FlProductCategoryDbEntity category) | ||
| 15 | + { | ||
| 16 | + if (category is null || !string.IsNullOrWhiteSpace(category.CategoryCode)) | ||
| 17 | + { | ||
| 18 | + return; | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + var code = BuildStableCategoryCode(category.Id); | ||
| 22 | + var exists = await db.Queryable<FlProductCategoryDbEntity>() | ||
| 23 | + .AnyAsync(x => !x.IsDeleted && x.Id != category.Id && x.CategoryCode == code); | ||
| 24 | + if (exists) | ||
| 25 | + { | ||
| 26 | + code = $"CAT_{category.Id.Replace("-", string.Empty, StringComparison.Ordinal).ToLowerInvariant()}"; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + await db.Updateable<FlProductCategoryDbEntity>() | ||
| 30 | + .SetColumns(x => new FlProductCategoryDbEntity { CategoryCode = code }) | ||
| 31 | + .Where(x => x.Id == category.Id) | ||
| 32 | + .ExecuteCommandAsync(); | ||
| 33 | + category.CategoryCode = code; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + private static string BuildStableCategoryCode(string categoryId) | ||
| 37 | + { | ||
| 38 | + var compact = categoryId.Replace("-", string.Empty, StringComparison.Ordinal).ToLowerInvariant(); | ||
| 39 | + var suffix = compact.Length <= 16 ? compact : compact[..16]; | ||
| 40 | + return $"CAT_{suffix}"; | ||
| 41 | + } | ||
| 42 | +} |
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/ProductCategoryNameMatchHelper.cs
| @@ -5,7 +5,7 @@ using SqlSugar; | @@ -5,7 +5,7 @@ using SqlSugar; | ||
| 5 | namespace FoodLabeling.Application.Helpers; | 5 | namespace FoodLabeling.Application.Helpers; |
| 6 | 6 | ||
| 7 | /// <summary> | 7 | /// <summary> |
| 8 | -/// 产品分类名称匹配(导入 Excel 与库中简繁/空格差异)。 | 8 | +/// 产品分类名称匹配(导入 Excel 与库中简繁/空格差异;支持名称、编码、展示文案)。 |
| 9 | /// </summary> | 9 | /// </summary> |
| 10 | public static class ProductCategoryNameMatchHelper | 10 | public static class ProductCategoryNameMatchHelper |
| 11 | { | 11 | { |
| @@ -20,15 +20,11 @@ public static class ProductCategoryNameMatchHelper | @@ -20,15 +20,11 @@ public static class ProductCategoryNameMatchHelper | ||
| 20 | return new List<FlProductCategoryDbEntity>(); | 20 | return new List<FlProductCategoryDbEntity>(); |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | - var categories = await db.Queryable<FlProductCategoryDbEntity>() | ||
| 24 | - .Where(x => !x.IsDeleted) | ||
| 25 | - .ToListAsync(); | ||
| 26 | - | ||
| 27 | - categories = await NarrowCategoriesByPartnerAsync(db, categories, partnerId); | ||
| 28 | - | 23 | + var categories = await LoadPartnerScopedCategoriesAsync(db, partnerId); |
| 29 | var key = NormalizeNameKey(n); | 24 | var key = NormalizeNameKey(n); |
| 25 | + | ||
| 30 | var exact = categories | 26 | var exact = categories |
| 31 | - .Where(c => NormalizeNameKey(c.CategoryName) == key) | 27 | + .Where(c => MatchesImportCategoryCell(c, key, n)) |
| 32 | .ToList(); | 28 | .ToList(); |
| 33 | if (exact.Count > 0) | 29 | if (exact.Count > 0) |
| 34 | { | 30 | { |
| @@ -47,28 +43,46 @@ public static class ProductCategoryNameMatchHelper | @@ -47,28 +43,46 @@ public static class ProductCategoryNameMatchHelper | ||
| 47 | .ToList(); | 43 | .ToList(); |
| 48 | } | 44 | } |
| 49 | 45 | ||
| 50 | - private static async Task<List<FlProductCategoryDbEntity>> NarrowCategoriesByPartnerAsync( | 46 | + private static async Task<List<FlProductCategoryDbEntity>> LoadPartnerScopedCategoriesAsync( |
| 51 | ISqlSugarClient db, | 47 | ISqlSugarClient db, |
| 52 | - List<FlProductCategoryDbEntity> categories, | ||
| 53 | string? partnerId) | 48 | string? partnerId) |
| 54 | { | 49 | { |
| 55 | - var pid = partnerId?.Trim(); | ||
| 56 | - if (string.IsNullOrWhiteSpace(pid)) | 50 | + var query = db.Queryable<FlProductCategoryDbEntity>().Where(x => !x.IsDeleted); |
| 51 | + var scopedPartnerIds = await LabelEntityPartnerScopeHelper.ResolveScopedPartnerIdsForListAsync(db, partnerId); | ||
| 52 | + if (scopedPartnerIds is not null) | ||
| 57 | { | 53 | { |
| 58 | - return categories; | 54 | + query = await LabelEntityPartnerScopeHelper.ApplyProductCategoryPartnerListFilterAsync( |
| 55 | + db, query, scopedPartnerIds); | ||
| 59 | } | 56 | } |
| 60 | 57 | ||
| 61 | - var linkedIds = await db.Queryable<FlProductCategoryPartnerDbEntity>() | ||
| 62 | - .Where(x => x.PartnerId == pid) | ||
| 63 | - .Select(x => x.CategoryId) | ||
| 64 | - .ToListAsync(); | ||
| 65 | - var linkedSet = new HashSet<string>(linkedIds, StringComparer.OrdinalIgnoreCase); | 58 | + return await query.ToListAsync(); |
| 59 | + } | ||
| 66 | 60 | ||
| 67 | - return categories | ||
| 68 | - .Where(c => | ||
| 69 | - AllScopeBindingHelper.IsDeclaredAll(c.AppliedPartnerType) | ||
| 70 | - || linkedSet.Contains(c.Id)) | ||
| 71 | - .ToList(); | 61 | + private static bool MatchesImportCategoryCell(FlProductCategoryDbEntity category, string normalizedKey, string rawCell) |
| 62 | + { | ||
| 63 | + if (NormalizeNameKey(category.CategoryName) == normalizedKey) | ||
| 64 | + { | ||
| 65 | + return true; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + if (!string.IsNullOrWhiteSpace(category.DisplayText) | ||
| 69 | + && NormalizeNameKey(category.DisplayText) == normalizedKey) | ||
| 70 | + { | ||
| 71 | + return true; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + var code = category.CategoryCode?.Trim(); | ||
| 75 | + if (string.IsNullOrWhiteSpace(code)) | ||
| 76 | + { | ||
| 77 | + return false; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + if (NormalizeNameKey(code) == normalizedKey) | ||
| 81 | + { | ||
| 82 | + return true; | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + return string.Equals(code, rawCell.Trim(), StringComparison.OrdinalIgnoreCase); | ||
| 72 | } | 86 | } |
| 73 | 87 | ||
| 74 | private static string NormalizeNameKey(string? raw) | 88 | private static string NormalizeNameKey(string? raw) |
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/TeamMemberListAccessHelper.cs
| @@ -45,6 +45,11 @@ public static class TeamMemberListAccessHelper | @@ -45,6 +45,11 @@ public static class TeamMemberListAccessHelper | ||
| 45 | return MemberRoleTier.Staff; | 45 | return MemberRoleTier.Staff; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | + if (await TeamMemberRoleHelper.IsSystemAdminUserAsync(db, currentUser.Id.Value)) | ||
| 49 | + { | ||
| 50 | + return null; | ||
| 51 | + } | ||
| 52 | + | ||
| 48 | if (await TeamMemberRoleHelper.IsCompanyAdminUserAsync(db, currentUser)) | 53 | if (await TeamMemberRoleHelper.IsCompanyAdminUserAsync(db, currentUser)) |
| 49 | { | 54 | { |
| 50 | return MemberRoleTier.System; | 55 | return MemberRoleTier.System; |
| @@ -56,8 +61,8 @@ public static class TeamMemberListAccessHelper | @@ -56,8 +61,8 @@ public static class TeamMemberListAccessHelper | ||
| 56 | return MemberRoleTier.Company; | 61 | return MemberRoleTier.Company; |
| 57 | } | 62 | } |
| 58 | 63 | ||
| 59 | - // Location Admin:仅可见比 Regional 更低的角色(不含 Regional / Company / System)。 | ||
| 60 | - if (await TeamMemberRoleHelper.IsLocationAdminUserAsync(db, currentUser)) | 64 | + // Location Admin / Location Manager:仅可见比 Regional 更低的角色。 |
| 65 | + if (await TeamMemberRoleHelper.IsLocationTierUserAsync(db, currentUser)) | ||
| 61 | { | 66 | { |
| 62 | return MemberRoleTier.Regional; | 67 | return MemberRoleTier.Regional; |
| 63 | } | 68 | } |
| @@ -218,7 +223,9 @@ public static class TeamMemberListAccessHelper | @@ -218,7 +223,9 @@ public static class TeamMemberListAccessHelper | ||
| 218 | 223 | ||
| 219 | if (roleRows.Any(r => | 224 | if (roleRows.Any(r => |
| 220 | TeamMemberRoleHelper.IsLocationAdminRoleToken(r.RoleName) | 225 | TeamMemberRoleHelper.IsLocationAdminRoleToken(r.RoleName) |
| 221 | - || TeamMemberRoleHelper.IsLocationAdminRoleToken(r.RoleCode))) | 226 | + || TeamMemberRoleHelper.IsLocationAdminRoleToken(r.RoleCode) |
| 227 | + || TeamMemberRoleHelper.IsLocationManagerRoleToken(r.RoleName) | ||
| 228 | + || TeamMemberRoleHelper.IsLocationManagerRoleToken(r.RoleCode))) | ||
| 222 | { | 229 | { |
| 223 | return MemberRoleTier.Location; | 230 | return MemberRoleTier.Location; |
| 224 | } | 231 | } |
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/TeamMemberListScopeHelper.cs
| @@ -75,7 +75,7 @@ public static class TeamMemberListScopeHelper | @@ -75,7 +75,7 @@ public static class TeamMemberListScopeHelper | ||
| 75 | var isRegionalOrLocationAdmin = | 75 | var isRegionalOrLocationAdmin = |
| 76 | currentUser.Id.HasValue && | 76 | currentUser.Id.HasValue && |
| 77 | (await TeamMemberRoleHelper.IsRegionalAdminUserAsync(db, currentUser) | 77 | (await TeamMemberRoleHelper.IsRegionalAdminUserAsync(db, currentUser) |
| 78 | - || await TeamMemberRoleHelper.IsLocationAdminUserAsync(db, currentUser)); | 78 | + || await TeamMemberRoleHelper.IsLocationTierUserAsync(db, currentUser)); |
| 79 | 79 | ||
| 80 | var allowedLocIds = isRegionalOrLocationAdmin | 80 | var allowedLocIds = isRegionalOrLocationAdmin |
| 81 | ? await LocationScopeBindingHelper.ResolveAppAccessibleLocationIdsForUserAsync( | 81 | ? await LocationScopeBindingHelper.ResolveAppAccessibleLocationIdsForUserAsync( |
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/TeamMemberRoleHelper.cs
| @@ -70,7 +70,8 @@ public static class TeamMemberRoleHelper | @@ -70,7 +70,8 @@ public static class TeamMemberRoleHelper | ||
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | if (IsCompanyAdminRoleName(roleName) || IsCompanyAdminRoleToken(roleName) | 72 | if (IsCompanyAdminRoleName(roleName) || IsCompanyAdminRoleToken(roleName) |
| 73 | - || IsRegionalAdminRoleToken(roleName) || IsLocationAdminRoleToken(roleName)) | 73 | + || IsRegionalAdminRoleToken(roleName) || IsLocationAdminRoleToken(roleName) |
| 74 | + || IsLocationManagerRoleToken(roleName)) | ||
| 74 | { | 75 | { |
| 75 | return false; | 76 | return false; |
| 76 | } | 77 | } |
| @@ -202,6 +203,54 @@ public static class TeamMemberRoleHelper | @@ -202,6 +203,54 @@ public static class TeamMemberRoleHelper | ||
| 202 | || string.Equals(name, FoodLabelingRoleCodes.LocationAdmin, StringComparison.OrdinalIgnoreCase); | 203 | || string.Equals(name, FoodLabelingRoleCodes.LocationAdmin, StringComparison.OrdinalIgnoreCase); |
| 203 | } | 204 | } |
| 204 | 205 | ||
| 206 | + /// <summary> | ||
| 207 | + /// RoleCode / RoleName 是否 Location Manager(库内常见 RoleCode <c>Manager</c>,与 Location Admin 数据范围同级)。 | ||
| 208 | + /// </summary> | ||
| 209 | + public static bool IsLocationManagerRoleToken(string? value) | ||
| 210 | + { | ||
| 211 | + if (string.IsNullOrWhiteSpace(value) || IsCompanyAdminRoleToken(value) || IsLocationAdminRoleToken(value)) | ||
| 212 | + { | ||
| 213 | + return false; | ||
| 214 | + } | ||
| 215 | + | ||
| 216 | + var key = NormalizeRoleKey(value); | ||
| 217 | + if (key == "manager" || key.Contains("locationmanager", StringComparison.Ordinal)) | ||
| 218 | + { | ||
| 219 | + return true; | ||
| 220 | + } | ||
| 221 | + | ||
| 222 | + var name = value.Trim(); | ||
| 223 | + return string.Equals(name, "Location Manager", StringComparison.OrdinalIgnoreCase); | ||
| 224 | + } | ||
| 225 | + | ||
| 226 | + /// <summary>Location Admin 或 Location Manager(Team Member 列表可见性 / 门店范围,不含保存时 Location Admin 专属规则)。</summary> | ||
| 227 | + public static bool IsLocationTierRoleToken(string? value) => | ||
| 228 | + IsLocationAdminRoleToken(value) || IsLocationManagerRoleToken(value); | ||
| 229 | + | ||
| 230 | + /// <summary>当前用户是否为 Location Admin / Location Manager(JWT + 库内 Role)。</summary> | ||
| 231 | + public static async Task<bool> IsLocationTierUserAsync(ISqlSugarClient db, ICurrentUser currentUser) | ||
| 232 | + { | ||
| 233 | + if (currentUser.Id is null) | ||
| 234 | + { | ||
| 235 | + return false; | ||
| 236 | + } | ||
| 237 | + | ||
| 238 | + if (IsRoleFromClaims(currentUser, IsLocationTierRoleToken)) | ||
| 239 | + { | ||
| 240 | + return true; | ||
| 241 | + } | ||
| 242 | + | ||
| 243 | + return await IsLocationTierUserAsync(db, currentUser.Id.Value); | ||
| 244 | + } | ||
| 245 | + | ||
| 246 | + /// <summary>指定用户是否为 Location Admin / Location Manager。</summary> | ||
| 247 | + public static async Task<bool> IsLocationTierUserAsync(ISqlSugarClient db, Guid userId) | ||
| 248 | + { | ||
| 249 | + var roleRows = await LoadUserRoleRowsAsync(db, userId); | ||
| 250 | + return roleRows.Any(r => | ||
| 251 | + IsLocationTierRoleToken(r.RoleName) || IsLocationTierRoleToken(r.RoleCode)); | ||
| 252 | + } | ||
| 253 | + | ||
| 205 | public static async Task<bool> IsRegionalAdminUserAsync(ISqlSugarClient db, ICurrentUser currentUser) | 254 | public static async Task<bool> IsRegionalAdminUserAsync(ISqlSugarClient db, ICurrentUser currentUser) |
| 206 | { | 255 | { |
| 207 | if (currentUser.Id is null) | 256 | if (currentUser.Id is null) |
| @@ -251,12 +300,12 @@ public static class TeamMemberRoleHelper | @@ -251,12 +300,12 @@ public static class TeamMemberRoleHelper | ||
| 251 | await RoleMatchesAsync(db, roleId, IsLocationAdminRoleToken); | 300 | await RoleMatchesAsync(db, roleId, IsLocationAdminRoleToken); |
| 252 | 301 | ||
| 253 | /// <summary> | 302 | /// <summary> |
| 254 | - /// Company / Regional / Location Admin(功能权限可与 Company Admin 对齐,差异在数据范围)。 | 303 | + /// Company / Regional / Location Admin / Location Manager(功能权限可与 Company Admin 对齐,差异在数据范围)。 |
| 255 | /// </summary> | 304 | /// </summary> |
| 256 | public static async Task<bool> IsScopedAdminUserAsync(ISqlSugarClient db, ICurrentUser currentUser) => | 305 | public static async Task<bool> IsScopedAdminUserAsync(ISqlSugarClient db, ICurrentUser currentUser) => |
| 257 | await IsCompanyAdminUserAsync(db, currentUser) | 306 | await IsCompanyAdminUserAsync(db, currentUser) |
| 258 | || await IsRegionalAdminUserAsync(db, currentUser) | 307 | || await IsRegionalAdminUserAsync(db, currentUser) |
| 259 | - || await IsLocationAdminUserAsync(db, currentUser); | 308 | + || await IsLocationTierUserAsync(db, currentUser); |
| 260 | 309 | ||
| 261 | /// <summary> | 310 | /// <summary> |
| 262 | /// 解析会话 scopeLevel:system > company > regional > location > staff。 | 311 | /// 解析会话 scopeLevel:system > company > regional > location > staff。 |
| @@ -279,7 +328,7 @@ public static class TeamMemberRoleHelper | @@ -279,7 +328,7 @@ public static class TeamMemberRoleHelper | ||
| 279 | return OrgScopeLevels.Regional; | 328 | return OrgScopeLevels.Regional; |
| 280 | } | 329 | } |
| 281 | 330 | ||
| 282 | - if (await IsLocationAdminUserAsync(db, currentUser)) | 331 | + if (await IsLocationTierUserAsync(db, currentUser)) |
| 283 | { | 332 | { |
| 284 | return OrgScopeLevels.Location; | 333 | return OrgScopeLevels.Location; |
| 285 | } | 334 | } |
美国版/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 | @@ -88,12 +88,12 @@ public class LabelAppService : ApplicationService, ILabelAppService | ||
| 88 | } | 88 | } |
| 89 | else if (!string.IsNullOrWhiteSpace(filterGroupId)) | 89 | else if (!string.IsNullOrWhiteSpace(filterGroupId)) |
| 90 | { | 90 | { |
| 91 | - labelIdsQuery = LabelRegionScopeHelper.ApplyLabelRegionListFilter( | 91 | + labelIdsQuery = await LabelRegionScopeHelper.ApplyLabelRegionListFilterAsync( |
| 92 | db, labelIdsQuery, filterGroupId, scopedLocationIds, regionSchema); | 92 | db, labelIdsQuery, filterGroupId, scopedLocationIds, regionSchema); |
| 93 | } | 93 | } |
| 94 | else | 94 | else |
| 95 | { | 95 | { |
| 96 | - labelIdsQuery = LabelRegionScopeHelper.ApplyLabelLocationListFilter( | 96 | + labelIdsQuery = await LabelRegionScopeHelper.ApplyLabelLocationListFilterAsync( |
| 97 | db, labelIdsQuery, scopedLocationIds, regionSchema); | 97 | db, labelIdsQuery, scopedLocationIds, regionSchema); |
| 98 | } | 98 | } |
| 99 | } | 99 | } |
| @@ -111,7 +111,7 @@ public class LabelAppService : ApplicationService, ILabelAppService | @@ -111,7 +111,7 @@ public class LabelAppService : ApplicationService, ILabelAppService | ||
| 111 | } | 111 | } |
| 112 | else | 112 | else |
| 113 | { | 113 | { |
| 114 | - labelIdsQuery = LabelRegionScopeHelper.ApplyLabelLocationListFilter( | 114 | + labelIdsQuery = await LabelRegionScopeHelper.ApplyLabelLocationListFilterAsync( |
| 115 | db, labelIdsQuery, scopedLocationIds, regionSchema); | 115 | db, labelIdsQuery, scopedLocationIds, regionSchema); |
| 116 | } | 116 | } |
| 117 | } | 117 | } |
| @@ -187,6 +187,7 @@ public class LabelAppService : ApplicationService, ILabelAppService | @@ -187,6 +187,7 @@ public class LabelAppService : ApplicationService, ILabelAppService | ||
| 187 | l.LocationId, | 187 | l.LocationId, |
| 188 | l.PartnerId, | 188 | l.PartnerId, |
| 189 | l.CreatorId, | 189 | l.CreatorId, |
| 190 | + l.LastModifierId, | ||
| 190 | LabelCategoryName = c.CategoryName, | 191 | LabelCategoryName = c.CategoryName, |
| 191 | LabelTypeName = t.TypeName, | 192 | LabelTypeName = t.TypeName, |
| 192 | TemplateName = tpl.TemplateName, | 193 | TemplateName = tpl.TemplateName, |
| @@ -259,7 +260,10 @@ public class LabelAppService : ApplicationService, ILabelAppService | @@ -259,7 +260,10 @@ public class LabelAppService : ApplicationService, ILabelAppService | ||
| 259 | }); | 260 | }); |
| 260 | 261 | ||
| 261 | var manageCtx = await PartnerScopedManagePermissionHelper.BuildListContextAsync( | 262 | var manageCtx = await PartnerScopedManagePermissionHelper.BuildListContextAsync( |
| 262 | - CurrentUser, _dbContext, orderedLabels.Select(x => x.CreatorId)); | 263 | + CurrentUser, |
| 264 | + _dbContext, | ||
| 265 | + orderedLabels.Select(x => x.CreatorId), | ||
| 266 | + orderedLabels.Select(x => x.LastModifierId)); | ||
| 263 | 267 | ||
| 264 | var items = new List<LabelGetListOutputDto>(orderedLabels.Count); | 268 | var items = new List<LabelGetListOutputDto>(orderedLabels.Count); |
| 265 | foreach (var x in orderedLabels) | 269 | foreach (var x in orderedLabels) |
| @@ -287,7 +291,12 @@ public class LabelAppService : ApplicationService, ILabelAppService | @@ -287,7 +291,12 @@ public class LabelAppService : ApplicationService, ILabelAppService | ||
| 287 | Guid.TryParse(x.CreatorId?.Trim(), out var creatorGuid) && | 291 | Guid.TryParse(x.CreatorId?.Trim(), out var creatorGuid) && |
| 288 | manageCtx.SystemAdminCreatorIds.Contains(creatorGuid); | 292 | manageCtx.SystemAdminCreatorIds.Contains(creatorGuid); |
| 289 | var canManage = PartnerScopedManagePermissionHelper.EvaluateCanManage( | 293 | var canManage = PartnerScopedManagePermissionHelper.EvaluateCanManage( |
| 290 | - CurrentUser, manageCtx, x.CreatorId, partnerIdsForManage); | 294 | + CurrentUser, |
| 295 | + manageCtx, | ||
| 296 | + x.CreatorId, | ||
| 297 | + partnerIdsForManage, | ||
| 298 | + x.Id, | ||
| 299 | + x.LastModifierId); | ||
| 291 | items.Add(new LabelGetListOutputDto | 300 | items.Add(new LabelGetListOutputDto |
| 292 | { | 301 | { |
| 293 | Id = x.LabelCode ?? string.Empty, | 302 | Id = x.LabelCode ?? string.Empty, |
美国版/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 | @@ -77,7 +77,7 @@ public class LabelCategoryAppService : ApplicationService, ILabelCategoryAppServ | ||
| 77 | ids); | 77 | ids); |
| 78 | var scopeMap = await BuildCategoryScopeMapAsync(entities, partnerScopeMap); | 78 | var scopeMap = await BuildCategoryScopeMapAsync(entities, partnerScopeMap); |
| 79 | var manageCtx = await PartnerScopedManagePermissionHelper.BuildListContextAsync( | 79 | var manageCtx = await PartnerScopedManagePermissionHelper.BuildListContextAsync( |
| 80 | - CurrentUser, _dbContext, entities.Select(x => x.CreatorId)); | 80 | + CurrentUser, _dbContext, entities.Select(x => x.CreatorId), entities.Select(x => x.LastModifierId)); |
| 81 | 81 | ||
| 82 | var items = entities.Select(x => | 82 | var items = entities.Select(x => |
| 83 | { | 83 | { |
| @@ -97,7 +97,12 @@ public class LabelCategoryAppService : ApplicationService, ILabelCategoryAppServ | @@ -97,7 +97,12 @@ public class LabelCategoryAppService : ApplicationService, ILabelCategoryAppServ | ||
| 97 | Guid.TryParse(x.CreatorId?.Trim(), out var creatorGuid) && | 97 | Guid.TryParse(x.CreatorId?.Trim(), out var creatorGuid) && |
| 98 | manageCtx.SystemAdminCreatorIds.Contains(creatorGuid); | 98 | manageCtx.SystemAdminCreatorIds.Contains(creatorGuid); |
| 99 | var canManage = PartnerScopedManagePermissionHelper.EvaluateCanManage( | 99 | var canManage = PartnerScopedManagePermissionHelper.EvaluateCanManage( |
| 100 | - CurrentUser, manageCtx, x.CreatorId, partnerIdsForManage); | 100 | + CurrentUser, |
| 101 | + manageCtx, | ||
| 102 | + x.CreatorId, | ||
| 103 | + partnerIdsForManage, | ||
| 104 | + x.Id, | ||
| 105 | + x.LastModifierId); | ||
| 101 | return new LabelCategoryGetListOutputDto | 106 | return new LabelCategoryGetListOutputDto |
| 102 | { | 107 | { |
| 103 | Id = x.Id, | 108 | Id = x.Id, |
美国版/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 | @@ -66,9 +66,8 @@ public class LabelMultipleOptionAppService : ApplicationService, ILabelMultipleO | ||
| 66 | LabelEntityPartnerScopeHelper.LabelEntityPartnerKind.MultipleOption, | 66 | LabelEntityPartnerScopeHelper.LabelEntityPartnerKind.MultipleOption, |
| 67 | entities.Select(x => x.Id).ToList()); | 67 | entities.Select(x => x.Id).ToList()); |
| 68 | 68 | ||
| 69 | - var systemAdminCreatorIds = await TeamMemberRoleHelper.ResolveSystemAdminCreatorIdSetAsync( | ||
| 70 | - _dbContext.SqlSugarClient, | ||
| 71 | - entities.Select(x => x.CreatorId)); | 69 | + var manageCtx = await PartnerScopedManagePermissionHelper.BuildListContextAsync( |
| 70 | + CurrentUser, _dbContext, entities.Select(x => x.CreatorId), entities.Select(x => x.LastModifierId)); | ||
| 72 | 71 | ||
| 73 | var items = new List<LabelMultipleOptionGetListOutputDto>(entities.Count); | 72 | var items = new List<LabelMultipleOptionGetListOutputDto>(entities.Count); |
| 74 | foreach (var x in entities) | 73 | foreach (var x in entities) |
| @@ -76,11 +75,23 @@ public class LabelMultipleOptionAppService : ApplicationService, ILabelMultipleO | @@ -76,11 +75,23 @@ public class LabelMultipleOptionAppService : ApplicationService, ILabelMultipleO | ||
| 76 | scopeMap.TryGetValue(x.Id, out var scope); | 75 | scopeMap.TryGetValue(x.Id, out var scope); |
| 77 | partnerScopeMap.TryGetValue(x.Id, out var partnerScope); | 76 | partnerScopeMap.TryGetValue(x.Id, out var partnerScope); |
| 78 | var partnerIds = partnerScope?.PartnerIds ?? new List<string>(); | 77 | var partnerIds = partnerScope?.PartnerIds ?? new List<string>(); |
| 78 | + var partnerIdsForManage = PartnerScopedManagePermissionHelper.ResolvePartnerScopedEntityPartnerIdsForManageFromEcho( | ||
| 79 | + x.AvailabilityType, | ||
| 80 | + x.AppliedRegionType, | ||
| 81 | + partnerScope?.AppliedPartnerType ?? x.AppliedPartnerType, | ||
| 82 | + scope?.RegionIds, | ||
| 83 | + scope?.LocationIds, | ||
| 84 | + partnerIds); | ||
| 79 | var createdBySystemAdmin = | 85 | var createdBySystemAdmin = |
| 80 | Guid.TryParse(x.CreatorId?.Trim(), out var creatorGuid) && | 86 | Guid.TryParse(x.CreatorId?.Trim(), out var creatorGuid) && |
| 81 | - systemAdminCreatorIds.Contains(creatorGuid); | ||
| 82 | - var canManage = await LabelMultipleOptionManagePermissionHelper.CanManageAsync( | ||
| 83 | - CurrentUser, _dbContext, partnerIds, createdBySystemAdmin); | 87 | + manageCtx.SystemAdminCreatorIds.Contains(creatorGuid); |
| 88 | + var canManage = PartnerScopedManagePermissionHelper.EvaluateCanManage( | ||
| 89 | + CurrentUser, | ||
| 90 | + manageCtx, | ||
| 91 | + x.CreatorId, | ||
| 92 | + partnerIdsForManage, | ||
| 93 | + x.Id, | ||
| 94 | + x.LastModifierId); | ||
| 84 | 95 | ||
| 85 | items.Add(new LabelMultipleOptionGetListOutputDto | 96 | items.Add(new LabelMultipleOptionGetListOutputDto |
| 86 | { | 97 | { |
美国版/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 | @@ -122,19 +122,21 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ | ||
| 122 | ? fromElements! | 122 | ? fromElements! |
| 123 | : (itemsDisplay?.Items ?? FoodLabelingDisplayConsts.NotAvailable); | 123 | : (itemsDisplay?.Items ?? FoodLabelingDisplayConsts.NotAvailable); |
| 124 | var partnerIds = scope?.PartnerIds ?? new List<string>(); | 124 | var partnerIds = scope?.PartnerIds ?? new List<string>(); |
| 125 | + var creatorIdForManage = PartnerScopedManagePermissionHelper.ResolveCreatorIdForPermission( | ||
| 126 | + x.Id, x.CreatorId, x.LastModifierId); | ||
| 125 | var createdBySystemAdmin = | 127 | var createdBySystemAdmin = |
| 126 | - Guid.TryParse(x.CreatorId?.Trim(), out var creatorGuid) && | 128 | + Guid.TryParse(creatorIdForManage?.Trim(), out var creatorGuid) && |
| 127 | systemAdminCreatorIds.Contains(creatorGuid); | 129 | systemAdminCreatorIds.Contains(creatorGuid); |
| 128 | IReadOnlyList<string>? creatorPartnerIds = null; | 130 | IReadOnlyList<string>? creatorPartnerIds = null; |
| 129 | if (!createdBySystemAdmin && | 131 | if (!createdBySystemAdmin && |
| 130 | - Guid.TryParse(x.CreatorId?.Trim(), out var ownerGuid) && | 132 | + Guid.TryParse(creatorIdForManage?.Trim(), out var ownerGuid) && |
| 131 | creatorPartnerMap.TryGetValue(ownerGuid, out var mappedCreatorPartners)) | 133 | creatorPartnerMap.TryGetValue(ownerGuid, out var mappedCreatorPartners)) |
| 132 | { | 134 | { |
| 133 | creatorPartnerIds = mappedCreatorPartners; | 135 | creatorPartnerIds = mappedCreatorPartners; |
| 134 | } | 136 | } |
| 135 | 137 | ||
| 136 | TeamMemberListAccessHelper.MemberRoleTier? creatorRoleTier = null; | 138 | TeamMemberListAccessHelper.MemberRoleTier? creatorRoleTier = null; |
| 137 | - if (Guid.TryParse(x.CreatorId?.Trim(), out var parsedCreatorGuid) | 139 | + if (Guid.TryParse(creatorIdForManage?.Trim(), out var parsedCreatorGuid) |
| 138 | && creatorRoleTierMap.TryGetValue(parsedCreatorGuid, out var mappedCreatorTier)) | 140 | && creatorRoleTierMap.TryGetValue(parsedCreatorGuid, out var mappedCreatorTier)) |
| 139 | { | 141 | { |
| 140 | creatorRoleTier = mappedCreatorTier; | 142 | creatorRoleTier = mappedCreatorTier; |
| @@ -147,9 +149,10 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ | @@ -147,9 +149,10 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ | ||
| 147 | createdBySystemAdmin, | 149 | createdBySystemAdmin, |
| 148 | currentPartnerScope.AllowedPartnerIds, | 150 | currentPartnerScope.AllowedPartnerIds, |
| 149 | creatorPartnerIds, | 151 | creatorPartnerIds, |
| 150 | - x.CreatorId, | 152 | + creatorIdForManage, |
| 151 | viewerRoleTier, | 153 | viewerRoleTier, |
| 152 | - creatorRoleTier); | 154 | + creatorRoleTier, |
| 155 | + allowSelfCreatedWithoutConcretePartner: true); | ||
| 153 | 156 | ||
| 154 | items.Add(new LabelTemplateGetListOutputDto | 157 | items.Add(new LabelTemplateGetListOutputDto |
| 155 | { | 158 | { |
美国版/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 | @@ -74,7 +74,7 @@ public class LabelTypeAppService : ApplicationService, ILabelTypeAppService | ||
| 74 | LabelEntityPartnerScopeHelper.LabelEntityPartnerKind.Type, | 74 | LabelEntityPartnerScopeHelper.LabelEntityPartnerKind.Type, |
| 75 | ids); | 75 | ids); |
| 76 | var manageCtx = await PartnerScopedManagePermissionHelper.BuildListContextAsync( | 76 | var manageCtx = await PartnerScopedManagePermissionHelper.BuildListContextAsync( |
| 77 | - CurrentUser, _dbContext, entities.Select(x => x.CreatorId)); | 77 | + CurrentUser, _dbContext, entities.Select(x => x.CreatorId), entities.Select(x => x.LastModifierId)); |
| 78 | 78 | ||
| 79 | var items = entities.Select(x => | 79 | var items = entities.Select(x => |
| 80 | { | 80 | { |
| @@ -94,7 +94,12 @@ public class LabelTypeAppService : ApplicationService, ILabelTypeAppService | @@ -94,7 +94,12 @@ public class LabelTypeAppService : ApplicationService, ILabelTypeAppService | ||
| 94 | Guid.TryParse(x.CreatorId?.Trim(), out var creatorGuid) && | 94 | Guid.TryParse(x.CreatorId?.Trim(), out var creatorGuid) && |
| 95 | manageCtx.SystemAdminCreatorIds.Contains(creatorGuid); | 95 | manageCtx.SystemAdminCreatorIds.Contains(creatorGuid); |
| 96 | var canManage = PartnerScopedManagePermissionHelper.EvaluateCanManage( | 96 | var canManage = PartnerScopedManagePermissionHelper.EvaluateCanManage( |
| 97 | - CurrentUser, manageCtx, x.CreatorId, partnerIdsForManage); | 97 | + CurrentUser, |
| 98 | + manageCtx, | ||
| 99 | + x.CreatorId, | ||
| 100 | + partnerIdsForManage, | ||
| 101 | + x.Id, | ||
| 102 | + x.LastModifierId); | ||
| 98 | return new LabelTypeGetListOutputDto | 103 | return new LabelTypeGetListOutputDto |
| 99 | { | 104 | { |
| 100 | Id = x.Id, | 105 | Id = x.Id, |
| @@ -532,12 +537,12 @@ public class LabelTypeAppService : ApplicationService, ILabelTypeAppService | @@ -532,12 +537,12 @@ public class LabelTypeAppService : ApplicationService, ILabelTypeAppService | ||
| 532 | } | 537 | } |
| 533 | else if (!string.IsNullOrWhiteSpace(filterGroupId)) | 538 | else if (!string.IsNullOrWhiteSpace(filterGroupId)) |
| 534 | { | 539 | { |
| 535 | - labelQuery = LabelRegionScopeHelper.ApplyLabelRegionListFilter( | 540 | + labelQuery = await LabelRegionScopeHelper.ApplyLabelRegionListFilterAsync( |
| 536 | db, labelQuery, filterGroupId, scopedLocationIds, regionSchema); | 541 | db, labelQuery, filterGroupId, scopedLocationIds, regionSchema); |
| 537 | } | 542 | } |
| 538 | else | 543 | else |
| 539 | { | 544 | { |
| 540 | - labelQuery = LabelRegionScopeHelper.ApplyLabelLocationListFilter( | 545 | + labelQuery = await LabelRegionScopeHelper.ApplyLabelLocationListFilterAsync( |
| 541 | db, labelQuery, scopedLocationIds, regionSchema); | 546 | db, labelQuery, scopedLocationIds, regionSchema); |
| 542 | } | 547 | } |
| 543 | } | 548 | } |
| @@ -554,7 +559,7 @@ public class LabelTypeAppService : ApplicationService, ILabelTypeAppService | @@ -554,7 +559,7 @@ public class LabelTypeAppService : ApplicationService, ILabelTypeAppService | ||
| 554 | } | 559 | } |
| 555 | else | 560 | else |
| 556 | { | 561 | { |
| 557 | - labelQuery = LabelRegionScopeHelper.ApplyLabelLocationListFilter( | 562 | + labelQuery = await LabelRegionScopeHelper.ApplyLabelLocationListFilterAsync( |
| 558 | db, labelQuery, scopedLocationIds, regionSchema); | 563 | db, labelQuery, scopedLocationIds, regionSchema); |
| 559 | } | 564 | } |
| 560 | } | 565 | } |
美国版/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 | @@ -1115,7 +1115,9 @@ public class ProductAppService : ApplicationService, IProductAppService | ||
| 1115 | throw new UserFriendlyException($"Multiple product categories match \"{n}\". Use a unique name in the system."); | 1115 | throw new UserFriendlyException($"Multiple product categories match \"{n}\". Use a unique name in the system."); |
| 1116 | } | 1116 | } |
| 1117 | 1117 | ||
| 1118 | - return matches[0].Id; | 1118 | + var matched = matches[0]; |
| 1119 | + await ProductCategoryImportHelper.EnsureImportableCategoryCodeAsync(_dbContext.SqlSugarClient, matched); | ||
| 1120 | + return matched.Id; | ||
| 1119 | } | 1121 | } |
| 1120 | 1122 | ||
| 1121 | private async Task<string?> ResolvePartnerIdFromImportCellAsync(string cell) | 1123 | private async Task<string?> ResolvePartnerIdFromImportCellAsync(string cell) |