Fix: Add truncate-table endpoint and improve dark mode visibility for usernames
- Added missing /api/maintenance/truncate-table endpoint to fix 404 error - Fixed dark mode visibility issue for usernames in Current Users table - Added explicit color styling for username strong tags in both light and dark modes
This commit is contained in:
@@ -5216,6 +5216,86 @@ def drop_table():
|
|||||||
}), 500
|
}), 500
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/api/maintenance/truncate-table', methods=['POST'])
|
||||||
|
@admin_plus
|
||||||
|
def truncate_table():
|
||||||
|
"""Truncate a database table - removes all rows but keeps structure"""
|
||||||
|
try:
|
||||||
|
data = request.json
|
||||||
|
table_name = data.get('table_name', '').strip()
|
||||||
|
|
||||||
|
if not table_name:
|
||||||
|
return jsonify({
|
||||||
|
'success': False,
|
||||||
|
'message': 'Table name is required'
|
||||||
|
}), 400
|
||||||
|
|
||||||
|
# Validate table name to prevent SQL injection
|
||||||
|
if not table_name.replace('_', '').isalnum():
|
||||||
|
return jsonify({
|
||||||
|
'success': False,
|
||||||
|
'message': 'Invalid table name format'
|
||||||
|
}), 400
|
||||||
|
|
||||||
|
# Load database config directly
|
||||||
|
settings_file = os.path.join(current_app.instance_path, 'external_server.conf')
|
||||||
|
config = {}
|
||||||
|
with open(settings_file, 'r') as f:
|
||||||
|
for line in f:
|
||||||
|
if '=' in line:
|
||||||
|
key, value = line.strip().split('=', 1)
|
||||||
|
config[key] = value
|
||||||
|
|
||||||
|
conn = mariadb.connect(
|
||||||
|
host=config.get('server_domain', 'localhost'),
|
||||||
|
port=int(config.get('port', '3306')),
|
||||||
|
user=config.get('username', 'root'),
|
||||||
|
password=config.get('password', ''),
|
||||||
|
database=config.get('database_name', 'trasabilitate')
|
||||||
|
)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# Verify table exists and get row count
|
||||||
|
cursor.execute("""
|
||||||
|
SELECT COUNT(*) as count
|
||||||
|
FROM information_schema.TABLES
|
||||||
|
WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s
|
||||||
|
""", (config.get('database_name', 'trasabilitate'), table_name))
|
||||||
|
|
||||||
|
result = cursor.fetchone()
|
||||||
|
if not result or result[0] == 0:
|
||||||
|
cursor.close()
|
||||||
|
conn.close()
|
||||||
|
return jsonify({
|
||||||
|
'success': False,
|
||||||
|
'message': f'Table "{table_name}" does not exist'
|
||||||
|
}), 404
|
||||||
|
|
||||||
|
# Get current row count before truncating
|
||||||
|
cursor.execute(f"SELECT COUNT(*) FROM `{table_name}`")
|
||||||
|
row_count = cursor.fetchone()[0]
|
||||||
|
|
||||||
|
# Truncate the table
|
||||||
|
cursor.execute(f"TRUNCATE TABLE `{table_name}`")
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
cursor.close()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'success': True,
|
||||||
|
'message': f'Table "{table_name}" has been cleared successfully',
|
||||||
|
'rows_cleared': row_count,
|
||||||
|
'structure_preserved': True
|
||||||
|
})
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
return jsonify({
|
||||||
|
'success': False,
|
||||||
|
'message': f'Failed to truncate table: {str(e)}'
|
||||||
|
}), 500
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/api/backup/table', methods=['POST'])
|
@bp.route('/api/backup/table', methods=['POST'])
|
||||||
@admin_plus
|
@admin_plus
|
||||||
def backup_single_table():
|
def backup_single_table():
|
||||||
|
|||||||
@@ -245,6 +245,15 @@
|
|||||||
background-color: rgba(255, 255, 255, 0.075) !important;
|
background-color: rgba(255, 255, 255, 0.075) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Theme-aware username styling */
|
||||||
|
body.light-mode .user-management-page .table td strong {
|
||||||
|
color: #000 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
body.dark-mode .user-management-page .table td strong {
|
||||||
|
color: #fff !important;
|
||||||
|
}
|
||||||
|
|
||||||
/* Theme-aware form elements */
|
/* Theme-aware form elements */
|
||||||
.user-management-page .form-control {
|
.user-management-page .form-control {
|
||||||
border: 1px solid #ced4da !important;
|
border: 1px solid #ced4da !important;
|
||||||
|
|||||||
Reference in New Issue
Block a user