mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 01:10:23 +08:00
refactor: 简化优先级拖拽交换逻辑并优化用户配额处理
- 优先级拖拽改为直接交换优先级值,而非重新编号 - 添加 Provider 优先级的点击编辑功能 - 创建用户时由后端统一处理默认配额逻辑 - 移除前端 getDefaultQuota API 调用和后端对应端点 Close #97
This commit is contained in:
@@ -198,20 +198,6 @@ async def delete_user_api_key(
|
||||
return await pipeline.run(adapter=adapter, http_request=request, db=db, mode=adapter.mode)
|
||||
|
||||
|
||||
@router.get("/defaults/quota")
|
||||
async def get_default_quota(request: Request, db: Session = Depends(get_db)):
|
||||
"""
|
||||
获取默认用户配额
|
||||
|
||||
获取系统配置的默认用户配额值,用于创建用户时的默认值。
|
||||
|
||||
**返回字段**:
|
||||
- `default_quota_usd`: 默认配额(USD)
|
||||
"""
|
||||
adapter = AdminGetDefaultQuotaAdapter()
|
||||
return await pipeline.run(adapter=adapter, http_request=request, db=db, mode=adapter.mode)
|
||||
|
||||
|
||||
# ============== 管理员适配器实现 ==============
|
||||
|
||||
|
||||
@@ -233,6 +219,14 @@ class AdminCreateUserAdapter(AdminApiAdapter):
|
||||
except (KeyError, AttributeError):
|
||||
raise InvalidRequestException("角色参数不合法")
|
||||
|
||||
# 确定配额:unlimited 优先,其次是指定值,最后是系统默认
|
||||
if request.unlimited:
|
||||
quota_usd = None # None 表示无限制
|
||||
elif request.quota_usd is not None:
|
||||
quota_usd = request.quota_usd
|
||||
else:
|
||||
quota_usd = SystemConfigService.get_config(db, "default_user_quota_usd", default=10.0)
|
||||
|
||||
try:
|
||||
user = UserService.create_user(
|
||||
db=db,
|
||||
@@ -240,7 +234,7 @@ class AdminCreateUserAdapter(AdminApiAdapter):
|
||||
username=request.username,
|
||||
password=request.password,
|
||||
role=role,
|
||||
quota_usd=request.quota_usd,
|
||||
quota_usd=quota_usd,
|
||||
)
|
||||
except ValueError as exc:
|
||||
raise InvalidRequestException(str(exc))
|
||||
@@ -601,15 +595,3 @@ class AdminDeleteUserKeyAdapter(AdminApiAdapter):
|
||||
)
|
||||
|
||||
return {"message": "API Key已删除"}
|
||||
|
||||
|
||||
class AdminGetDefaultQuotaAdapter(AdminApiAdapter):
|
||||
"""获取系统默认用户配额"""
|
||||
|
||||
async def handle(self, context): # type: ignore[override]
|
||||
db = context.db
|
||||
default_quota = SystemConfigService.get_config(db, "default_user_quota_usd", default=10.0)
|
||||
|
||||
return {
|
||||
"default_quota_usd": float(default_quota),
|
||||
}
|
||||
|
||||
@@ -233,12 +233,13 @@ class CreateUserRequest(BaseModel):
|
||||
password: str = Field(..., min_length=6, max_length=128, description="密码")
|
||||
email: str = Field(..., min_length=3, max_length=255, description="邮箱地址")
|
||||
role: Optional[UserRole] = Field(UserRole.USER, description="用户角色")
|
||||
quota_usd: Optional[float] = Field(default=10.0, description="USD配额,null表示无限制")
|
||||
quota_usd: Optional[float] = Field(default=None, description="USD配额,null表示使用系统默认配额")
|
||||
unlimited: bool = Field(default=False, description="是否无限配额")
|
||||
|
||||
@field_validator("quota_usd", mode="before")
|
||||
@classmethod
|
||||
def validate_quota_usd(cls, v):
|
||||
"""验证配额值,允许null表示无限制"""
|
||||
"""验证配额值,null表示使用系统默认配额"""
|
||||
if v is None:
|
||||
return None
|
||||
if isinstance(v, (int, float)) and v >= 0 and v <= 10000:
|
||||
|
||||
Reference in New Issue
Block a user