Skip to content

Commit e588913

Browse files
authored
Fix current user info detail schema (#499)
1 parent 1c46e24 commit e588913

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

backend/app/admin/schema/user.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33
from datetime import datetime
4+
from typing import Any
45

56
from pydantic import ConfigDict, EmailStr, Field, HttpUrl, model_validator
67
from typing_extensions import Self
@@ -77,19 +78,20 @@ class GetUserInfoDetail(GetUserInfoNoRelationDetail):
7778
class GetCurrentUserInfoDetail(GetUserInfoDetail):
7879
model_config = ConfigDict(from_attributes=True)
7980

80-
dept: GetDeptDetail | str | None = None
81-
roles: list[GetRoleDetail] | list[str] | None = None
81+
dept: str | None = None
82+
roles: list[str]
8283

83-
@model_validator(mode='after')
84-
def handel(self) -> Self:
84+
@model_validator(mode='before')
85+
@classmethod
86+
def handel(cls, data: Any) -> Self:
8587
"""处理部门和角色"""
86-
dept = self.dept
88+
dept = data['dept']
8789
if dept:
88-
self.dept = dept.name # type: ignore
89-
roles = self.roles
90+
data['dept'] = dept['name']
91+
roles = data['roles']
9092
if roles:
91-
self.roles = [role.name for role in roles] # type: ignore
92-
return self
93+
data['roles'] = [role['name'] for role in roles]
94+
return data
9395

9496

9597
class CurrentUserIns(GetUserInfoDetail):

0 commit comments

Comments
 (0)