fix(auth): restringe workshop/mecanico solo por servidor y cookie
- Elimina el script inline que redirigia a todos los usuarios. - auth_bp.py: la respuesta de login ahora setea cookie pos_role. - app.py: before_request redirige a /pos/workshop solo cuando la cookie indica rol workshop/mechanic (no depende de JS cacheado). - login.js/login.min.js/app-init.js: sincronizan/limpian la cookie pos_role junto con el token en login y logout. Tests: 35 passed
This commit is contained in:
14
pos/app.py
14
pos/app.py
@@ -1,4 +1,4 @@
|
||||
from flask import Flask
|
||||
from flask import Flask, request, redirect
|
||||
from json_provider import OrjsonProvider
|
||||
|
||||
|
||||
@@ -10,6 +10,18 @@ def create_app():
|
||||
from middleware_tenant import resolve_tenant
|
||||
app.before_request(resolve_tenant)
|
||||
|
||||
# ─── Server-side guard: workshop/mechanic users only see /pos/workshop ──────
|
||||
@app.before_request
|
||||
def restrict_workshop_users():
|
||||
path = request.path
|
||||
if not path.startswith('/pos/'):
|
||||
return
|
||||
if path == '/pos/workshop' or path.startswith('/pos/static/') or path.startswith('/pos/api/') or path == '/pos/sw.js' or path == '/pos/login' or path.startswith('/pos/login'):
|
||||
return
|
||||
role = request.cookies.get('pos_role', '').lower()
|
||||
if role in ('workshop', 'mechanic'):
|
||||
return redirect('/pos/workshop')
|
||||
|
||||
# ─── PWA: Service Worker must be served from /pos/ scope ──────
|
||||
@app.route('/pos/sw.js')
|
||||
def pos_sw():
|
||||
|
||||
Reference in New Issue
Block a user