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).
This commit is contained in:
maziggy
2026-02-06 12:32:29 +01:00
parent 42fd6d95a0
commit 93f416b922
3 changed files with 9 additions and 22 deletions
-15
View File
@@ -87,21 +87,6 @@ async def setup_auth(request: SetupRequest, db: AsyncSession = Depends(get_db)):
logger = logging.getLogger(__name__)
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)
admin_created = False
+2
View File
@@ -135,9 +135,11 @@ class FirmwareCheckService:
release_time=latest.get("release_time"),
)
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)
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)
return None
+7 -7
View File
@@ -1022,7 +1022,7 @@ export function SettingsPage() {
<Users className="w-4 h-4" />
{t('settings.tabs.users')}
{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
@@ -2406,9 +2406,9 @@ export function SettingsPage() {
{plugEnergySummary.totalToday.toFixed(2)}
<span className="text-sm font-normal text-bambu-gray ml-1">kWh</span>
</div>
{localSettings && localSettings.energy_cost_per_kwh > 0 && (
{(localSettings?.energy_cost_per_kwh ?? 0) > 0 && (
<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>
@@ -2423,9 +2423,9 @@ export function SettingsPage() {
{plugEnergySummary.totalYesterday.toFixed(2)}
<span className="text-sm font-normal text-bambu-gray ml-1">kWh</span>
</div>
{localSettings && localSettings.energy_cost_per_kwh > 0 && (
{(localSettings?.energy_cost_per_kwh ?? 0) > 0 && (
<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>
@@ -2440,9 +2440,9 @@ export function SettingsPage() {
{plugEnergySummary.totalLifetime.toFixed(1)}
<span className="text-sm font-normal text-bambu-gray ml-1">kWh</span>
</div>
{localSettings && localSettings.energy_cost_per_kwh > 0 && (
{(localSettings?.energy_cost_per_kwh ?? 0) > 0 && (
<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>