fix: satisfy Ruff lint checks
Lint / Lint (Node/Svelte) (push) Successful in 14s
Lint / Lint (Go) (push) Successful in 16s
Lint / Lint (Python) (push) Successful in 9s
Tests / Test (Node/Svelte) (push) Successful in 14s
Tests / Test (Go) (push) Successful in 18s
Tests / Test (Python) (push) Successful in 10s

This commit is contained in:
Gabriel20xx committed 2026-08-05 16:00:40 +02:00
1 parent da97fd4fb1
commit 2093c39ed2
3 files changed
+23 -12

No files matched your search

@@ -1,10 +1,10 @@
"""Shared PostgreSQL and authentication primitives for Python services."""
from .auth import (
RESET_CODE_TTL,
ROLE_ADMIN,
ROLE_SUPERADMIN,
ROLE_USER,
RESET_CODE_TTL,
AuthStore,
AuthUser,
ResetManager,
@@ -16,8 +16,8 @@ from .auth import (
)
from .config import DatabaseConfig, database_url_from_env
from .postgres import Database
from .totp import generate_totp_secret, totp_provisioning_uri, verify_totp
from .tokens import hash_token, new_session_token
from .totp import generate_totp_secret, totp_provisioning_uri, verify_totp
__all__ = [
"AuthStore",
@@ -63,7 +63,10 @@ def can_manage_users(role: str | None) -> bool:
def can_assign_role(actor_role: str | None, target_role: str | None) -> bool:
return normalize_role(actor_role) == ROLE_SUPERADMIN and normalize_role(target_role) != ROLE_SUPERADMIN
return (
normalize_role(actor_role) == ROLE_SUPERADMIN
and normalize_role(target_role) != ROLE_SUPERADMIN
)
class ResetManager:
@@ -153,7 +156,8 @@ class AuthStore:
"""
INSERT INTO auth_users (username, email, password_hash, role, updated_at)
VALUES ($1, $2, $3,
CASE WHEN EXISTS (SELECT 1 FROM auth_users) THEN 'user' ELSE 'superadmin' END,
CASE WHEN EXISTS (SELECT 1 FROM auth_users) THEN 'user'
ELSE 'superadmin' END,
now())
RETURNING id, username, email, password_hash, role, created_at, updated_at
""",
@@ -256,17 +260,23 @@ class AuthStore:
) -> None:
fields: list[str] = []
values: list[object] = []
for column, value in (("username", username), ("email", email), ("password_hash", password_hash), ("role", normalize_role(role) if role is not None else None)):
for column, value in (
("username", username),
("email", email),
("password_hash", password_hash),
("role", normalize_role(role) if role is not None else None),
):
if value is not None:
fields.append(f"{column} = ${len(values) + 1}")
values.append(value)
if not fields:
return
values.append(user_id)
await self.database.execute(
f"UPDATE auth_users SET {', '.join(fields)}, updated_at = now() WHERE id = ${len(values)}",
*values,
query = (
f"UPDATE auth_users SET {', '.join(fields)}, "
f"updated_at = now() WHERE id = ${len(values)}"
)
await self.database.execute(query, *values)
async def delete_user(self, user_id: int) -> None:
await self.database.execute("DELETE FROM auth_users WHERE id = $1", user_id)
@@ -284,7 +294,8 @@ class AuthStore:
async def set_totp_secret(self, user_id: int, secret: str) -> None:
await self.database.execute(
"UPDATE auth_users SET totp_secret = $1, totp_enabled = false, updated_at = now() WHERE id = $2",
"UPDATE auth_users SET totp_secret = $1, totp_enabled = false, "
"updated_at = now() WHERE id = $2",
secret,
user_id,
)
@@ -298,7 +309,8 @@ class AuthStore:
async def disable_totp(self, user_id: int) -> None:
await self.database.execute(
"UPDATE auth_users SET totp_secret = '', totp_enabled = false, updated_at = now() WHERE id = $1",
"UPDATE auth_users SET totp_secret = '', totp_enabled = false, "
"updated_at = now() WHERE id = $1",
user_id,
)