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
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:
1 parent
da97fd4fb1
commit
2093c39ed2
3 files changed
+23
-12
No files matched your search
@@ -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,
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user