perf(projects): add detailed annotations for route role
This commit is contained in:
parent
1335d47ae8
commit
f6bab0cc9d
@ -25,6 +25,10 @@ export function createPermissionGuard(router: Router) {
|
|||||||
const loginRoute: RouteKey = 'login';
|
const loginRoute: RouteKey = 'login';
|
||||||
const noPermissionRoute: RouteKey = '403';
|
const noPermissionRoute: RouteKey = '403';
|
||||||
|
|
||||||
|
// check whether the user has permission to access the route
|
||||||
|
// 1. if the route's "roles" is empty, then it is allowed to access
|
||||||
|
// 2. if the user is super admin, then it is allowed to access
|
||||||
|
// 3. if the user's role is included in the route's "roles", then it is allowed to access
|
||||||
const SUPER_ADMIN = 'R_SUPER';
|
const SUPER_ADMIN = 'R_SUPER';
|
||||||
const hasPermission =
|
const hasPermission =
|
||||||
!routeRoles.length ||
|
!routeRoles.length ||
|
||||||
|
@ -13,6 +13,7 @@ import SvgIcon from '@/components/custom/svg-icon.vue';
|
|||||||
export function filterAuthRoutesByRoles(routes: ElegantConstRoute[], roles: string[]) {
|
export function filterAuthRoutesByRoles(routes: ElegantConstRoute[], roles: string[]) {
|
||||||
const SUPER_ROLE = 'R_SUPER';
|
const SUPER_ROLE = 'R_SUPER';
|
||||||
|
|
||||||
|
// if the user is super admin, then it is allowed to access all routes
|
||||||
if (roles.includes(SUPER_ROLE)) {
|
if (roles.includes(SUPER_ROLE)) {
|
||||||
return routes;
|
return routes;
|
||||||
}
|
}
|
||||||
@ -29,10 +30,12 @@ export function filterAuthRoutesByRoles(routes: ElegantConstRoute[], roles: stri
|
|||||||
function filterAuthRouteByRoles(route: ElegantConstRoute, roles: string[]) {
|
function filterAuthRouteByRoles(route: ElegantConstRoute, roles: string[]) {
|
||||||
const routeRoles = (route.meta && route.meta.roles) || [];
|
const routeRoles = (route.meta && route.meta.roles) || [];
|
||||||
|
|
||||||
|
// if the route's "roles" is empty, then it is allowed to access
|
||||||
if (!routeRoles.length) {
|
if (!routeRoles.length) {
|
||||||
return [route];
|
return [route];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if the user's role is included in the route's "roles", then it is allowed to access
|
||||||
const hasPermission = routeRoles.some(role => roles.includes(role));
|
const hasPermission = routeRoles.some(role => roles.includes(role));
|
||||||
|
|
||||||
const filterRoute = { ...route };
|
const filterRoute = { ...route };
|
||||||
|
Loading…
Reference in New Issue
Block a user