fix(菜单权限): 授权树按操作者置灰不可授予项 + 放行保留既有授权
普通管理员勾到无权授予的菜单后,ensureGrantable 抛 403,而 createUser/updateUser 都是 @Transactional,整笔回滚——线上表现就是「后台不能保存权限,也不能创建用户」 (2026-09-16 周丽娥账号创建用户与保存 uid=45 权限双双失败,库里查无新用户)。 根因是校验 2026-07-28 就加了,但授权树一直拿全量菜单,两边规则不一致。 - permission-menus 按操作者标记 grantable;授权树据此置灰(不隐藏:授权是整树替换, 隐藏会把超管授予过、操作者自己没有的菜单当取消勾选删掉,与 09-13「权限自己没掉」同类) - ensureGrantable 放行目标已持有的授权,只拦新增,不构成提权 - GlobalExceptionHandler 补业务异常日志:此前普通业务异常一行都不记,本次排查只能靠 反推响应体字节数(nginx body_bytes_sent 含 chunked 开销)才定位到根因
This commit is contained in:
+18
-2
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.common.exception;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.security.DeviceSessionPolicy;
|
||||
import com.nanri.aiimage.common.service.TaskOwnerForwardService;
|
||||
import com.nanri.aiimage.config.TaskOperationLockConfig;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
@@ -60,14 +61,23 @@ public class GlobalExceptionHandler {
|
||||
}
|
||||
|
||||
@ExceptionHandler(BusinessException.class)
|
||||
public ApiResponse<Void> handleBusinessException(BusinessException ex) {
|
||||
public ApiResponse<Void> handleBusinessException(BusinessException ex, HttpServletRequest request) {
|
||||
// 业务异常此前完全不记日志:2026-09-16 线上「保存权限/创建用户」双双失败时,
|
||||
// 服务端只留 RequestTraceFilter 的 200 一行,根因只能靠反推响应体字节数才定位到。
|
||||
// 401/4011(未登录、被顶下线)属于轮询类接口的常态噪声,降为 debug 以免淹没真实业务错。
|
||||
if (isRoutineAuthNoise(ex.getCode())) {
|
||||
log.debug("[business] {} {} code={} message={}", request.getMethod(), request.getRequestURI(),
|
||||
ex.getCode(), ex.getMessage());
|
||||
} else {
|
||||
log.warn("[business] {} {} code={} message={}", request.getMethod(), request.getRequestURI(),
|
||||
ex.getCode(), ex.getMessage());
|
||||
}
|
||||
if (Integer.valueOf(BusinessCodes.TASK_ALREADY_FINISHED).equals(ex.getCode())) {
|
||||
// 幂等忽略:任务已结束时的重复提交无副作用,按成功返回,避免客户端反复重试
|
||||
return ApiResponse.success("任务已结束,忽略重复提交", null);
|
||||
}
|
||||
if (Integer.valueOf(BusinessCodes.TASK_BUSY).equals(ex.getCode())) {
|
||||
// 锁竞争:必须如实返回失败 + 可重试码,否则 worker 会把「未落库」当成功而停止重试
|
||||
log.warn("[business] 任务忙,调用方应稍后重试: {}", ex.getMessage());
|
||||
return ApiResponse.fail(BusinessCodes.TASK_BUSY, ex.getMessage());
|
||||
}
|
||||
return ex.getCode() == null
|
||||
@@ -75,6 +85,12 @@ public class GlobalExceptionHandler {
|
||||
: ApiResponse.fail(ex.getCode(), ex.getMessage());
|
||||
}
|
||||
|
||||
/** 未登录 / 登录态失效 / 被其他设备顶下线:按 401 语义的常态噪声,不占 WARN。 */
|
||||
private boolean isRoutineAuthNoise(Integer code) {
|
||||
return Integer.valueOf(401).equals(code)
|
||||
|| Integer.valueOf(DeviceSessionPolicy.CODE_KICKED).equals(code);
|
||||
}
|
||||
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
public ApiResponse<Void> handleMethodArgumentNotValidException(MethodArgumentNotValidException ex) {
|
||||
String message = ex.getBindingResult().getFieldError() != null
|
||||
|
||||
Reference in New Issue
Block a user