From 982315bdaf0c5b9e600df9cdb181b5833dd9d156 Mon Sep 17 00:00:00 2001
From: consultoria-as
Date: Thu, 2 Jul 2026 22:37:28 +0000
Subject: [PATCH] feat(permissions): add dashboard.view permission for
cashier/counter/workshop
---
pos/blueprints/config_bp.py | 3 +++
pos/static/js/app-init.js | 18 ++++++++++++------
pos/static/js/sidebar.js | 11 ++++++++---
pos/templates/accounting.html | 4 ++--
pos/templates/catalog.html | 4 ++--
pos/templates/config.html | 4 ++--
pos/templates/customers.html | 4 ++--
pos/templates/dashboard.html | 4 ++--
pos/templates/diagrams.html | 4 ++--
pos/templates/fleet.html | 4 ++--
pos/templates/inventory.html | 4 ++--
pos/templates/invoicing.html | 4 ++--
pos/templates/marketplace_external.html | 4 ++--
pos/templates/pos.html | 2 +-
pos/templates/quotations.html | 4 ++--
pos/templates/remission_notes.html | 4 ++--
pos/templates/reports.html | 4 ++--
pos/templates/supplier_catalog.html | 4 ++--
pos/templates/whatsapp.html | 4 ++--
pos/templates/workshop.html | 4 ++--
20 files changed, 56 insertions(+), 42 deletions(-)
diff --git a/pos/blueprints/config_bp.py b/pos/blueprints/config_bp.py
index ad4140f..843afe5 100644
--- a/pos/blueprints/config_bp.py
+++ b/pos/blueprints/config_bp.py
@@ -46,6 +46,9 @@ _DEFAULT_ROLE_PERMISSIONS = {
_AVAILABLE_PERMISSIONS = [
+ {'module': 'Dashboard', 'permissions': [
+ {'key': 'dashboard.view', 'label': 'Ver Dashboard'},
+ ]},
{'module': 'Punto de Venta', 'permissions': [
{'key': 'pos.sell', 'label': 'Realizar ventas'},
{'key': 'pos.view', 'label': 'Ver ventas/cotizaciones'},
diff --git a/pos/static/js/app-init.js b/pos/static/js/app-init.js
index 170afdf..644dba0 100644
--- a/pos/static/js/app-init.js
+++ b/pos/static/js/app-init.js
@@ -201,7 +201,8 @@
'accounting.view': '/pos/accounting',
'reports.view': '/pos/reports',
'config.view': '/pos/config',
- 'config.edit': '/pos/config'
+ 'config.edit': '/pos/config',
+ 'dashboard.view': '/pos/dashboard'
};
for (var p in permMap) {
if (userPerms.indexOf(p) !== -1 && allowed.indexOf(permMap[p]) === -1) {
@@ -211,14 +212,18 @@
return allowed.indexOf(pagePath) !== -1;
}
- // Counter: fixed module set (no dashboard).
+ // Counter: fixed module set. Dashboard only if explicitly granted.
if (userRole === 'counter') {
- return ['/pos/sale','/pos/catalog','/pos/inventory','/pos/customers','/pos/workshop','/pos/remission-notes','/pos/reports'].indexOf(pagePath) !== -1;
+ var allowed = ['/pos/sale','/pos/catalog','/pos/inventory','/pos/customers','/pos/workshop','/pos/remission-notes','/pos/reports'];
+ if (userPerms.indexOf('dashboard.view') !== -1) allowed.push('/pos/dashboard');
+ return allowed.indexOf(pagePath) !== -1;
}
- // Cashier: fixed module set (no dashboard).
+ // Cashier: fixed module set. Dashboard only if explicitly granted.
if (userRole === 'cashier') {
- return ['/pos/sale','/pos/catalog','/pos/inventory','/pos/customers','/pos/workshop','/pos/remission-notes','/pos/invoicing','/pos/reports'].indexOf(pagePath) !== -1;
+ var allowed = ['/pos/sale','/pos/catalog','/pos/inventory','/pos/customers','/pos/workshop','/pos/remission-notes','/pos/invoicing','/pos/reports'];
+ if (userPerms.indexOf('dashboard.view') !== -1) allowed.push('/pos/dashboard');
+ return allowed.indexOf(pagePath) !== -1;
}
// Always allow login/logout pages so users can sign out without hitting the guard.
@@ -287,8 +292,9 @@
(function hideBackToSystemForRestrictedRoles() {
var backBtn = document.getElementById('backToSystemBtn');
if (!backBtn) return;
- // owner/admin are the only roles that should see the dashboard shortcut from POS.
+ // owner/admin always see it; others only if they have dashboard.view.
if (role === 'owner' || role === 'admin') return;
+ if ((window.POS_USER.permissions || []).indexOf('dashboard.view') !== -1) return;
backBtn.style.display = 'none';
})();
diff --git a/pos/static/js/sidebar.js b/pos/static/js/sidebar.js
index 8ce7889..d34af9d 100644
--- a/pos/static/js/sidebar.js
+++ b/pos/static/js/sidebar.js
@@ -53,7 +53,8 @@ window.renderSidebar = function(modulesOverride) {
'invoicing.view': 'invoicing',
'quotations.view': 'quotations',
'accounting.view': 'accounting',
- 'reports.view': 'reports'
+ 'reports.view': 'reports',
+ 'dashboard.view': 'dashboard'
};
for (var p in permMap) {
if (perms.indexOf(p) !== -1 && allowed.indexOf(permMap[p]) === -1) {
@@ -63,10 +64,14 @@ window.renderSidebar = function(modulesOverride) {
return allowed.indexOf(id) !== -1;
}
if (role === 'counter') {
- return ['pos','catalog','inventory','customers','workshop','remission_notes','reports'].indexOf(id) !== -1;
+ var allowed = ['pos','catalog','inventory','customers','workshop','remission_notes','reports'];
+ if (hasPerm('dashboard.view')) allowed.push('dashboard');
+ return allowed.indexOf(id) !== -1;
}
if (role === 'cashier') {
- return ['pos','catalog','inventory','customers','workshop','remission_notes','invoicing','reports'].indexOf(id) !== -1;
+ var allowed = ['pos','catalog','inventory','customers','workshop','remission_notes','invoicing','reports'];
+ if (hasPerm('dashboard.view')) allowed.push('dashboard');
+ return allowed.indexOf(id) !== -1;
}
return true;
}
diff --git a/pos/templates/accounting.html b/pos/templates/accounting.html
index 469fcf6..e2f293e 100644
--- a/pos/templates/accounting.html
+++ b/pos/templates/accounting.html
@@ -493,10 +493,10 @@
-
+
-
+
diff --git a/pos/templates/catalog.html b/pos/templates/catalog.html
index 1e6d51a..913a2c9 100644
--- a/pos/templates/catalog.html
+++ b/pos/templates/catalog.html
@@ -316,10 +316,10 @@
-
+
-
+
diff --git a/pos/templates/config.html b/pos/templates/config.html
index e50f453..943f1a0 100644
--- a/pos/templates/config.html
+++ b/pos/templates/config.html
@@ -1016,10 +1016,10 @@
-
+
-
+
diff --git a/pos/templates/customers.html b/pos/templates/customers.html
index 6a1bf2b..13e687c 100644
--- a/pos/templates/customers.html
+++ b/pos/templates/customers.html
@@ -651,10 +651,10 @@
-
+
-
+
diff --git a/pos/templates/dashboard.html b/pos/templates/dashboard.html
index 1dbf2db..b90da34 100644
--- a/pos/templates/dashboard.html
+++ b/pos/templates/dashboard.html
@@ -606,10 +606,10 @@
-
+
-
+
diff --git a/pos/templates/diagrams.html b/pos/templates/diagrams.html
index 4a35f11..45acbe9 100644
--- a/pos/templates/diagrams.html
+++ b/pos/templates/diagrams.html
@@ -150,10 +150,10 @@
-
+
-
+
diff --git a/pos/templates/fleet.html b/pos/templates/fleet.html
index 6bb9ddf..71064b4 100644
--- a/pos/templates/fleet.html
+++ b/pos/templates/fleet.html
@@ -303,10 +303,10 @@
-
+
-
+
diff --git a/pos/templates/inventory.html b/pos/templates/inventory.html
index ea1cc84..cd01121 100644
--- a/pos/templates/inventory.html
+++ b/pos/templates/inventory.html
@@ -1062,10 +1062,10 @@
-
+
-
+
diff --git a/pos/templates/invoicing.html b/pos/templates/invoicing.html
index 17da913..e33c5e2 100644
--- a/pos/templates/invoicing.html
+++ b/pos/templates/invoicing.html
@@ -1064,10 +1064,10 @@
-
+
-
+
diff --git a/pos/templates/marketplace_external.html b/pos/templates/marketplace_external.html
index 4b8b94b..a11ef52 100644
--- a/pos/templates/marketplace_external.html
+++ b/pos/templates/marketplace_external.html
@@ -343,10 +343,10 @@
-
+
-
+
-
+
-
+
Cotizaciones
diff --git a/pos/templates/remission_notes.html b/pos/templates/remission_notes.html
index d3a5b5c..d63c6d7 100644
--- a/pos/templates/remission_notes.html
+++ b/pos/templates/remission_notes.html
@@ -227,8 +227,8 @@
-
-
+
+
-
+
-
+
diff --git a/pos/templates/supplier_catalog.html b/pos/templates/supplier_catalog.html
index 2286bc4..6e6b61b 100644
--- a/pos/templates/supplier_catalog.html
+++ b/pos/templates/supplier_catalog.html
@@ -126,8 +126,8 @@
-
-
+
+