Files
romm/backend/endpoints/forms/identity.py
Zach Clendenen 438347615a fix(api): return 4xx for duplicate collections and overlong names
A duplicate collection name raised a 500. Names compare
case-insensitively in the database, so "TRUE" collides with "True".
Return 409 instead, as the existing test's name already said.

Memory card name and emulator, and the RetroAchievements username,
had no length check before the insert, so an overlong value failed in
the database with a 500. Validate them against their column lengths,
which returns 422.
2026-09-30 22:30:43 -05:00

37 lines
1.1 KiB
Python

from fastapi import UploadFile
from fastapi.param_functions import Form
from pydantic import BaseModel, Field
from models.user import TEXT_FIELD_LENGTH
class UserForm(BaseModel):
username: str | None = None
password: str | None = None
email: str | None = None
role: str | None = None
enabled: bool | None = None
ra_username: str | None = Field(default=None, max_length=TEXT_FIELD_LENGTH)
avatar: UploadFile | None = None
ui_settings: str | None = None
class OAuth2RequestForm:
def __init__(
self,
grant_type: str = Form(default="password"),
scope: str = Form(default=""),
username: str | None = Form(default=None),
password: str | None = Form(default=None),
client_id: str | None = Form(default=None),
client_secret: str | None = Form(default=None),
refresh_token: str | None = Form(default=None),
):
self.grant_type = grant_type
self.scopes = scope.split()
self.username = username
self.password = password
self.client_id = client_id
self.client_secret = client_secret
self.refresh_token = refresh_token