|
@@ -84,9 +84,28 @@ class AuditService:
|
|
|
readable_action = self._get_readable_action(action)
|
|
readable_action = self._get_readable_action(action)
|
|
|
formatted_details = self._format_details(details)
|
|
formatted_details = self._format_details(details)
|
|
|
|
|
|
|
|
|
|
+ user_email = "System"
|
|
|
|
|
+ if user_id:
|
|
|
|
|
+ user_info = db.execute_query("SELECT email FROM users WHERE id = %s", (user_id,))
|
|
|
|
|
+ if user_info:
|
|
|
|
|
+ user_email = user_info[0]['email']
|
|
|
|
|
+
|
|
|
message = f"<b>Audit Log:</b> {readable_action}\n"
|
|
message = f"<b>Audit Log:</b> {readable_action}\n"
|
|
|
|
|
+ message += f"<b>By:</b> {user_email}\n"
|
|
|
|
|
+
|
|
|
if target_type:
|
|
if target_type:
|
|
|
- message += f"<b>Target:</b> {target_type} (ID: {target_id})\n"
|
|
|
|
|
|
|
+ target_display = f"{target_type} (ID: {target_id})"
|
|
|
|
|
+ if target_type == 'user':
|
|
|
|
|
+ t_user = db.execute_query("SELECT email FROM users WHERE id = %s", (target_id,))
|
|
|
|
|
+ if t_user:
|
|
|
|
|
+ target_display += f" - {t_user[0]['email']}"
|
|
|
|
|
+ elif target_type == 'order':
|
|
|
|
|
+ t_order = db.execute_query("SELECT first_name FROM orders WHERE id = %s", (target_id,))
|
|
|
|
|
+ if t_order:
|
|
|
|
|
+ target_display += f" - {t_order[0]['first_name']}"
|
|
|
|
|
+
|
|
|
|
|
+ message += f"<b>Target:</b> {target_display}\n"
|
|
|
|
|
+
|
|
|
if formatted_details:
|
|
if formatted_details:
|
|
|
message += f"<b>Details:</b>{formatted_details}"
|
|
message += f"<b>Details:</b>{formatted_details}"
|
|
|
|
|
|