Skip to content

Commit 33fee97

Browse files
authored
Merge pull request #1282 from colinin/fix-menu-parent
fix(platform): Fix the same menu error
2 parents 7225b76 + 3afc940 commit 33fee97

4 files changed

Lines changed: 14 additions & 1 deletion

File tree

aspnet-core/modules/platform/LINGYUN.Platform.Application/LINGYUN/Platform/Menus/MenuAppService.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,15 @@ public async virtual Task<MenuDto> UpdateAsync(Guid id, MenuUpdateDto input)
210210
{
211211
menu.Component = input.Component;
212212
}
213+
if (menu.ParentId != input.ParentId)
214+
{
215+
if (input.ParentId == menu.Id)
216+
{
217+
throw new BusinessException(PlatformErrorCodes.CannotSetSelfParentMenu, "The current menu cannot be the same as the upper-level menu!");
218+
}
219+
menu.ParentId = input.ParentId;
220+
}
213221

214-
menu.ParentId = input.ParentId;
215222
menu.IsPublic = input.IsPublic;
216223

217224
await MenuManager.UpdateAsync(menu);

aspnet-core/modules/platform/LINGYUN.Platform.Domain.Shared/LINGYUN/Platform/Localization/Resources/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"Platform:02001": "The same menu exists in the sibling directory: {Name}!",
77
"Platform:02002": "You are not allowed to delete menu nodes when there are other submenus!",
88
"Platform:02003": "The menu level has reached the specified maximum: {Depth}!",
9+
"Platform:02004": "The current menu cannot be the same as the upper-level menu!",
910
"Platform:02101": "The menu metadata is missing the necessary element :{Name}, which is defined in the data dictionary :{DataName}!",
1011
"Platform:03001": "The metadata format does not match!",
1112
"Platform:04400": "The user favorites the menu repeatedly!",

aspnet-core/modules/platform/LINGYUN.Platform.Domain.Shared/LINGYUN/Platform/Localization/Resources/zh-Hans.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"Platform:02001": "同级目录下存在相同的菜单: {Name}!",
77
"Platform:02002": "在有其他子菜单的情况下,不允许删除菜单节点!",
88
"Platform:02003": "菜单层级已达到规定最大值: {Depth}!",
9+
"Platform:02004": "当前菜单不能与上级菜单相同!",
910
"Platform:02101": "菜单元数据缺少必要的元素: {Name},此选项在数据字典:{DataName} 中定义!",
1011
"Platform:03001": "元数据格式不匹配!",
1112
"Platform:04400": "用户重复收藏菜单!",

aspnet-core/modules/platform/LINGYUN.Platform.Domain.Shared/LINGYUN/Platform/PlatformErrorCodes.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ public static class PlatformErrorCodes
2222
/// </summary>
2323
public const string MenuAchieveMaxDepth = Namespace + ":02003";
2424
/// <summary>
25+
/// 当前菜单不能与上级菜单相同
26+
/// </summary>
27+
public const string CannotSetSelfParentMenu = Namespace + ":02004";
28+
/// <summary>
2529
/// 菜单元数据缺少必要的元素
2630
/// </summary>
2731
public const string MenuMissingMetadata = Namespace + ":02101";

0 commit comments

Comments
 (0)