fix(platform): address round-3 review — lazy logging, aria-label, colSpan, key uniqueness

- Replace f-string with %s lazy formatting in logger.info calls
- Remove email echo from 404 error detail (defense-in-depth)
- Add aria-label to AdminUserSearch input for accessibility
- Add toast to useEffect dependency array in RateLimitModal
- Fix colSpan={8} -> colSpan={9} to match 9-column table header
- Use composite key for TableRow to avoid duplicate React keys
- Remove redundant `as UserTransaction[]` cast and unused import
This commit is contained in:
Zamil Majdy
2026-03-27 10:40:52 +07:00
parent 35ccf41d11
commit 4cc46236a6
5 changed files with 11 additions and 9 deletions

View File

@@ -47,7 +47,7 @@ async def _resolve_user_id(
user = await get_user_by_email(email)
if not user:
raise HTTPException(
status_code=404, detail=f"No user found with email: {email}"
status_code=404, detail="No user found with the provided email."
)
return user.id, email
@@ -84,7 +84,7 @@ async def get_user_rate_limit(
"""
resolved_id, resolved_email = await _resolve_user_id(user_id, email)
logger.info(f"Admin {admin_user_id} checking rate limit for user {resolved_id}")
logger.info("Admin %s checking rate limit for user %s", admin_user_id, resolved_id)
daily_limit, weekly_limit = await get_global_rate_limits(
resolved_id, config.daily_token_limit, config.weekly_token_limit
@@ -113,8 +113,10 @@ async def reset_user_rate_limit(
) -> UserRateLimitResponse:
"""Reset a user's daily usage counter (and optionally weekly). Admin-only."""
logger.info(
f"Admin {admin_user_id} resetting rate limit for user {user_id} "
f"(reset_weekly={reset_weekly})"
"Admin %s resetting rate limit for user %s (reset_weekly=%s)",
admin_user_id,
user_id,
reset_weekly,
)
try:

View File

@@ -51,6 +51,7 @@ export function AdminUserSearch({
<div className="flex w-full items-center gap-2">
<Input
placeholder={placeholder}
aria-label={placeholder}
value={currentValue}
onChange={(e) => handleChange(e.target.value)}
onKeyDown={(e) => e.key === "Enter" && handleSearch()}

View File

@@ -3,7 +3,6 @@
import { useState } from "react";
import { useToast } from "@/components/molecules/Toast/use-toast";
import type { UserRateLimitResponse } from "@/app/api/__generated__/models/userRateLimitResponse";
import type { UserTransaction } from "@/app/api/__generated__/models/userTransaction";
import {
getV2GetUserRateLimit,
getV2GetAllUsersHistory,
@@ -98,7 +97,7 @@ export function useRateLimitManager() {
// Deduplicate by user_id to get unique users
const seen = new Set<string>();
const users: UserOption[] = [];
for (const tx of response.data.history as UserTransaction[]) {
for (const tx of response.data.history) {
if (!seen.has(tx.user_id)) {
seen.add(tx.user_id);
users.push({

View File

@@ -103,7 +103,7 @@ export async function AdminUserGrantHistory({
{history.length === 0 ? (
<TableRow>
<TableCell
colSpan={8}
colSpan={9}
className="py-10 text-center text-gray-500"
>
No transactions found
@@ -112,7 +112,7 @@ export async function AdminUserGrantHistory({
) : (
history.map((transaction) => (
<TableRow
key={transaction.user_id}
key={`${transaction.user_id}-${transaction.transaction_time}`}
className="hover:bg-gray-50"
>
<TableCell className="font-medium">

View File

@@ -59,7 +59,7 @@ export function RateLimitModal({
}
fetchRateLimit();
}, [open, userId]);
}, [open, userId, toast]);
async function handleReset(resetWeekly: boolean) {
if (!rateLimitData) return;