Merge pull request #108 from machka-pasla/dev
fixed locales and traffic after adding days
This commit is contained in:
@@ -568,6 +568,11 @@ class SubscriptionService:
|
|||||||
bonus_days: int,
|
bonus_days: int,
|
||||||
reason: str = "bonus",
|
reason: str = "bonus",
|
||||||
) -> Optional[datetime]:
|
) -> Optional[datetime]:
|
||||||
|
reason_lower = (reason or "").lower()
|
||||||
|
apply_main_traffic_limit = any(
|
||||||
|
keyword in reason_lower for keyword in ("admin", "promo code", "referral", "bonus")
|
||||||
|
)
|
||||||
|
|
||||||
user = await user_dal.get_user_by_id(session, user_id)
|
user = await user_dal.get_user_by_id(session, user_id)
|
||||||
if not user:
|
if not user:
|
||||||
logging.warning(
|
logging.warning(
|
||||||
@@ -594,8 +599,12 @@ class SubscriptionService:
|
|||||||
start_date = datetime.now(timezone.utc)
|
start_date = datetime.now(timezone.utc)
|
||||||
new_end_date_obj = start_date + timedelta(days=bonus_days)
|
new_end_date_obj = start_date + timedelta(days=bonus_days)
|
||||||
|
|
||||||
# For promo code activations, use the configured user traffic limit
|
# Apply main traffic limit for admin/referral/promo bonuses, fallback to trial limit otherwise
|
||||||
traffic_limit = self.settings.user_traffic_limit_bytes if "promo code" in reason.lower() else self.settings.trial_traffic_limit_bytes
|
traffic_limit = (
|
||||||
|
self.settings.user_traffic_limit_bytes
|
||||||
|
if apply_main_traffic_limit
|
||||||
|
else self.settings.trial_traffic_limit_bytes
|
||||||
|
)
|
||||||
|
|
||||||
bonus_sub_payload = {
|
bonus_sub_payload = {
|
||||||
"user_id": user_id,
|
"user_id": user_id,
|
||||||
@@ -626,12 +635,23 @@ class SubscriptionService:
|
|||||||
session, active_sub.subscription_id, new_end_date_obj
|
session, active_sub.subscription_id, new_end_date_obj
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
apply_main_traffic_limit
|
||||||
|
and updated_sub_model
|
||||||
|
and updated_sub_model.traffic_limit_bytes != self.settings.user_traffic_limit_bytes
|
||||||
|
):
|
||||||
|
updated_sub_model = await subscription_dal.update_subscription(
|
||||||
|
session,
|
||||||
|
updated_sub_model.subscription_id,
|
||||||
|
{"traffic_limit_bytes": self.settings.user_traffic_limit_bytes},
|
||||||
|
)
|
||||||
|
|
||||||
if updated_sub_model:
|
if updated_sub_model:
|
||||||
# Prepare panel update payload
|
# Prepare panel update payload
|
||||||
panel_update_payload = self._build_panel_update_payload(
|
panel_update_payload = self._build_panel_update_payload(
|
||||||
expire_at=new_end_date_obj,
|
expire_at=new_end_date_obj,
|
||||||
traffic_limit_bytes=(
|
traffic_limit_bytes=(
|
||||||
self.settings.user_traffic_limit_bytes if "promo code" in reason.lower() else None
|
self.settings.user_traffic_limit_bytes if apply_main_traffic_limit else None
|
||||||
),
|
),
|
||||||
include_uuid=False,
|
include_uuid=False,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -257,6 +257,7 @@
|
|||||||
"admin_user_invalid_days": "❌ Invalid number of days. Enter number from 1 to 3650.",
|
"admin_user_invalid_days": "❌ Invalid number of days. Enter number from 1 to 3650.",
|
||||||
"admin_user_subscription_added_success": "✅ Successfully added {days} days to user {user_id}",
|
"admin_user_subscription_added_success": "✅ Successfully added {days} days to user {user_id}",
|
||||||
"admin_user_subscription_added_error": "❌ Error adding subscription days",
|
"admin_user_subscription_added_error": "❌ Error adding subscription days",
|
||||||
|
"admin_panel_user_creation_failed": "❌ Failed to create or link panel user for ID {user_id}. Manual intervention required.",
|
||||||
"admin_user_ban_toggle_success": "✅ User {status}",
|
"admin_user_ban_toggle_success": "✅ User {status}",
|
||||||
"admin_user_ban_toggle_error": "❌ Error changing ban status",
|
"admin_user_ban_toggle_error": "❌ Error changing ban status",
|
||||||
"admin_user_ban_success": "✅ User {input} has been banned",
|
"admin_user_ban_success": "✅ User {input} has been banned",
|
||||||
|
|||||||
@@ -257,6 +257,7 @@
|
|||||||
"admin_user_invalid_days": "❌ Неверное количество дней. Введите число от 1 до 3650.",
|
"admin_user_invalid_days": "❌ Неверное количество дней. Введите число от 1 до 3650.",
|
||||||
"admin_user_subscription_added_success": "✅ Успешно добавлено {days} дней подписки пользователю {user_id}",
|
"admin_user_subscription_added_success": "✅ Успешно добавлено {days} дней подписки пользователю {user_id}",
|
||||||
"admin_user_subscription_added_error": "❌ Ошибка добавления дней подписки",
|
"admin_user_subscription_added_error": "❌ Ошибка добавления дней подписки",
|
||||||
|
"admin_panel_user_creation_failed": "❌ Не удалось создать или привязать пользователя в панели для ID {user_id}. Требуется ручная проверка.",
|
||||||
"admin_user_ban_toggle_success": "✅ Пользователь {status}",
|
"admin_user_ban_toggle_success": "✅ Пользователь {status}",
|
||||||
"admin_user_ban_toggle_error": "❌ Ошибка изменения статуса блокировки",
|
"admin_user_ban_toggle_error": "❌ Ошибка изменения статуса блокировки",
|
||||||
"admin_user_ban_success": "✅ Пользователь {input} заблокирован",
|
"admin_user_ban_success": "✅ Пользователь {input} заблокирован",
|
||||||
|
|||||||
Reference in New Issue
Block a user