中文汉化
Deploy to Staging / deploy (push) Has been cancelled
Conflict detector / main (push) Has been cancelled
Lint Backend / lint-backend (push) Has been cancelled
Playwright Tests / changes (push) Has been cancelled
Test Backend / test-backend (push) Has been cancelled
Test Docker Compose / test-docker-compose (push) Has been cancelled
Playwright Tests / test-playwright (1, 4) (push) Has been cancelled
Playwright Tests / test-playwright (2, 4) (push) Has been cancelled
Playwright Tests / test-playwright (3, 4) (push) Has been cancelled
Playwright Tests / test-playwright (4, 4) (push) Has been cancelled
Playwright Tests / merge-playwright-reports (push) Has been cancelled
Playwright Tests / alls-green-playwright (push) Has been cancelled
Issue Manager / issue-manager (push) Has been cancelled

This commit is contained in:
z66
2025-12-18 09:40:41 +08:00
parent 6a91475bf6
commit db867dcbe5
41 changed files with 671 additions and 666 deletions
+12 -12
View File
@@ -15,7 +15,7 @@ def read_items(
session: SessionDep, current_user: CurrentUser, skip: int = 0, limit: int = 100
) -> Any:
"""
Retrieve items.
获取 Item 列表。
"""
if current_user.is_superuser:
@@ -44,13 +44,13 @@ def read_items(
@router.get("/{id}", response_model=ItemPublic)
def read_item(session: SessionDep, current_user: CurrentUser, id: uuid.UUID) -> Any:
"""
Get item by ID.
通过 ID 获取 Item。
"""
item = session.get(Item, id)
if not item:
raise HTTPException(status_code=404, detail="Item not found")
raise HTTPException(status_code=404, detail="项目未找到")
if not current_user.is_superuser and (item.owner_id != current_user.id):
raise HTTPException(status_code=400, detail="Not enough permissions")
raise HTTPException(status_code=400, detail="权限不足")
return item
@@ -59,7 +59,7 @@ def create_item(
*, session: SessionDep, current_user: CurrentUser, item_in: ItemCreate
) -> Any:
"""
Create new item.
创建新的 Item
"""
item = Item.model_validate(item_in, update={"owner_id": current_user.id})
session.add(item)
@@ -77,13 +77,13 @@ def update_item(
item_in: ItemUpdate,
) -> Any:
"""
Update an item.
更新 Item
"""
item = session.get(Item, id)
if not item:
raise HTTPException(status_code=404, detail="Item not found")
raise HTTPException(status_code=404, detail="项目未找到")
if not current_user.is_superuser and (item.owner_id != current_user.id):
raise HTTPException(status_code=400, detail="Not enough permissions")
raise HTTPException(status_code=400, detail="权限不足")
update_dict = item_in.model_dump(exclude_unset=True)
item.sqlmodel_update(update_dict)
session.add(item)
@@ -97,13 +97,13 @@ def delete_item(
session: SessionDep, current_user: CurrentUser, id: uuid.UUID
) -> Message:
"""
Delete an item.
删除 Item
"""
item = session.get(Item, id)
if not item:
raise HTTPException(status_code=404, detail="Item not found")
raise HTTPException(status_code=404, detail="项目未找到")
if not current_user.is_superuser and (item.owner_id != current_user.id):
raise HTTPException(status_code=400, detail="Not enough permissions")
raise HTTPException(status_code=400, detail="权限不足")
session.delete(item)
session.commit()
return Message(message="Item deleted successfully")
return Message(message="项目删除成功")
+14 -14
View File
@@ -26,15 +26,15 @@ def login_access_token(
session: SessionDep, form_data: Annotated[OAuth2PasswordRequestForm, Depends()]
) -> Token:
"""
OAuth2 compatible token login, get an access token for future requests
OAuth2 兼容的令牌登录,获取用于后续请求的访问令牌
"""
user = crud.authenticate(
session=session, email=form_data.username, password=form_data.password
)
if not user:
raise HTTPException(status_code=400, detail="Incorrect email or password")
raise HTTPException(status_code=400, detail="邮箱或密码错误")
elif not user.is_active:
raise HTTPException(status_code=400, detail="Inactive user")
raise HTTPException(status_code=400, detail="用户未激活")
access_token_expires = timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES)
return Token(
access_token=security.create_access_token(
@@ -46,7 +46,7 @@ def login_access_token(
@router.post("/login/test-token", response_model=UserPublic)
def test_token(current_user: CurrentUser) -> Any:
"""
Test access token
测试访问令牌
"""
return current_user
@@ -54,14 +54,14 @@ def test_token(current_user: CurrentUser) -> Any:
@router.post("/password-recovery/{email}")
def recover_password(email: str, session: SessionDep) -> Message:
"""
Password Recovery
密码找回
"""
user = crud.get_user_by_email(session=session, email=email)
if not user:
raise HTTPException(
status_code=404,
detail="The user with this email does not exist in the system.",
detail="系统中不存在该邮箱的用户。",
)
password_reset_token = generate_password_reset_token(email=email)
email_data = generate_reset_password_email(
@@ -72,30 +72,30 @@ def recover_password(email: str, session: SessionDep) -> Message:
subject=email_data.subject,
html_content=email_data.html_content,
)
return Message(message="Password recovery email sent")
return Message(message="密码找回邮件已发送")
@router.post("/reset-password/")
def reset_password(session: SessionDep, body: NewPassword) -> Message:
"""
Reset password
重置密码
"""
email = verify_password_reset_token(token=body.token)
if not email:
raise HTTPException(status_code=400, detail="Invalid token")
raise HTTPException(status_code=400, detail="无效的令牌")
user = crud.get_user_by_email(session=session, email=email)
if not user:
raise HTTPException(
status_code=404,
detail="The user with this email does not exist in the system.",
detail="系统中不存在该邮箱的用户。",
)
elif not user.is_active:
raise HTTPException(status_code=400, detail="Inactive user")
raise HTTPException(status_code=400, detail="用户未激活")
hashed_password = get_password_hash(password=body.new_password)
user.hashed_password = hashed_password
session.add(user)
session.commit()
return Message(message="Password updated successfully")
return Message(message="密码更新成功")
@router.post(
@@ -105,14 +105,14 @@ def reset_password(session: SessionDep, body: NewPassword) -> Message:
)
def recover_password_html_content(email: str, session: SessionDep) -> Any:
"""
HTML Content for Password Recovery
获取密码找回邮件的 HTML 内容
"""
user = crud.get_user_by_email(session=session, email=email)
if not user:
raise HTTPException(
status_code=404,
detail="The user with this username does not exist in the system.",
detail="系统中不存在该用户名的用户。",
)
password_reset_token = generate_password_reset_token(email=email)
email_data = generate_reset_password_email(
+1 -1
View File
@@ -23,7 +23,7 @@ class PrivateUserCreate(BaseModel):
@router.post("/users/", response_model=UserPublic)
def create_user(user_in: PrivateUserCreate, session: SessionDep) -> Any:
"""
Create a new user.
创建新用户。
"""
user = User(
+24 -24
View File
@@ -36,7 +36,7 @@ router = APIRouter(prefix="/users", tags=["users"])
)
def read_users(session: SessionDep, skip: int = 0, limit: int = 100) -> Any:
"""
Retrieve users.
获取用户列表。
"""
count_statement = select(func.count()).select_from(User)
@@ -53,13 +53,13 @@ def read_users(session: SessionDep, skip: int = 0, limit: int = 100) -> Any:
)
def create_user(*, session: SessionDep, user_in: UserCreate) -> Any:
"""
Create new user.
创建新用户。
"""
user = crud.get_user_by_email(session=session, email=user_in.email)
if user:
raise HTTPException(
status_code=400,
detail="The user with this email already exists in the system.",
detail="系统中已存在该邮箱的用户。",
)
user = crud.create_user(session=session, user_create=user_in)
@@ -80,14 +80,14 @@ def update_user_me(
*, session: SessionDep, user_in: UserUpdateMe, current_user: CurrentUser
) -> Any:
"""
Update own user.
更新当前用户信息。
"""
if user_in.email:
existing_user = crud.get_user_by_email(session=session, email=user_in.email)
if existing_user and existing_user.id != current_user.id:
raise HTTPException(
status_code=409, detail="User with this email already exists"
status_code=409, detail="该邮箱已被其他用户使用"
)
user_data = user_in.model_dump(exclude_unset=True)
current_user.sqlmodel_update(user_data)
@@ -102,25 +102,25 @@ def update_password_me(
*, session: SessionDep, body: UpdatePassword, current_user: CurrentUser
) -> Any:
"""
Update own password.
更新当前用户密码。
"""
if not verify_password(body.current_password, current_user.hashed_password):
raise HTTPException(status_code=400, detail="Incorrect password")
raise HTTPException(status_code=400, detail="密码错误")
if body.current_password == body.new_password:
raise HTTPException(
status_code=400, detail="New password cannot be the same as the current one"
status_code=400, detail="新密码不能与当前密码相同"
)
hashed_password = get_password_hash(body.new_password)
current_user.hashed_password = hashed_password
session.add(current_user)
session.commit()
return Message(message="Password updated successfully")
return Message(message="密码更新成功")
@router.get("/me", response_model=UserPublic)
def read_user_me(current_user: CurrentUser) -> Any:
"""
Get current user.
获取当前用户信息。
"""
return current_user
@@ -128,27 +128,27 @@ def read_user_me(current_user: CurrentUser) -> Any:
@router.delete("/me", response_model=Message)
def delete_user_me(session: SessionDep, current_user: CurrentUser) -> Any:
"""
Delete own user.
删除当前用户。
"""
if current_user.is_superuser:
raise HTTPException(
status_code=403, detail="Super users are not allowed to delete themselves"
status_code=403, detail="超级用户不允许删除自己"
)
session.delete(current_user)
session.commit()
return Message(message="User deleted successfully")
return Message(message="用户删除成功")
@router.post("/signup", response_model=UserPublic)
def register_user(session: SessionDep, user_in: UserRegister) -> Any:
"""
Create new user without the need to be logged in.
无需登录即可创建新用户(用户注册)。
"""
user = crud.get_user_by_email(session=session, email=user_in.email)
if user:
raise HTTPException(
status_code=400,
detail="The user with this email already exists in the system",
detail="系统中已存在该邮箱的用户",
)
user_create = UserCreate.model_validate(user_in)
user = crud.create_user(session=session, user_create=user_create)
@@ -160,7 +160,7 @@ def read_user_by_id(
user_id: uuid.UUID, session: SessionDep, current_user: CurrentUser
) -> Any:
"""
Get a specific user by id.
通过 ID 获取指定用户。
"""
user = session.get(User, user_id)
if user == current_user:
@@ -168,7 +168,7 @@ def read_user_by_id(
if not current_user.is_superuser:
raise HTTPException(
status_code=403,
detail="The user doesn't have enough privileges",
detail="用户权限不足",
)
return user
@@ -185,20 +185,20 @@ def update_user(
user_in: UserUpdate,
) -> Any:
"""
Update a user.
更新用户信息。
"""
db_user = session.get(User, user_id)
if not db_user:
raise HTTPException(
status_code=404,
detail="The user with this id does not exist in the system",
detail="系统中不存在该ID的用户",
)
if user_in.email:
existing_user = crud.get_user_by_email(session=session, email=user_in.email)
if existing_user and existing_user.id != user_id:
raise HTTPException(
status_code=409, detail="User with this email already exists"
status_code=409, detail="该邮箱已被其他用户使用"
)
db_user = crud.update_user(session=session, db_user=db_user, user_in=user_in)
@@ -210,17 +210,17 @@ def delete_user(
session: SessionDep, current_user: CurrentUser, user_id: uuid.UUID
) -> Message:
"""
Delete a user.
删除用户。
"""
user = session.get(User, user_id)
if not user:
raise HTTPException(status_code=404, detail="User not found")
raise HTTPException(status_code=404, detail="用户未找到")
if user == current_user:
raise HTTPException(
status_code=403, detail="Super users are not allowed to delete themselves"
status_code=403, detail="超级用户不允许删除自己"
)
statement = delete(Item).where(col(Item.owner_id) == user_id)
session.exec(statement) # type: ignore
session.delete(user)
session.commit()
return Message(message="User deleted successfully")
return Message(message="用户删除成功")
+2 -2
View File
@@ -15,7 +15,7 @@ router = APIRouter(prefix="/utils", tags=["utils"])
)
def test_email(email_to: EmailStr) -> Message:
"""
Test emails.
测试邮件发送。
"""
email_data = generate_test_email(email_to=email_to)
send_email(
@@ -23,7 +23,7 @@ def test_email(email_to: EmailStr) -> Message:
subject=email_data.subject,
html_content=email_data.html_content,
)
return Message(message="Test email sent")
return Message(message="测试邮件已发送")
@router.get("/health-check/")