Sfoglia il codice sorgente

Fix trivial conditionals, commented-out code, and dead variables (CodeQL)

Simplify always-true authEnabled ternary and localSettings truthiness
checks in SettingsPage.tsx. Remove commented-out auth re-setup guard
and its dead _existing_setting/_user_count queries from auth.py.
Add clarifying comments to firmware_check.py api_key logs (model
identifier, not a secret).
maziggy 3 mesi fa
parent
commit
93f416b922

+ 0 - 15
backend/app/api/routes/auth.py

@@ -87,21 +87,6 @@ async def setup_auth(request: SetupRequest, db: AsyncSession = Depends(get_db)):
     logger = logging.getLogger(__name__)
     logger = logging.getLogger(__name__)
 
 
     try:
     try:
-        # Check if auth is already configured (prevent re-setup)
-        result = await db.execute(select(Settings).where(Settings.key == "auth_enabled"))
-        _existing_setting = result.scalar_one_or_none()
-
-        # Check if users exist
-        user_count_result = await db.execute(select(User))
-        _user_count = len(user_count_result.scalars().all())
-
-        # if _existing_setting and _user_count > 0:
-        #    # Auth already configured and users exist - prevent re-setup
-        #    raise HTTPException(
-        #        status_code=status.HTTP_400_BAD_REQUEST,
-        #        detail="Authentication is already configured. Use user management to modify users.",
-        #    )
-
         # If auth_enabled is true but no users exist, allow re-setup (recovery scenario)
         # If auth_enabled is true but no users exist, allow re-setup (recovery scenario)
 
 
         admin_created = False
         admin_created = False

+ 2 - 0
backend/app/services/firmware_check.py

@@ -135,9 +135,11 @@ class FirmwareCheckService:
                         release_time=latest.get("release_time"),
                         release_time=latest.get("release_time"),
                     )
                     )
             else:
             else:
+                # api_key is a printer model identifier (e.g. "x1", "p1"), not a secret
                 logger.warning("Failed to fetch firmware for %s: %s", api_key, response.status_code)
                 logger.warning("Failed to fetch firmware for %s: %s", api_key, response.status_code)
 
 
         except (httpx.HTTPError, OSError, KeyError, ValueError) as e:
         except (httpx.HTTPError, OSError, KeyError, ValueError) as e:
+            # api_key is a printer model identifier (e.g. "x1", "p1"), not a secret
             logger.error("Error fetching firmware for %s: %s", api_key, e)
             logger.error("Error fetching firmware for %s: %s", api_key, e)
 
 
         return None
         return None

+ 7 - 7
frontend/src/pages/SettingsPage.tsx

@@ -1022,7 +1022,7 @@ export function SettingsPage() {
           <Users className="w-4 h-4" />
           <Users className="w-4 h-4" />
           {t('settings.tabs.users')}
           {t('settings.tabs.users')}
           {authEnabled && (
           {authEnabled && (
-            <span className={`w-2 h-2 rounded-full ${authEnabled ? 'bg-green-400' : 'bg-gray-500'}`} />
+            <span className="w-2 h-2 rounded-full bg-green-400" />
           )}
           )}
         </button>
         </button>
         <button
         <button
@@ -2406,9 +2406,9 @@ export function SettingsPage() {
                         {plugEnergySummary.totalToday.toFixed(2)}
                         {plugEnergySummary.totalToday.toFixed(2)}
                         <span className="text-sm font-normal text-bambu-gray ml-1">kWh</span>
                         <span className="text-sm font-normal text-bambu-gray ml-1">kWh</span>
                       </div>
                       </div>
-                      {localSettings && localSettings.energy_cost_per_kwh > 0 && (
+                      {(localSettings?.energy_cost_per_kwh ?? 0) > 0 && (
                         <div className="text-xs text-bambu-gray mt-1">
                         <div className="text-xs text-bambu-gray mt-1">
-                          ~{(plugEnergySummary.totalToday * localSettings.energy_cost_per_kwh).toFixed(2)} {localSettings.currency}
+                          ~{(plugEnergySummary.totalToday * (localSettings?.energy_cost_per_kwh ?? 0)).toFixed(2)} {localSettings?.currency}
                         </div>
                         </div>
                       )}
                       )}
                     </div>
                     </div>
@@ -2423,9 +2423,9 @@ export function SettingsPage() {
                         {plugEnergySummary.totalYesterday.toFixed(2)}
                         {plugEnergySummary.totalYesterday.toFixed(2)}
                         <span className="text-sm font-normal text-bambu-gray ml-1">kWh</span>
                         <span className="text-sm font-normal text-bambu-gray ml-1">kWh</span>
                       </div>
                       </div>
-                      {localSettings && localSettings.energy_cost_per_kwh > 0 && (
+                      {(localSettings?.energy_cost_per_kwh ?? 0) > 0 && (
                         <div className="text-xs text-bambu-gray mt-1">
                         <div className="text-xs text-bambu-gray mt-1">
-                          ~{(plugEnergySummary.totalYesterday * localSettings.energy_cost_per_kwh).toFixed(2)} {localSettings.currency}
+                          ~{(plugEnergySummary.totalYesterday * (localSettings?.energy_cost_per_kwh ?? 0)).toFixed(2)} {localSettings?.currency}
                         </div>
                         </div>
                       )}
                       )}
                     </div>
                     </div>
@@ -2440,9 +2440,9 @@ export function SettingsPage() {
                         {plugEnergySummary.totalLifetime.toFixed(1)}
                         {plugEnergySummary.totalLifetime.toFixed(1)}
                         <span className="text-sm font-normal text-bambu-gray ml-1">kWh</span>
                         <span className="text-sm font-normal text-bambu-gray ml-1">kWh</span>
                       </div>
                       </div>
-                      {localSettings && localSettings.energy_cost_per_kwh > 0 && (
+                      {(localSettings?.energy_cost_per_kwh ?? 0) > 0 && (
                         <div className="text-xs text-bambu-gray mt-1">
                         <div className="text-xs text-bambu-gray mt-1">
-                          ~{(plugEnergySummary.totalLifetime * localSettings.energy_cost_per_kwh).toFixed(2)} {localSettings.currency}
+                          ~{(plugEnergySummary.totalLifetime * (localSettings?.energy_cost_per_kwh ?? 0)).toFixed(2)} {localSettings?.currency}
                         </div>
                         </div>
                       )}
                       )}
                     </div>
                     </div>