{"record":{"id":"bcfdddb34a4bb623","repo":"elunez/eladmin","slug":"min-level","errorCode":null,"errorMessage":"权限不足，你的角色级别：{min}，低于操作的角色级别：{level}","messagePattern":"权限不足，你的角色级别：(.+?)，低于操作的角色级别：(.+?)","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"eladmin-system/src/main/java/me/zhengjie/modules/system/rest/RoleController.java","lineNumber":155,"sourceCode":"        // 验证是否被用户关联\n        roleService.verification(ids);\n        roleService.delete(ids);\n        return new ResponseEntity<>(HttpStatus.OK);\n    }\n\n    /**\n     * 获取用户的角色级别\n     * @return /\n     */\n    private int getLevels(){\n        List<Integer> levels = roleService.findByUsersId(SecurityUtils.getCurrentUserId()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList());\n        return Collections.min(levels);\n    }\n\n    private void checkLevel(Integer level){\n        int min = getLevels();\n        if(level == null || level < min){\n            throw new BadRequestException(\"权限不足，你的角色级别：\" + min + \"，低于操作的角色级别：\" + level);\n        }\n    }\n}\n","sourceCodeStart":137,"sourceCodeEnd":159,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/RoleController.java#L137-L159","documentation":"Thrown by RoleController.checkLevel (line 155) during role create/update/level-sensitive operations when the caller's own minimum role level is numerically higher (less privileged) than the level being written. In eladmin a SMALLER number means MORE privilege; the check `level == null || level < min` rejects assigning a level above your own or leaving it null.","triggerScenarios":"A level-5 admin creating/updating a role with level 2 (or any level below their own minimum); POST /api/roles with no level field in the JSON (level == null branch); editing a role whose level the current user could never have granted.","commonSituations":"Operators misreading the inverted scale and trying to 'raise' a role's privilege by increasing the number; new deployments where a non-super-admin tests role management; front-end sending an incomplete role payload so level is null.","solutions":["Set the role's level to a value >= your own minimum level (e.g. if your min is 2, you may only create levels 2-999).","Include the level field in the request body — omitting it trips the null branch.","Have a top-level (level 1) admin perform the operation if a higher-privilege role is genuinely needed."],"exampleFix":"// before: level-3 user tries to create a level-1 role\n{ \"name\": \"super\", \"level\": 1 }\n// after: stays at or below own privilege\n{ \"name\": \"limited\", \"level\": 3 }","handlingStrategy":"validation","validationCode":"// Client-side mirror of RoleController.checkLevel\nconst myMinLevel = Math.min(...store.state.user.roles.map(r => r.level));\nif (form.level == null || form.level < myMinLevel) {\n  notifyError(`角色级别必须 >= ${myMinLevel}`);\n  return;\n}\nawait axios.post('/api/roles', form);","typeGuard":"const levelAllowed = (level, myMin) => level != null && level >= myMin;","tryCatchPattern":"Catch BadRequestException on role create/update; treat as permanent — surface the server's level numbers and pre-fill a valid level.","preventionTips":["Restrict the level input's min to the current user's own minimum level.","Remember lower number = higher privilege when reading the message.","Always send level in the role payload."],"tags":["authorization","rbac","eladmin","role","level"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}