refactor: replace role-based access checks with canAccess utility in menu components
Some checks failed
Spell Check / Spell Check with Typos (push) Failing after 7s

This commit is contained in:
puriphatt 2025-07-02 14:58:44 +07:00
parent 57660d7991
commit 8799799214
4 changed files with 131 additions and 111 deletions

View file

@ -1,5 +1,5 @@
import { RouteRecordRaw } from 'vue-router';
import { isRoleInclude } from 'stores/utils';
import { isRoleInclude, canAccess } from 'stores/utils';
const routes: RouteRecordRaw[] = [
{
@ -16,21 +16,8 @@ const routes: RouteRecordRaw[] = [
path: '/branch-management',
name: 'BranchManagement',
beforeEnter: (to, from, next) => {
if (
isRoleInclude([
'admin',
'branch_admin',
'head_of_admin',
'head_of_account',
'system',
'owner',
'branch_manager',
])
) {
next();
} else {
next('/');
}
if (canAccess('branch')) next();
else next('/');
},
component: () => import('pages/01_branch-management/MainPage.vue'),
},
@ -38,36 +25,36 @@ const routes: RouteRecordRaw[] = [
path: '/personnel-management',
name: 'PersonnelManagement',
beforeEnter: (to, from, next) => {
if (
isRoleInclude([
'admin',
'branch_admin',
'head_of_admin',
'system',
'owner',
'branch_manager',
])
) {
next();
} else {
next('/');
}
if (canAccess('personnel')) next();
else next('/');
},
component: () => import('pages/02_personnel-management/MainPage.vue'),
},
{
path: '/customer-management',
name: 'CustomerManagement',
beforeEnter: (to, from, next) => {
if (canAccess('customer')) next();
else next('/');
},
component: () => import('pages/03_customer-management/MainPage.vue'),
},
{
path: '/customer-management/:customerId',
name: 'CustomerSpecificManagement',
beforeEnter: (to, from, next) => {
if (canAccess('customer')) next();
else next('/');
},
component: () => import('pages/03_customer-management/MainPage.vue'),
},
{
path: '/customer-management/:customerId/branch',
name: 'CustomerBranchManagement',
beforeEnter: (to, from, next) => {
if (canAccess('customer')) next();
else next('/');
},
component: () => import('pages/03_customer-management/MainPage.vue'),
},
{
@ -78,11 +65,19 @@ const routes: RouteRecordRaw[] = [
{
path: '/workflow',
name: 'Workflow',
beforeEnter: (to, from, next) => {
if (canAccess('workflow')) next();
else next('/');
},
component: () => import('pages/04_flow-managment/MainPage.vue'),
},
{
path: '/property',
name: 'Property',
beforeEnter: (to, from, next) => {
if (canAccess('workflow')) next();
else next('/');
},
component: () => import('pages/04_property-managment/MainPage.vue'),
},
{
@ -98,6 +93,10 @@ const routes: RouteRecordRaw[] = [
{
path: '/agencies-management',
name: 'agencies-management',
beforeEnter: (to, from, next) => {
if (canAccess('agencies')) next();
else next('/');
},
component: () => import('pages/07_agencies-management/MainPage.vue'),
},
{
@ -138,6 +137,10 @@ const routes: RouteRecordRaw[] = [
{
path: '/dash-board',
name: 'dashBoard',
beforeEnter: (to, from, next) => {
if (canAccess('dashBoard')) next();
else next('/');
},
component: () => import('pages/15_dash-board/MainPage.vue'),
},
{
@ -225,7 +228,7 @@ const routes: RouteRecordRaw[] = [
},
{
path: '/receipt/:id',
name: 'receiptform',
name: 'receiptForm',
component: () => import('pages/13_receipt/MainPage.vue'),
},
{