- Add helpers/company_context.py with get_active_company_id() fallback logic - Add inject_company_context() context processor to app.py (user_companies, active_company, has_multiple_companies) - Add /api/switch-company/<id> POST endpoint in public blueprint - Set session['active_company_id'] on login (both standard and 2FA paths) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
15 lines
426 B
Python
15 lines
426 B
Python
"""Company context helpers for multi-company users."""
|
|
|
|
from flask import session
|
|
from flask_login import current_user
|
|
|
|
|
|
def get_active_company_id():
|
|
"""Return the active company ID from session, falling back to users.company_id."""
|
|
if not current_user.is_authenticated:
|
|
return None
|
|
active_id = session.get('active_company_id')
|
|
if active_id:
|
|
return active_id
|
|
return current_user.company_id
|