335be66980
- Add MULTI_TARIFF_ENABLED feature flag for gradual rollout
- Migration 0041: remove unique constraint on subscriptions.user_id
- Migration 0042: add remnawave_short_id (NOT NULL, UNIQUE) to subscriptions
- Each subscription gets its own Remnawave user (user_{tg_id}_{short_id})
- Add _resolve_subscription() to all 30+ bot handlers for per-subscription routing
- Add my_subscriptions.py with list/detail views and delegation handlers
- Refactor cabinet subscription.py (4687 lines -> 10 focused modules)
- Add subscription_id parameter to all cabinet API endpoints
- Adapt all services: autopay, wheel, contests, campaign, guest purchase,
monitoring, blocked users, account merge, promo codes, payments
- Replace all user.subscription (singular) with user.subscriptions iteration
- IDOR protection via get_subscription_by_id_for_user on all endpoints
- Full backward compatibility: MULTI_TARIFF_ENABLED=False = legacy behavior
104 lines
2.9 KiB
Python
104 lines
2.9 KiB
Python
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class PromoGroupSummary(BaseModel):
|
|
id: int
|
|
name: str
|
|
server_discount_percent: int
|
|
traffic_discount_percent: int
|
|
device_discount_percent: int
|
|
apply_discounts_to_addons: bool = True
|
|
|
|
|
|
class SubscriptionSummary(BaseModel):
|
|
id: int
|
|
status: str
|
|
actual_status: str
|
|
is_trial: bool
|
|
start_date: datetime
|
|
end_date: datetime
|
|
traffic_limit_gb: int
|
|
traffic_used_gb: float
|
|
device_limit: int
|
|
autopay_enabled: bool
|
|
autopay_days_before: int | None = None
|
|
subscription_url: str | None = None
|
|
subscription_crypto_link: str | None = None
|
|
connected_squads: list[str] = Field(default_factory=list)
|
|
|
|
|
|
class UserResponse(BaseModel):
|
|
id: int
|
|
telegram_id: int | None = None
|
|
username: str | None = None
|
|
first_name: str | None = None
|
|
last_name: str | None = None
|
|
status: str
|
|
language: str
|
|
balance_kopeks: int
|
|
balance_rubles: float
|
|
referral_code: str | None = None
|
|
referred_by_id: int | None = None
|
|
has_had_paid_subscription: bool
|
|
has_made_first_topup: bool
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
last_activity: datetime | None = None
|
|
promo_group: PromoGroupSummary | None = None
|
|
subscription: SubscriptionSummary | None = None
|
|
|
|
|
|
class UserListResponse(BaseModel):
|
|
items: list[UserResponse]
|
|
total: int
|
|
limit: int
|
|
offset: int
|
|
|
|
|
|
class UserCreateRequest(BaseModel):
|
|
telegram_id: int | None = None
|
|
username: str | None = None
|
|
first_name: str | None = None
|
|
last_name: str | None = None
|
|
language: str = 'ru'
|
|
referred_by_id: int | None = None
|
|
promo_group_id: int | None = None
|
|
|
|
|
|
class UserUpdateRequest(BaseModel):
|
|
username: str | None = None
|
|
first_name: str | None = None
|
|
last_name: str | None = None
|
|
language: str | None = None
|
|
status: str | None = None
|
|
promo_group_id: int | None = None
|
|
referral_code: str | None = None
|
|
has_had_paid_subscription: bool | None = None
|
|
has_made_first_topup: bool | None = None
|
|
|
|
|
|
class BalanceUpdateRequest(BaseModel):
|
|
amount_kopeks: int = Field(..., ge=-100_000_000, le=100_000_000)
|
|
description: str | None = Field(default='Корректировка через веб-API')
|
|
create_transaction: bool = True
|
|
|
|
|
|
class UserSubscriptionCreateRequest(BaseModel):
|
|
"""Схема для создания подписки через users API (user_id берется из URL)"""
|
|
|
|
is_trial: bool = False
|
|
duration_days: int | None = None
|
|
traffic_limit_gb: int | None = None
|
|
device_limit: int | None = None
|
|
squad_uuid: str | None = None
|
|
connected_squads: list[str] | None = None
|
|
replace_existing: bool = False
|
|
subscription_id: int | None = Field(
|
|
default=None,
|
|
description='ID of existing subscription to replace (required in multi-tariff mode when replace_existing=true)',
|
|
)
|