fix: user card open in payments list for email only users
This commit is contained in:
@@ -262,14 +262,34 @@ def _payment_traffic_gb_split(payment: Payment) -> Tuple[Optional[float], Option
|
|||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
|
|
||||||
|
def _payment_user_display_label(loaded_user: Any, payment_user_id: int) -> str:
|
||||||
|
"""Human-facing name for payments tables: TG profile name, else email, else user id."""
|
||||||
|
if loaded_user is None:
|
||||||
|
return str(payment_user_id)
|
||||||
|
tid = getattr(loaded_user, "telegram_id", None)
|
||||||
|
if tid is not None:
|
||||||
|
fn = (getattr(loaded_user, "first_name", None) or "").strip()
|
||||||
|
ln = (getattr(loaded_user, "last_name", None) or "").strip()
|
||||||
|
full = f"{fn} {ln}".strip()
|
||||||
|
if full:
|
||||||
|
return full
|
||||||
|
un = (getattr(loaded_user, "username", None) or "").strip()
|
||||||
|
if un:
|
||||||
|
return un if un.startswith("@") else f"@{un}"
|
||||||
|
return str(payment_user_id)
|
||||||
|
email = (getattr(loaded_user, "email", None) or "").strip()
|
||||||
|
if email:
|
||||||
|
return email
|
||||||
|
return str(payment_user_id)
|
||||||
|
|
||||||
|
|
||||||
def _serialize_payment(payment: Payment) -> Dict[str, Any]:
|
def _serialize_payment(payment: Payment) -> Dict[str, Any]:
|
||||||
# Avoid lazy-loading `payment.user` outside an active SQLAlchemy session.
|
# Avoid lazy-loading `payment.user` outside an active SQLAlchemy session.
|
||||||
# Some admin routes serialize payments after the session scope is closed.
|
# Some admin routes serialize payments after the session scope is closed.
|
||||||
user_label = str(payment.user_id)
|
|
||||||
telegram_id = None
|
telegram_id = None
|
||||||
loaded_user = payment.__dict__.get("user")
|
loaded_user = payment.__dict__.get("user")
|
||||||
|
user_label = _payment_user_display_label(loaded_user, int(payment.user_id))
|
||||||
if loaded_user is not None:
|
if loaded_user is not None:
|
||||||
user_label = loaded_user.username or loaded_user.first_name or str(payment.user_id)
|
|
||||||
tid = getattr(loaded_user, "telegram_id", None)
|
tid = getattr(loaded_user, "telegram_id", None)
|
||||||
if tid is not None:
|
if tid is not None:
|
||||||
try:
|
try:
|
||||||
@@ -1550,9 +1570,7 @@ async def admin_payments_export_route(request: web.Request) -> web.Response:
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
for p in rows:
|
for p in rows:
|
||||||
label = ""
|
label = _payment_user_display_label(p.user, int(p.user_id)) if p.user else str(p.user_id)
|
||||||
if p.user:
|
|
||||||
label = p.user.username or p.user.first_name or ""
|
|
||||||
writer.writerow(
|
writer.writerow(
|
||||||
[
|
[
|
||||||
p.payment_id,
|
p.payment_id,
|
||||||
|
|||||||
@@ -262,7 +262,8 @@
|
|||||||
|
|
||||||
function openPaymentUserCard(userId) {
|
function openPaymentUserCard(userId) {
|
||||||
const uid = Number(userId);
|
const uid = Number(userId);
|
||||||
if (!Number.isFinite(uid) || uid <= 0) return;
|
// Synthetic email-only users use negative user_id; still a valid admin target.
|
||||||
|
if (!Number.isFinite(uid) || uid === 0) return;
|
||||||
const next = normalizeSection("users");
|
const next = normalizeSection("users");
|
||||||
sidebarOpen = false;
|
sidebarOpen = false;
|
||||||
if (active !== next) {
|
if (active !== next) {
|
||||||
|
|||||||
@@ -72,7 +72,7 @@
|
|||||||
$: paymentHeaders = [
|
$: paymentHeaders = [
|
||||||
at("id", {}, "ID"),
|
at("id", {}, "ID"),
|
||||||
at("user", {}, "Пользователь"),
|
at("user", {}, "Пользователь"),
|
||||||
at("payments_col_telegram_id", {}, "Telegram ID"),
|
at("payments_col_user_id", {}, "ID"),
|
||||||
at("payments_col_traffic_regular", {}, "Основной трафик"),
|
at("payments_col_traffic_regular", {}, "Основной трафик"),
|
||||||
at("payments_col_traffic_premium", {}, "Премиум"),
|
at("payments_col_traffic_premium", {}, "Премиум"),
|
||||||
at("amount", {}, "Сумма"),
|
at("amount", {}, "Сумма"),
|
||||||
@@ -104,7 +104,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>{at("id", {}, "ID")}</th>
|
<th>{at("id", {}, "ID")}</th>
|
||||||
<th>{at("user", {}, "Пользователь")}</th>
|
<th>{at("user", {}, "Пользователь")}</th>
|
||||||
<th>{at("payments_col_telegram_id", {}, "Telegram ID")}</th>
|
<th>{at("payments_col_user_id", {}, "ID")}</th>
|
||||||
<th>{at("payments_col_traffic_regular", {}, "Основной трафик")}</th>
|
<th>{at("payments_col_traffic_regular", {}, "Основной трафик")}</th>
|
||||||
<th>{at("payments_col_traffic_premium", {}, "Премиум")}</th>
|
<th>{at("payments_col_traffic_premium", {}, "Премиум")}</th>
|
||||||
<th>{at("amount", {}, "Сумма")}</th>
|
<th>{at("amount", {}, "Сумма")}</th>
|
||||||
@@ -133,11 +133,8 @@
|
|||||||
<span class="admin-payments-user-name">{p.user_label || p.user_id}</span>
|
<span class="admin-payments-user-name">{p.user_label || p.user_id}</span>
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td
|
<td class="admin-cell-mono" data-label={at("payments_col_user_id", {}, "ID")}>
|
||||||
class="admin-cell-mono"
|
{p.user_id != null && p.user_id !== "" ? p.user_id : "—"}
|
||||||
data-label={at("payments_col_telegram_id", {}, "Telegram ID")}
|
|
||||||
>
|
|
||||||
{p.telegram_id != null ? p.telegram_id : "—"}
|
|
||||||
</td>
|
</td>
|
||||||
<td
|
<td
|
||||||
class="admin-cell-traffic-gb"
|
class="admin-cell-traffic-gb"
|
||||||
|
|||||||
+1
-1
@@ -920,7 +920,7 @@
|
|||||||
"admin_status": "Status",
|
"admin_status": "Status",
|
||||||
"admin_date": "Date",
|
"admin_date": "Date",
|
||||||
"admin_payments_empty": "No payments",
|
"admin_payments_empty": "No payments",
|
||||||
"admin_payments_col_telegram_id": "Telegram ID",
|
"admin_payments_col_user_id": "ID",
|
||||||
"admin_payments_col_traffic_regular": "Main traffic",
|
"admin_payments_col_traffic_regular": "Main traffic",
|
||||||
"admin_payments_col_traffic_premium": "Premium traffic",
|
"admin_payments_col_traffic_premium": "Premium traffic",
|
||||||
"admin_payments_col_actions": "",
|
"admin_payments_col_actions": "",
|
||||||
|
|||||||
+1
-1
@@ -920,7 +920,7 @@
|
|||||||
"admin_status": "Статус",
|
"admin_status": "Статус",
|
||||||
"admin_date": "Дата",
|
"admin_date": "Дата",
|
||||||
"admin_payments_empty": "Нет платежей",
|
"admin_payments_empty": "Нет платежей",
|
||||||
"admin_payments_col_telegram_id": "Telegram ID",
|
"admin_payments_col_user_id": "ID",
|
||||||
"admin_payments_col_traffic_regular": "Основной трафик",
|
"admin_payments_col_traffic_regular": "Основной трафик",
|
||||||
"admin_payments_col_traffic_premium": "Премиум трафик",
|
"admin_payments_col_traffic_premium": "Премиум трафик",
|
||||||
"admin_payments_col_actions": "",
|
"admin_payments_col_actions": "",
|
||||||
|
|||||||
Reference in New Issue
Block a user