Add workshop module toggle in Modules & Integrations settings
This commit is contained in:
@@ -183,13 +183,20 @@
|
||||
};
|
||||
|
||||
// ─── Page guard based on role + permissions ───
|
||||
function moduleEnabled(key) {
|
||||
try {
|
||||
var modules = JSON.parse(localStorage.getItem('pos_modules') || '{}');
|
||||
return modules[key] !== false;
|
||||
} catch(e) { return true; }
|
||||
}
|
||||
|
||||
function isPageAllowed(pagePath, userRole, userPerms) {
|
||||
if (userRole === 'owner' || userRole === 'admin') return true;
|
||||
|
||||
// Restricted roles (workshop/mechanic/counter/cashier) see modules based on permissions.
|
||||
if (['workshop', 'mechanic', 'counter', 'cashier'].indexOf(userRole) !== -1) {
|
||||
var allowed = [];
|
||||
if (userRole === 'workshop' || userRole === 'mechanic') {
|
||||
if ((userRole === 'workshop' || userRole === 'mechanic') && moduleEnabled('workshop')) {
|
||||
allowed = ['/pos/workshop'];
|
||||
}
|
||||
var permMap = {
|
||||
@@ -208,6 +215,8 @@
|
||||
};
|
||||
for (var p in permMap) {
|
||||
if (userPerms.indexOf(p) !== -1 && allowed.indexOf(permMap[p]) === -1) {
|
||||
// Hide workshop if its module is disabled
|
||||
if (permMap[p] === '/pos/workshop' && !moduleEnabled('workshop')) continue;
|
||||
allowed.push(permMap[p]);
|
||||
}
|
||||
}
|
||||
@@ -229,7 +238,9 @@
|
||||
fallback = '/pos/dashboard';
|
||||
} else if (['workshop', 'mechanic', 'counter', 'cashier'].indexOf(userRole) !== -1) {
|
||||
var allowed = [];
|
||||
if (userRole === 'workshop' || userRole === 'mechanic') allowed = ['/pos/workshop'];
|
||||
if ((userRole === 'workshop' || userRole === 'mechanic') && moduleEnabled('workshop')) {
|
||||
allowed = ['/pos/workshop'];
|
||||
}
|
||||
var permMap = {
|
||||
'pos.sell': '/pos/sale',
|
||||
'pos.view': '/pos/sale',
|
||||
@@ -246,6 +257,7 @@
|
||||
};
|
||||
for (var p in permMap) {
|
||||
if (userPerms.indexOf(p) !== -1 && allowed.indexOf(permMap[p]) === -1) {
|
||||
if (permMap[p] === '/pos/workshop' && !moduleEnabled('workshop')) continue;
|
||||
allowed.push(permMap[p]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user