-
Notifications
You must be signed in to change notification settings - Fork 693
Expand file tree
/
Copy pathsystem_schema.py
More file actions
223 lines (166 loc) · 6.78 KB
/
system_schema.py
File metadata and controls
223 lines (166 loc) · 6.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import re
from typing import Optional,List
from pydantic import BaseModel, Field, field_validator
from apps.swagger.i18n import PLACEHOLDER_PREFIX
from common.core.schemas import BaseCreatorDTO
EMAIL_REGEX = re.compile(
r"^[a-zA-Z0-9]+([._-][a-zA-Z0-9]+)*@"
r"([a-zA-Z0-9]+(-[a-zA-Z0-9]+)*\.)+"
r"[a-zA-Z]{2,}$"
)
PWD_REGEX = re.compile(
r"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)"
r"(?=.*[~!@#$%^&*()_+\-={}|:\"<>?`\[\];',./])"
r"[A-Za-z\d~!@#$%^&*()_+\-={}|:\"<>?`\[\];',./]{8,20}$"
)
class UserStatus(BaseCreatorDTO):
status: int = Field(default=1, description=f"{PLACEHOLDER_PREFIX}status")
class UserLanguage(BaseModel):
language: str = Field(description=f"{PLACEHOLDER_PREFIX}language")
class BaseUser(BaseModel):
account: str = Field(min_length=1, max_length=100, description="用户账号")
oid: int
class BaseUserDTO(BaseUser, BaseCreatorDTO):
language: str = Field(pattern=r"^(zh-CN|en|ko-KR)$", default="zh-CN", description="用户语言")
password: str
status: int = 1
origin: int = 0
name: str
def to_dict(self):
return {
"id": self.id,
"account": self.account,
"oid": self.oid
}
@field_validator("language")
def validate_language(cls, lang: str) -> str:
if not re.fullmatch(r"^(zh-CN|en|ko-KR)$", lang):
raise ValueError("Language must be 'zh-CN', 'en', or 'ko-KR'")
return lang
class UserCreator(BaseUser):
name: str = Field(min_length=1, max_length=100, description=f"{PLACEHOLDER_PREFIX}user_name")
email: str = Field(min_length=1, max_length=100, description=f"{PLACEHOLDER_PREFIX}user_email")
status: int = Field(default=1, description=f"{PLACEHOLDER_PREFIX}status")
origin: Optional[int] = Field(default=0, description=f"{PLACEHOLDER_PREFIX}origin")
oid_list: Optional[list[int]] = Field(default=None, description=f"{PLACEHOLDER_PREFIX}oid")
system_variables: Optional[List] = Field(default=[])
""" @field_validator("email")
def validate_email(cls, lang: str) -> str:
if not re.fullmatch(EMAIL_REGEX, lang):
raise ValueError("Email format is invalid!")
return lang """
class UserEditor(UserCreator, BaseCreatorDTO):
pass
class UserGrid(UserEditor):
create_time: int = Field(description=f"{PLACEHOLDER_PREFIX}create_time")
language: str = Field(default="zh-CN" ,description=f"{PLACEHOLDER_PREFIX}language")
# space_name: Optional[str] = None
# origin: str = ''
class PwdEditor(BaseModel):
pwd: str = Field(description=f"{PLACEHOLDER_PREFIX}origin_pwd")
new_pwd: str = Field(description=f"{PLACEHOLDER_PREFIX}new_pwd")
class UserWsBase(BaseModel):
uid_list: list[int] = Field(description=f"{PLACEHOLDER_PREFIX}uid")
oid: Optional[int] = Field(default=None, description=f"{PLACEHOLDER_PREFIX}oid")
class UserWsDTO(UserWsBase):
weight: Optional[int] = Field(default=0, description=f"{PLACEHOLDER_PREFIX}weight")
class UserWsEditor(BaseModel):
uid: int = Field(description=f"{PLACEHOLDER_PREFIX}uid")
oid: int = Field(description=f"{PLACEHOLDER_PREFIX}oid")
weight: int = Field(default=0, description=f"{PLACEHOLDER_PREFIX}weight")
class UserInfoDTO(UserEditor):
language: str = "zh-CN"
weight: int = 0
isAdmin: bool = False
class AssistantBase(BaseModel):
name: str = Field(description=f"{PLACEHOLDER_PREFIX}model_name")
domain: str = Field(description=f"{PLACEHOLDER_PREFIX}assistant_domain")
type: int = Field(default=0, description=f"{PLACEHOLDER_PREFIX}assistant_type") # 0普通小助手 1高级 4页面嵌入
configuration: Optional[str] = Field(default=None, description=f"{PLACEHOLDER_PREFIX}assistant_configuration")
description: Optional[str] = Field(default=None, description=f"{PLACEHOLDER_PREFIX}assistant_description")
oid: Optional[int] = Field(default=1, description=f"{PLACEHOLDER_PREFIX}oid")
class AssistantDTO(AssistantBase, BaseCreatorDTO):
pass
class AssistantHeader(AssistantDTO):
unique: Optional[str] = None
certificate: Optional[str] = None
online: bool = False
request_origin: Optional[str] = None
class AssistantValidator(BaseModel):
valid: bool = False
id_match: bool = False
domain_match: bool = False
token: Optional[str] = None
def __init__(
self,
valid: bool = False,
id_match: bool = False,
domain_match: bool = False,
token: Optional[str] = None,
**kwargs
):
super().__init__(
valid=valid,
id_match=id_match,
domain_match=domain_match,
token=token,
**kwargs
)
class WorkspaceUser(UserEditor):
weight: int
create_time: int
class UserWs(BaseCreatorDTO):
name: str = Field(description="user_name")
class UserWsOption(UserWs):
account: str = Field(description="user_account")
class AssistantFieldSchema(BaseModel):
id: Optional[int] = None
name: Optional[str] = None
type: Optional[str] = None
comment: Optional[str] = None
class AssistantTableSchema(BaseModel):
id: Optional[int] = None
name: Optional[str] = None
comment: Optional[str] = None
rule: Optional[str] = None
sql: Optional[str] = None
fields: Optional[list[AssistantFieldSchema]] = None
class AssistantOutDsBase(BaseModel):
id: Optional[int] = None
name: str
type: Optional[str] = None
type_name: Optional[str] = None
comment: Optional[str] = None
description: Optional[str] = None
configuration: Optional[str] = None
class AssistantOutDsSchema(AssistantOutDsBase):
host: Optional[str] = None
port: Optional[int] = None
dataBase: Optional[str] = None
user: Optional[str] = None
password: Optional[str] = None
db_schema: Optional[str] = None
extraParams: Optional[str] = None
mode: Optional[str] = None
tables: Optional[list[AssistantTableSchema]] = None
class AssistantUiSchema(BaseCreatorDTO):
theme: Optional[str] = None
header_font_color: Optional[str] = None
logo: Optional[str] = None
float_icon: Optional[str] = None
float_icon_drag: Optional[bool] = False
x_type: Optional[str] = 'right'
x_val: Optional[int] = 0
y_type: Optional[str] = 'bottom'
y_val: Optional[int] = 33
name: Optional[str] = None
welcome: Optional[str] = None
welcome_desc: Optional[str] = None
class ApikeyStatus(BaseModel):
id: int = Field(description=f"{PLACEHOLDER_PREFIX}id")
status: bool = Field(description=f"{PLACEHOLDER_PREFIX}status")
class ApikeyGridItem(BaseCreatorDTO):
access_key: str = Field(description=f"Access Key")
secret_key: str = Field(description=f"Secret Key")
status: bool = Field(description=f"{PLACEHOLDER_PREFIX}status")
create_time: int = Field(description=f"{PLACEHOLDER_PREFIX}create_time")