-
Notifications
You must be signed in to change notification settings - Fork 7.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: menuVisibleWithForbidden: true route auth #5083
base: main
Are you sure you want to change the base?
Conversation
|
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 eslint
packages/utils/src/helpers/generate-routes-frontend.tsOops! Something went wrong! :( ESLint: 9.16.0 Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/node_modules/@vben/eslint-config/dist/index.mjs' imported from /eslint.config.mjs WalkthroughThe changes include the addition of a new function, Changes
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (1)
packages/utils/src/helpers/generate-routes-frontend.ts (1)
31-38
: Improve function implementation and documentationSeveral improvements can be made to the
isForBidden
function:
- Follow camelCase naming convention
- Add proper JSDoc param type annotations
- Simplify the logic using optional chaining
Suggested improvements:
/** * Check if route access is forbidden - * @param route - * @returns + * @param {RouteRecordRaw} route - The route to check + * @param {string[]} roles - User roles to check against + * @returns {boolean} True if access is forbidden, false otherwise */ -function isForBidden (route: RouteRecordRaw, roles: string[]) { - return !!route.meta?.authority && !roles.some((role) => route.meta?.authority?.includes(role)); +function isForbidden(route: RouteRecordRaw, roles: string[]) { + return !!route.meta?.authority && !roles.some((role) => route.meta?.authority?.includes(role)); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
packages/utils/src/helpers/generate-routes-frontend.ts
(1 hunks)
🔇 Additional comments (1)
packages/utils/src/helpers/generate-routes-frontend.ts (1)
24-38
: Verify usage of menuVisibleWithForbidden across the codebase
Let's ensure this change doesn't break other use cases of menuVisibleWithForbidden
.
✅ Verification successful
Let me gather more context about the usage of menuVisibleWithForbidden
to understand its relationship with isForBidden
.
Based on the gathered information, I can now provide the final response:
Function isForBidden
is safely scoped and menuVisibleWithForbidden
usage is consistent
- The
isForBidden
function is only used withingenerate-routes-frontend.ts
and has no other dependencies - The
menuVisibleWithForbidden
meta property is properly typed in@core/base/typings
and consistently used across the codebase for route configuration - The changes are localized to route generation logic and maintain the expected behavior with forbidden routes
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for other usages of menuVisibleWithForbidden
echo "Searching for menuVisibleWithForbidden usage:"
rg "menuVisibleWithForbidden" --type ts
# Search for potential usages of isForBidden function
echo -e "\nSearching for isForBidden usage:"
rg "isForBidden\(" --type ts
Length of output: 1174
Script:
#!/bin/bash
# Get context around menuVisibleWithForbidden usages
echo "Context for menuVisibleWithForbidden in generate-routes-frontend.ts:"
rg "menuVisibleWithForbidden" packages/utils/src/helpers/generate-routes-frontend.ts -B 2 -A 2
echo -e "\nContext for menuVisibleWithForbidden in access.ts files:"
rg "menuVisibleWithForbidden" "apps/*/src/router/access.ts" -B 2 -A 2
rg "menuVisibleWithForbidden" "playground/src/router/access.ts" -B 2 -A 2
# Get the full implementation of isForBidden function
echo -e "\nFull implementation of isForBidden:"
ast-grep --pattern 'function isForBidden($_) { $$$ }'
Length of output: 1008
if (isForBidden(route, roles)) { | ||
route.component = forbiddenComponent; | ||
} | ||
return route; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical: Current implementation doesn't fix the reported issue
The change doesn't address the original problem where routes with both authority
and menuVisibleWithForbidden: true
show 403 even when the user has permissions. The new isForBidden
function only checks authority without considering menuVisibleWithForbidden
.
Suggested fix:
- if (isForBidden(route, roles)) {
+ if (isForBidden(route, roles) && !menuHasVisibleWithForbidden(route)) {
route.component = forbiddenComponent;
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if (isForBidden(route, roles)) { | |
route.component = forbiddenComponent; | |
} | |
return route; | |
if (isForBidden(route, roles) && !menuHasVisibleWithForbidden(route)) { | |
route.component = forbiddenComponent; | |
} | |
return route; |
Description
目前设置了authority和menuVisibleWithForbidden: true的route,即使用户有权限访问,也会被替换成403组件
Type of change
Please delete options that are not relevant.
Summary by CodeRabbit
New Features
Bug Fixes