c3lf-system-3/web/src/router.js
2024-11-23 01:35:29 +01:00

125 lines
4.8 KiB
JavaScript

import {createRouter, createWebHistory} from 'vue-router'
import store from '@/store';
import Items from './views/Items';
import Boxes from './views/Boxes';
import Files from './views/Files';
import Error from './views/Error';
import HowTo from './views/HowTo';
import Login from '@/views/Login.vue';
import Register from '@/views/Register.vue';
import Dashboard from "@/views/admin/Dashboard.vue";
import Tickets from "@/views/Tickets.vue";
import Ticket from "@/views/Ticket.vue";
import Admin from "@/views/admin/Admin.vue";
import Empty from "@/views/Empty.vue";
import Events from "@/views/admin/Events.vue";
import Settings from "@/views/admin/Settings.vue";
import AccessControl from "@/views/admin/AccessControl.vue";
import {default as BoxesAdmin} from "@/views/admin/Boxes.vue"
import Shipping from "@/views/admin/Shipping.vue";
import Notifications from "@/views/admin/Notifications.vue";
const routes = [
{path: '/', redirect: '/37C3/items', meta: {requiresAuth: false}},
{path: '/login/', name: 'login', component: Login, meta: {requiresAuth: false}},
{path: '/register/', name: 'register', component: Register, meta: {requiresAuth: false}},
{path: '/howto/', name: 'howto', component: HowTo, meta: {requiresAuth: true}},
{
path: '/:event/items/', name: 'items', component: Items, meta:
{requiresAuth: true, requiresPermission: 'view_item'}
},
{
path: '/:event/item/:uid/', name: 'item', component: Items, meta:
{requiresAuth: true, requiresPermission: 'view_item'}
},
{
path: '/:event/boxes/', name: 'boxes', component: Boxes, meta:
{requiresAuth: true, requiresPermission: 'view_container'}
},
{
path: '/:event/box/:uid/', name: 'box', component: Boxes, meta:
{requiresAuth: true, requiresPermission: 'view_container'}
},
{
path: '/:event/tickets/', name: 'tickets', component: Tickets, meta:
{requiresAuth: true, requiresPermission: 'view_issuethread'}
},
{
path: '/:event/ticket/:id/', name: 'ticket', component: Ticket, meta:
{requiresAuth: true, requiresPermission: 'view_issuethread'}
},
{
path: '/admin/', component: Admin, meta:
{requiresAuth: true, requiresPermission: 'delete_event'},
children: [
{
path: 'files/', name: 'files', component: Files, meta:
{requiresAuth: true, requiresPermission: 'delete_event'}
},
{
path: 'events/', name: 'events', component: Events, meta:
{requiresAuth: true, requiresPermission: 'delete_event'}
},
{
path: 'settings/', name: 'settings', component: Settings, meta:
{requiresAuth: true, requiresPermission: 'delete_event'}
},
{
path: '', name: 'admin', component: Dashboard, meta:
{requiresAuth: true, requiresPermission: 'delete_event'}
},
{
path: 'users/', name: 'users', component: AccessControl, meta:
{requiresAuth: true, requiresPermission: 'delete_event'}
},
{
path: 'boxes/', name: 'admin_boxes', component: BoxesAdmin, meta:
{requiresAuth: true, requiresPermission: 'delete_event'}
},
{
path: 'shipping/', name: 'shipping', component: Shipping, meta:
{requiresAuth: true, requiresPermission: 'delete_event'}
},
{
path: 'notifications/', name: 'notifications', component: Notifications, meta:
{requiresAuth: true, requiresPermission: 'delete_event'}
}
]
},
{path: '/user', name: 'user', component: Empty, meta: {requiresAuth: true}},
//{path: '*', component: Error},
];
const router = createRouter({
history: createWebHistory(),
linkActiveClass: "active",
routes,
});
router.beforeEach((to, from, next) => {
if (to.meta.requiresAuth && !store.getters.isLoggedIn) {
console.log("Not logged in, redirecting to login page")
next({
name: 'login',
query: {redirect: to.fullPath},
})
} else if (to.meta.requiresPermission && !store.getters.checkPermission(to.params.event || "*", to.meta.requiresPermission)) {
console.log("Not enough permissions, redirecting to empty page")
next({
path: '/user',
})
} else {
next()
}
});
router.afterEach((to, from) => {
if (to.params.event && to.params.event !== store.state.lastEvent) {
//console.log('update last event', to.params.event);
store.commit('updateLastEvent', to.params.event);
}
});
export default router;