Fix superadmin access control and modal aria-hidden warning
- Implement role normalization system to handle role name variants (superadmin, super_admin, administrator) - Add session persistence configuration (PERMANENT_SESSION_LIFETIME = 7 days) - Add modules JSON column to users database table schema - Update setup script with backward compatibility check for modules column - Fix user_management_simple route to properly fetch and display modules - Resolve modal aria-hidden accessibility warning by managing focus on close button - All changes deployed and tested successfully
This commit is contained in:
@@ -103,7 +103,15 @@ def login():
|
||||
|
||||
if user:
|
||||
session['user'] = user['username']
|
||||
session['role'] = user['role']
|
||||
session.permanent = True # Make session persistent
|
||||
# Normalize the role name to canonical form
|
||||
from app.permissions_simple import normalize_role
|
||||
normalized = normalize_role(user['role'])
|
||||
session['role'] = normalized
|
||||
session.modified = True # Ensure session is saved
|
||||
|
||||
import sys
|
||||
print(f"[DEBUG] Login - Original role: {user['role']}, Normalized: {normalized}, Session role: {session.get('role')}, Permanent: {session.permanent}", file=sys.stderr)
|
||||
|
||||
# Load user's modules into session
|
||||
user_modules = []
|
||||
@@ -119,6 +127,7 @@ def login():
|
||||
user_modules = ['quality', 'warehouse', 'labels', 'daily_mirror']
|
||||
|
||||
session['modules'] = user_modules
|
||||
session.modified = True # Ensure all session changes are saved
|
||||
|
||||
# Check app license for non-superadmin users
|
||||
if user['role'] != 'superadmin':
|
||||
@@ -318,6 +327,7 @@ def user_management_simple():
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SHOW TABLES LIKE 'users'")
|
||||
if cursor.fetchone():
|
||||
# Select users with modules column
|
||||
cursor.execute("SELECT id, username, role, modules FROM users")
|
||||
for row in cursor.fetchall():
|
||||
user_data = {
|
||||
@@ -348,8 +358,9 @@ def user_management_simple():
|
||||
|
||||
return render_template('user_management_simple.html', users=users)
|
||||
except Exception as e:
|
||||
print(f"Error in user_management_simple: {e}")
|
||||
flash('Error loading user management page.')
|
||||
import traceback
|
||||
error_details = traceback.format_exc()
|
||||
flash(f'Error loading user management page: {str(e)} - {error_details}', 'danger')
|
||||
return redirect(url_for('main.dashboard'))
|
||||
|
||||
@bp.route('/create_user_simple', methods=['POST'])
|
||||
|
||||
Reference in New Issue
Block a user