fix: 菜单固定为全局
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using MediatR;
|
||||
using TakeoutSaaS.Application.Identity;
|
||||
using TakeoutSaaS.Application.Identity.Commands;
|
||||
using TakeoutSaaS.Application.Identity.Contracts;
|
||||
using TakeoutSaaS.Domain.Identity.Repositories;
|
||||
@@ -19,12 +20,18 @@ public sealed class UpdateMenuCommandHandler(
|
||||
/// <inheritdoc />
|
||||
public async Task<MenuDefinitionDto?> Handle(UpdateMenuCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// 1. 校验存在
|
||||
// 1. 菜单固定时禁止修改
|
||||
if (!MenuPolicy.CanMaintainMenus)
|
||||
{
|
||||
throw new BusinessException(ErrorCodes.Forbidden, "菜单已固定,禁止修改");
|
||||
}
|
||||
|
||||
// 2. 校验存在
|
||||
var tenantId = tenantProvider.GetCurrentTenantId();
|
||||
var entity = await menuRepository.FindByIdAsync(request.Id, tenantId, cancellationToken)
|
||||
?? throw new BusinessException(ErrorCodes.NotFound, "菜单不存在");
|
||||
|
||||
// 2. 更新字段
|
||||
// 3. 更新字段
|
||||
entity.ParentId = request.ParentId;
|
||||
entity.Name = request.Name.Trim();
|
||||
entity.Path = request.Path.Trim();
|
||||
@@ -42,11 +49,11 @@ public sealed class UpdateMenuCommandHandler(
|
||||
? null
|
||||
: System.Text.Json.JsonSerializer.Serialize(request.AuthList);
|
||||
|
||||
// 3. 持久化
|
||||
// 4. 持久化
|
||||
await menuRepository.UpdateAsync(entity, cancellationToken);
|
||||
await menuRepository.SaveChangesAsync(cancellationToken);
|
||||
|
||||
// 4. 返回 DTO
|
||||
// 5. 返回 DTO
|
||||
return MenuMapper.ToDto(entity);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user