Skip to content

Commit ac393bd

Browse files
committed
display all navbar items even if no access, including local dev
1 parent 8066aa9 commit ac393bd

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

frontend/src/index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ if (typeof process === 'undefined') {
66

77
const api = require('./api');
88
const mothership = require('./mothership');
9+
const { routes } = require('./routes');
910
const vanillatoasts = require('vanillatoasts');
1011

1112
const app = Vue.createApp({
@@ -67,7 +68,7 @@ app.component('app-component', {
6768
window.state = this;
6869

6970
if (mothership.hasAPIKey) {
70-
const hash = window.location.hash.replace(/^#?\/?\??/, '') || '';
71+
const hash = window.location.hash.replace(/^#?\/?/, '') || '';
7172
const hashQuery = hash.split('?')[1] || '';
7273
const hashParams = new URLSearchParams(hashQuery);
7374
if (hashParams.has('code')) {
@@ -110,6 +111,7 @@ app.component('app-component', {
110111
const { nodeEnv } = await api.status();
111112
this.nodeEnv = nodeEnv;
112113
}
114+
113115
this.status = 'loaded';
114116
},
115117
setup() {
@@ -126,7 +128,6 @@ app.component('app-component', {
126128
}
127129
});
128130

129-
const { routes } = require('./routes');
130131
const router = VueRouter.createRouter({
131132
history: VueRouter.createWebHashHistory(),
132133
routes: routes.map(route => ({
@@ -136,6 +137,14 @@ const router = VueRouter.createRouter({
136137
}))
137138
});
138139

140+
router.beforeEach((to, from, next) => {
141+
if (to.name === 'root' && window.state.roles && window.state.roles[0] === 'dashboards') {
142+
return next('dashboards');
143+
} else {
144+
next();
145+
}
146+
});
147+
139148
app.use(router);
140149

141150
app.mount('#content');

frontend/src/navbar/navbar.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@ module.exports = app => app.component('navbar', {
1515
inject: ['state'],
1616
data: () => ({ showFlyout: false }),
1717
mounted: function() {
18-
// Redirect to first allowed route if current route is not allowed
19-
if (!this.hasAccess(this.roles, this.$route.name)) {
20-
const firstAllowedRoute = this.allowedRoutes[0];
21-
if (firstAllowedRoute) {
22-
this.$router.push({ name: firstAllowedRoute.name });
23-
}
24-
}
25-
2618
const mobileMenuMask = document.querySelector('#mobile-menu-mask');
2719
const mobileMenu = document.querySelector('#mobile-menu');
2820

@@ -61,11 +53,8 @@ module.exports = app => app.component('navbar', {
6153
canViewTeam() {
6254
return this.hasAccess(this.roles, 'team');
6355
},
64-
allowedRoutes() {
65-
return routes.filter(route => this.hasAccess(this.roles, route.name));
66-
},
6756
defaultRoute() {
68-
return this.allowedRoutes[0]?.name || 'dashboards';
57+
return this.roles && this.roles[0] === 'dashboards' ? 'dashboards' : 'root';
6958
}
7059
},
7160
methods: {

frontend/src/routes.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ const roleAccess = {
99
dashboards: ['dashboards', 'dashboard']
1010
};
1111

12+
const allowedRoutesForLocalDev = ['document', 'root'];
13+
1214
// Helper function to check if a role has access to a route
1315
function hasAccess(roles, routeName) {
1416
// change to true for local development
15-
if (!roles) return false;
17+
if (!roles) return allowedRoutesForLocalDev.includes(routeName);
1618
return roles.some(role => roleAccess[role]?.includes(routeName));
1719
}
1820

0 commit comments

Comments
 (0)