Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/utils/src/helpers/generate-routes-frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,22 @@ async function generateRoutesByFrontend(

// 如果有禁止访问的页面,将禁止访问的页面替换为403页面
return mapTree(finalRoutes, (route) => {
if (menuHasVisibleWithForbidden(route)) {
if (isForBidden(route, roles)) {
route.component = forbiddenComponent;
}
return route;
Comment on lines +24 to 27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

Suggested change
if (isForBidden(route, roles)) {
route.component = forbiddenComponent;
}
return route;
if (isForBidden(route, roles) && !menuHasVisibleWithForbidden(route)) {
route.component = forbiddenComponent;
}
return route;

});
}

/**
* 判断是否禁止访问
* @param route
* @returns
*/
function isForBidden (route: RouteRecordRaw, roles: string[]) {
return !!route.meta?.authority && !roles.some((role) => route.meta?.authority?.includes(role));
}

/**
* 判断路由是否有权限访问
* @param route
Expand Down
Loading