Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e1e488f723 | |||
| 0562aee04b | |||
| b1c104f36c |
+51
-16
@@ -8154,10 +8154,26 @@ def admin_audit_dashboard():
|
||||
|
||||
# DEC_START: Decrypt the sensitive fields for display
|
||||
for row in audit_rows:
|
||||
if "payload" in row:
|
||||
# decrypt_document_fields acts in-place
|
||||
decrypt_document_fields(row["payload"], SENSITIVE_AUDIT_FIELDS)
|
||||
# DEC_END
|
||||
payload_raw = row.get("payload")
|
||||
|
||||
if payload_raw and isinstance(payload_raw, str):
|
||||
try:
|
||||
# Safely evaluate the python-like dict string, providing context for ObjectId
|
||||
safe_context = {"ObjectId": ObjectId, "None": None, "True": True, "False": False}
|
||||
payload_dict = eval(payload_raw, {"__builtins__": {}}, safe_context)
|
||||
|
||||
if isinstance(payload_dict, dict):
|
||||
# Decrypt the sensitive keys inside the extracted dictionary
|
||||
decrypt_document_fields(payload_dict, SENSITIVE_AUDIT_FIELDS)
|
||||
|
||||
# Replace the raw string with the clean dictionary for the Jinja template
|
||||
row["payload"] = payload_dict
|
||||
except Exception as parse_err:
|
||||
app.logger.error(f"Failed to parse audit payload string for index {row.get('chain_index')}: {parse_err}")
|
||||
|
||||
elif payload_raw and isinstance(payload_raw, dict):
|
||||
# Fallback in case some newer log rows are already stored as proper dictionaries
|
||||
decrypt_document_fields(payload_raw, SENSITIVE_AUDIT_FIELDS)
|
||||
|
||||
return render_template(
|
||||
'admin_audit.html',
|
||||
@@ -8204,11 +8220,26 @@ def admin_audit_export_pdf_official():
|
||||
|
||||
audit_rows = list(db['audit_log'].find({}).sort('chain_index', -1).limit(limit))
|
||||
|
||||
# DEC_START: Decrypt sensitive fields for the PDF report
|
||||
for row in audit_rows:
|
||||
if "payload" in row:
|
||||
decrypt_document_fields(row["payload"], SENSITIVE_AUDIT_FIELDS)
|
||||
# DEC_END
|
||||
payload_raw = row.get("payload")
|
||||
|
||||
if payload_raw and isinstance(payload_raw, str):
|
||||
try:
|
||||
# Safely evaluate the python-like dict string with custom token support
|
||||
safe_context = {"ObjectId": ObjectId, "None": None, "True": True, "False": False}
|
||||
payload_dict = eval(payload_raw, {"__builtins__": {}}, safe_context)
|
||||
|
||||
if isinstance(payload_dict, dict):
|
||||
# Decrypt the dictionary fields in-place
|
||||
decrypt_document_fields(payload_dict, SENSITIVE_AUDIT_FIELDS)
|
||||
# Replace string with the clean dictionary so the PDF generator can read it
|
||||
row["payload"] = payload_dict
|
||||
except Exception as parse_err:
|
||||
app.logger.error(f"Failed to parse audit payload string for PDF export at index {row.get('chain_index')}: {parse_err}")
|
||||
|
||||
elif payload_raw and isinstance(payload_raw, dict):
|
||||
# Fallback for standard dict payloads
|
||||
decrypt_document_fields(payload_raw, SENSITIVE_AUDIT_FIELDS)
|
||||
|
||||
# Get school information from settings or use defaults
|
||||
school_info = _get_school_info_for_export()
|
||||
@@ -10373,13 +10404,8 @@ def admin_damaged_items():
|
||||
flash('Administratorrechte erforderlich.', 'error')
|
||||
return redirect(url_for('login'))
|
||||
|
||||
'''
|
||||
permissions = _get_current_user_permissions()
|
||||
if not _action_access_allowed(permissions, 'can_manage_settings'):
|
||||
flash('Sie haben keine Berechtigung, die Schulstammdaten zu ändern.', 'error')
|
||||
if cfg.MODULES.is_enabled('library'):
|
||||
return redirect(url_for('library_admin'))
|
||||
'''
|
||||
# Import the decryption handler if it's not already at the top of the file
|
||||
from modules.inventarsystem.data_protection import decrypt_text
|
||||
|
||||
client = None
|
||||
try:
|
||||
@@ -10419,9 +10445,18 @@ def admin_damaged_items():
|
||||
{'Item': item_id, 'Status': {'$in': ['active', 'planned']}},
|
||||
{'_id': 1, 'User': 1, 'Status': 1, 'End': 1}
|
||||
)
|
||||
|
||||
# Decrypt the borrower inside the active loan tracking object
|
||||
if active_borrow and active_borrow.get('User'):
|
||||
active_borrow['User'] = decrypt_text(active_borrow['User'])
|
||||
|
||||
reports = item_doc.get('DamageReports', []) or []
|
||||
latest_report = reports[0] if reports else {}
|
||||
|
||||
# Decrypt the static snapshot borrower field on the item itself
|
||||
raw_user = item_doc.get('User', '')
|
||||
decrypted_user = decrypt_text(raw_user) if raw_user else ''
|
||||
|
||||
damaged_rows.append({
|
||||
'id': item_id,
|
||||
'name': item_doc.get('Name', ''),
|
||||
@@ -10431,7 +10466,7 @@ def admin_damaged_items():
|
||||
'isbn': item_doc.get('ISBN', ''),
|
||||
'condition': item_doc.get('Condition', ''),
|
||||
'available': bool(item_doc.get('Verfuegbar', False)),
|
||||
'borrow_user': item_doc.get('User', ''),
|
||||
'borrow_user': decrypted_user,
|
||||
'damage_count': len(reports),
|
||||
'damage_reports': reports,
|
||||
'latest_damage_description': latest_report.get('description', ''),
|
||||
|
||||
Reference in New Issue
Block a user