From 216e81ca3c019638ab778055c9dac611faba073f Mon Sep 17 00:00:00 2001 From: Mohammad Date: Thu, 9 Jan 2025 19:08:13 +0330 Subject: [PATCH] Revert "fix: circular import in models" This reverts commit 9e24dfbb4c9547a37a4f0866343369a0eb15ab15. --- app/models/user.py | 25 +++++++++++-------------- app/models/user_template.py | 8 +++----- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/app/models/user.py b/app/models/user.py index 1af723584..fa590036c 100644 --- a/app/models/user.py +++ b/app/models/user.py @@ -2,12 +2,13 @@ import secrets from datetime import datetime from enum import Enum -from typing import Dict, List, Literal, Optional, Union +from typing import Dict, List, Optional, Union -from pydantic import (BaseModel, ConfigDict, Field, field_validator, - model_validator) +from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator from app import xray +from app.models.admin import Admin +from app.models.proxy import ProxySettings, ProxyTypes from app.subscription.share import generate_v2ray_links from app.utils.jwt import create_subscription_token from config import XRAY_SUBSCRIPTION_PATH, XRAY_SUBSCRIPTION_URL_PREFIX @@ -56,7 +57,7 @@ class NextPlanModel(BaseModel): class User(BaseModel): - proxies: Dict["ProxyTypes", "ProxySettings"] = {} + proxies: Dict[ProxyTypes, ProxySettings] = {} expire: Optional[int] = Field(None, nullable=True) data_limit: Optional[int] = Field( ge=0, default=None, description="data_limit can be 0 or greater" @@ -64,7 +65,7 @@ class User(BaseModel): data_limit_reset_strategy: UserDataLimitResetStrategy = ( UserDataLimitResetStrategy.no_reset ) - inbounds: Dict["ProxyTypes", List[str]] = {} + inbounds: Dict[ProxyTypes, List[str]] = {} note: Optional[str] = Field(None, nullable=True) sub_updated_at: Optional[datetime] = Field(None, nullable=True) sub_last_user_agent: Optional[str] = Field(None, nullable=True) @@ -287,9 +288,9 @@ class UserResponse(User): links: List[str] = [] subscription_url: str = "" proxies: dict - excluded_inbounds: Dict["ProxyTypes", List[str]] = {} + excluded_inbounds: Dict[ProxyTypes, List[str]] = {} - admin: Optional["Admin"] = None + admin: Optional[Admin] = None model_config = ConfigDict(from_attributes=True) @model_validator(mode="after") @@ -327,10 +328,10 @@ def cast_to_int(cls, v): class SubscriptionUserResponse(UserResponse): - admin: Literal["Admin"] | None = Field(default=None, exclude=True) - excluded_inbounds: Dict["ProxyTypes", List[str]] | None = Field(None, exclude=True) + admin: Admin | None = Field(default=None, exclude=True) + excluded_inbounds: Dict[ProxyTypes, List[str]] | None = Field(None, exclude=True) note: str | None = Field(None, exclude=True) - inbounds: Dict["ProxyTypes", List[str]] | None = Field(None, exclude=True) + inbounds: Dict[ProxyTypes, List[str]] | None = Field(None, exclude=True) auto_delete_in_days: int | None = Field(None, exclude=True) model_config = ConfigDict(from_attributes=True) @@ -363,7 +364,3 @@ class UserUsagesResponse(BaseModel): class UsersUsagesResponse(BaseModel): usages: List[UserUsageResponse] - - -from app.models.admin import Admin # noqa -from app.models.proxy import ProxySettings, ProxyTypes # noqa diff --git a/app/models/user_template.py b/app/models/user_template.py index d989f7e88..12d91b451 100644 --- a/app/models/user_template.py +++ b/app/models/user_template.py @@ -1,8 +1,9 @@ from typing import Dict, List, Optional -from pydantic import BaseModel, ConfigDict, Field, field_validator +from pydantic import field_validator, ConfigDict, BaseModel, Field from app import xray +from app.models.proxy import ProxyTypes class UserTemplate(BaseModel): @@ -16,7 +17,7 @@ class UserTemplate(BaseModel): username_prefix: Optional[str] = Field(max_length=20, min_length=1, default=None) username_suffix: Optional[str] = Field(max_length=20, min_length=1, default=None) - inbounds: Dict["ProxyTypes", List[str]] = {} + inbounds: Dict[ProxyTypes, List[str]] = {} class UserTemplateCreate(UserTemplate): @@ -62,6 +63,3 @@ def validate_inbounds(cls, v): final[protocol] = [inbound["tag"]] return final model_config = ConfigDict(from_attributes=True) - - -from app.models.proxy import ProxyTypes # noqa