From 1e86dbbbb3a95f4077a4bbd05bc517c42366ca1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Glasn=C3=A1k?= Date: Wed, 22 Feb 2023 19:09:12 +0100 Subject: [PATCH] [auth] Added auth guard --- app/src/plugins/app/_config/router.ts | 47 ++++++++++++++----- app/src/plugins/tm@dashboard/tasks/tasks.vue | 5 +- .../teams/_components/a-team-filter.vue | 1 + app/src/plugins/tm@dashboard/teams/teams.vue | 3 +- .../tm@modal/task/z-complete-task-modal.vue | 9 ++-- 5 files changed, 44 insertions(+), 21 deletions(-) diff --git a/app/src/plugins/app/_config/router.ts b/app/src/plugins/app/_config/router.ts index 004bfa9..e4c1a2f 100644 --- a/app/src/plugins/app/_config/router.ts +++ b/app/src/plugins/app/_config/router.ts @@ -1,4 +1,5 @@ import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router' +import store from '@/store' const routes: Array = [ { @@ -16,17 +17,20 @@ const routes: Array = [ { path: '/auth/login', name: 'Login', - component: () => import('@/plugins/lib@auth/login/login.vue') + component: () => import('@/plugins/lib@auth/login/login.vue'), + meta: {requiresAuth: false} }, { path: '/auth/forgot-password', name: 'Forgot password', - component: () => import('@/plugins/lib@auth/forgot-password/forgot-password.vue') + component: () => import('@/plugins/lib@auth/forgot-password/forgot-password.vue'), + meta: {requiresAuth: false} }, { path: '/auth/reset-password', name: 'Reset password', - component: () => import('@/plugins/lib@auth/reset-password/reset-password.vue') + component: () => import('@/plugins/lib@auth/reset-password/reset-password.vue'), + meta: {requiresAuth: false} } ] }, @@ -45,50 +49,50 @@ const routes: Array = [ { path: '/app/dashboard/tasks', name: 'Dashboard - Tasks', - meta: { title: 'Tasks' }, + meta: { title: 'Tasks', requiresAuth: true }, component: () => import('@/plugins/tm@dashboard/tasks/tasks.vue') }, { path: '/app/dashboard/teams', name: 'Dashboard - Teams', - meta: { title: 'Teams Overview' }, + meta: { title: 'Teams Overview', requiresAuth: true }, component: () => import('@/plugins/tm@dashboard/teams/teams.vue') }, { path: '/app/dashboard/projects', name: 'Dashboard - Projects', - meta: { title: 'Projects overview' }, + meta: { title: 'Projects overview', requiresAuth: true }, component: () => import('@/plugins/tm@dashboard/projects/projects.vue') }, { path: '/app/overview/unscheduled', name: 'Overview - Unscheduled tasks', - meta: { title: 'Unscheduled tasks' }, + meta: { title: 'Unscheduled tasks', requiresAuth: true }, component: () => import('@/plugins/tm@overview/tasks-unscheduled/tasks-unscheduled.vue') }, { path: '/app/overview/ongoing', name: 'Overview - Ongoing tasks', - meta: { title: 'Ongoing tasks' }, + meta: { title: 'Ongoing tasks', requiresAuth: true }, component: () => import('@/plugins/tm@overview/tasks-ongoing/tasks-ongoing.vue') }, { path: '/app/overview/teams', name: 'Overview - Teams', - meta: { title: 'Teams' }, + meta: { title: 'Teams', requiresAuth: true }, component: () => import('@/plugins/tm@overview/teams/teams.vue') }, { path: '/app/dashboard/user', name: 'Dashboard - User', - meta: { title: 'Profile' }, + meta: { title: 'Profile', requiresAuth: true }, component: () => import('@/plugins/tm@profile/profile/my-profile.vue') }, { path: '/app/search', name: 'Search', - meta: { title: 'Search Results' }, + meta: { title: 'Search Results', requiresAuth: true }, component: () => import('@/plugins/lib@search/search/search.vue') } ] @@ -98,7 +102,8 @@ const routes: Array = [ { path: '/:catchAll(.*)', name: '404', - component: () => import('@/plugins/w@screen/404/404.vue') + component: () => import('@/plugins/w@screen/404/404.vue'), + meta: {requiresAuth: null} } ] @@ -107,4 +112,22 @@ const router = createRouter({ routes }) +router.beforeEach((to, from, next) => { + const isLoggedIn = store.getters['auth/isLoggedIn'] + + if (to.meta.requiresAuth === true) { + if (isLoggedIn) + return next() + else + return next({name: 'Login'}) + } else if (to.meta.requiresAuth === false) { + if (!isLoggedIn) + return next() + else + return next({name: 'Dashboard - Tasks'}) + } else { + return next({name: 'Login'}) + } +}) + export default router diff --git a/app/src/plugins/tm@dashboard/tasks/tasks.vue b/app/src/plugins/tm@dashboard/tasks/tasks.vue index f1b4ca2..b61ca64 100644 --- a/app/src/plugins/tm@dashboard/tasks/tasks.vue +++ b/app/src/plugins/tm@dashboard/tasks/tasks.vue @@ -35,13 +35,12 @@ export default { splitDays() { const days = [] const workingHours = {} - const capacityPerDay = this.$store.getters['auth/user'].work_end - this.$store.getters['auth/user'].work_start this.timelineData.tasks.forEach(task => { if (!workingHours[task.split]) workingHours[task.split] = 0 - if (task.nonWorking) + if (task.nonWorking || task.subtask.is_finished) return workingHours[task.split] += timelineUtils._getDifferenceInHours(task.end, task.start) @@ -52,7 +51,7 @@ export default { id: i + 1, fullname: `${this.filter.employee.name} ${this.filter.employee.surname}`, initials: this.filter.employee.name.charAt(0).toUpperCase() + this.filter.employee.surname.charAt(0).toUpperCase(), - unscheduledTime: capacityPerDay - workingHours[i + 1], + unscheduledTime: workingHours[i + 1], date: addDays(this.filter.start, i), isWeekend: timelineUtils.isWeekend(addDays(this.filter.start, i)) }) diff --git a/app/src/plugins/tm@dashboard/teams/_components/a-team-filter.vue b/app/src/plugins/tm@dashboard/teams/_components/a-team-filter.vue index 119f133..e9a0e8e 100644 --- a/app/src/plugins/tm@dashboard/teams/_components/a-team-filter.vue +++ b/app/src/plugins/tm@dashboard/teams/_components/a-team-filter.vue @@ -25,6 +25,7 @@ label="Nenaplánované hodiny" v-model="time" variant="outlined" + :disabled="true" > diff --git a/app/src/plugins/tm@dashboard/teams/teams.vue b/app/src/plugins/tm@dashboard/teams/teams.vue index f53c7d4..b1b8b02 100644 --- a/app/src/plugins/tm@dashboard/teams/teams.vue +++ b/app/src/plugins/tm@dashboard/teams/teams.vue @@ -37,7 +37,6 @@ export default { this.filter.team.employees.forEach((employee, index) => { let workingHours = 0 - const capacityPerDay = employee.work_end - employee.work_start this.timelineData.tasks.forEach(task => { if (task?.subtask?.employee_id == employee.id) @@ -49,7 +48,7 @@ export default { name: employee.name, fullname: `${employee.name} ${employee.surname}`, initials: employee.name.charAt(0).toUpperCase() + employee.surname.charAt(0).toUpperCase(), - unscheduledTime: capacityPerDay - workingHours + unscheduledTime: workingHours }) }) diff --git a/app/src/plugins/tm@modal/task/z-complete-task-modal.vue b/app/src/plugins/tm@modal/task/z-complete-task-modal.vue index d10954e..b113d95 100644 --- a/app/src/plugins/tm@modal/task/z-complete-task-modal.vue +++ b/app/src/plugins/tm@modal/task/z-complete-task-modal.vue @@ -2,7 +2,7 @@
-

Ste si istý, že chcete {{ this.subtask.is_finished ? 'znovu otvoriť' : 'dokončiť' }} task, z masterTasku {{ subtask?.master_task?.name || subtask.master_task }}?

+

Ste si istý, že chcete {{ subtask.is_finished ? 'znovu otvoriť' : 'dokončiť' }} task, z masterTasku {{ subtask?.master_task?.name || subtask.master_task }}?