Procházet zdrojové kódy

fix: update quota management to use Path for file handling and improve UI layout

Manuel před 8 měsíci
rodič
revize
8523cb5462

+ 3 - 1
routes/admin/quota.py

@@ -3,6 +3,7 @@
 import os
 import re
 from datetime import datetime, timezone
+from pathlib import Path
 
 from flask import render_template, request
 from loguru import logger
@@ -17,7 +18,8 @@ from services.database.admin_helpers import load_env_vars
 
 from .helpers import flash_and_redirect, get_config_manager
 
-QUOTA_DISABLED_FLAG = os.path.join(os.getcwd(), "quota_disabled")
+PROJECT_ROOT = Path(__file__).resolve().parents[2]
+QUOTA_DISABLED_FLAG = PROJECT_ROOT / "quota_disabled"
 
 
 def is_quota_enabled() -> bool:

+ 5 - 4
services/quota/quota_scheduler.py

@@ -1,6 +1,7 @@
 import os
 import re
 from datetime import datetime
+from pathlib import Path
 from types import SimpleNamespace
 
 from loguru import logger
@@ -26,8 +27,8 @@ def register_quota_scheduler_tasks(scheduler):
     def check_quota_users():
         session = None
         try:
-            quota_disabled_flag = os.path.join(os.getcwd(), "quota_disabled")
-            quota_enabled = not os.path.exists(quota_disabled_flag)
+            quota_disabled_flag = Path(__file__).resolve().parents[2] / "quota_disabled"
+            quota_enabled = not quota_disabled_flag.exists()
             _sync_quota_squid_rules(quota_enabled)
 
             # reinicio mensual 1ero del mes
@@ -307,8 +308,8 @@ def register_quota_scheduler_tasks(scheduler):
         misfire_grace_time=600,
     )
     def reload_squid_if_quota_enabled():
-        quota_disabled_flag = os.path.join(os.getcwd(), "quota_disabled")
-        quota_enabled = not os.path.exists(quota_disabled_flag)
+        quota_disabled_flag = Path(__file__).resolve().parents[2] / "quota_disabled"
+        quota_enabled = not quota_disabled_flag.exists()
 
         if not quota_enabled:
             # logger.debug(

+ 11 - 6
templates/admin/quota.html

@@ -61,12 +61,17 @@
                 <h3 class="text-lg font-semibold">Resumen de Cuotas</h3>
                 <p class="text-sm text-gray-600">Visualiza el estado general de las cuotas de ancho de banda y límites de datos para los usuarios y grupos.</p>
             </div>
-            <form method="POST" action="{{ url_for('admin.toggle_quota') }}" class="shrink-0">
-                <input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
-                <button type="submit" title="Activa o desactiva el control de cuotas para usuarios y grupos" class="px-4 py-2 font-semibold rounded-lg shadow-sm transition-colors duration-150 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 {{ 'bg-red-500 hover:bg-red-600 text-white' if quota_enabled else 'bg-green-500 hover:bg-green-600 text-white' }}">
-                    {{ 'Desactivar cuotas' if quota_enabled else 'Activar cuotas' }}
-                </button>
-            </form>
+            <div class="flex flex-wrap items-center gap-3">
+                <form method="POST" action="{{ url_for('admin.toggle_quota') }}" class="shrink-0">
+                    <input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
+                    <button type="submit" title="Activa o desactiva el control de cuotas para usuarios y grupos" class="px-4 py-2 font-semibold rounded-lg shadow-sm transition-colors duration-150 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 {{ 'bg-red-500 hover:bg-red-600 text-white' if quota_enabled else 'bg-green-500 hover:bg-green-600 text-white' }}">
+                        {{ 'Desactivar cuotas' if quota_enabled else 'Activar cuotas' }}
+                    </button>
+                </form>
+                <span class="inline-flex items-center rounded-full px-3 py-1 text-sm font-medium {{ 'bg-green-100 text-green-800' if quota_enabled else 'bg-red-100 text-red-800' }}">
+                    {{ 'Cuotas habilitadas' if quota_enabled else 'Cuotas deshabilitadas' }}
+                </span>
+            </div>
         </div>
 
         <div class="grid grid-cols-1 md:grid-cols-3 gap-4">