From 70a710d135273445c082729cfd2964857a3471f9 Mon Sep 17 00:00:00 2001 From: anor Date: Fri, 6 Nov 2026 23:20:42 +1000 Subject: [PATCH] =?UTF-8?q?feat(=D0=B0=D0=B4=D0=BC=D0=B8=D0=BD=D0=BA=D0=B0?= =?UTF-8?q?):=20=D0=B2=D1=8B=D0=B1=D0=BE=D1=80=20=D0=B2=D1=81=D0=B5=D1=85?= =?UTF-8?q?=20=D0=BF=D0=BE=20=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin_api.py | 6 ++++++ customers.py | 11 +++++++++++ docs/ADMIN_V2_BASELINE.md | 6 ++++++ static/admin.html | 18 +++++++++++++++++- tests/test_customers_api.py | 7 +++++++ 5 files changed, 47 insertions(+), 1 deletion(-) diff --git a/admin_api.py b/admin_api.py index 0867e4c..b4e66fb 100644 --- a/admin_api.py +++ b/admin_api.py @@ -102,6 +102,12 @@ async def attention_snooze(key: str, request: Request): return {"ok": True, "key": key, "minutes": minutes} +@router.get("/customer-emails") +async def customer_emails(request: Request, q: str = "", status: str = ""): + require_admin(request) + return {"emails": await asyncio.to_thread(customers.emails, q, status)} + + @router.get("/customers") async def customers_list(request: Request, query: str = "", q: str = "", status: str = "", page: int = 1, per_page: int = 50, sort: str = "last_seen"): diff --git a/customers.py b/customers.py index 6043f85..60c1847 100644 --- a/customers.py +++ b/customers.py @@ -208,3 +208,14 @@ def export_zip(email: str) -> bytes | None: if f.is_file() and f.stat().st_size <= 20 * 1024 * 1024: z.write(f, "files/" + str(f.relative_to(root))) return buf.getvalue() + + +def emails(query: str = "", status: str = "") -> list[str]: + out, page = [], 1 + while True: + d = list_customers(query, status, page, 200, "last_seen") + out.extend(r["raw_email"] or r["email"] for r in d["items"]) + if len(d["items"]) < 200: + break + page += 1 + return out diff --git a/docs/ADMIN_V2_BASELINE.md b/docs/ADMIN_V2_BASELINE.md index a662c37..c858350 100644 --- a/docs/ADMIN_V2_BASELINE.md +++ b/docs/ADMIN_V2_BASELINE.md @@ -345,6 +345,12 @@ - Тесты: `tests/test_admin_v2_flag.py` — 2. - Включение флага не выполнялось: нет подписанной сверки. +## 4.46. P1.1c — выбор всех по фильтру + +- `/api/admin/v2/customer-emails?q=&status=`: все email фильтра, страницы по 200. +- Старый экран: «всех по фильтру»; счётчик «Выбрано N». +- Тест: `tests/test_customers_api.py` — 5. + ## 5. Следующий шаг P0.0 design-gate → P0.1 backup/restore → P0.2 (release `feat/topup` отдельно, не в рамках выравнивания). diff --git a/static/admin.html b/static/admin.html index 6bcaa6e..92dacba 100644 --- a/static/admin.html +++ b/static/admin.html @@ -651,6 +651,7 @@ document.addEventListener('DOMContentLoaded',function(){applyThemeIcon();applyDe
Выбрать на странице: + @@ -1268,6 +1269,21 @@ function clearSelection() { refreshSelection(); } +async function selectFiltered() { + const q = (document.getElementById('users-q') || {}).value || ''; + const status = (document.getElementById('users-status') || {}).value || ''; + const p = new URLSearchParams(); + if (q.trim()) p.set('q', q.trim()); + if (status) p.set('status', status); + const r = await запрос('/api/admin/v2/customer-emails?' + p.toString()); + if (!r.ok) return; + const d = await r.json(); + selected.clear(); + for (const email of d.emails) selected.add(email); + document.querySelectorAll('#users .rowsel').forEach(cb => cb.checked = selected.has(cb.dataset.email)); + refreshSelection(); +} + function selectGroup(kind) { selected.clear(); for (const u of LIVE) { @@ -1292,7 +1308,7 @@ function refreshSelection() { } const bar = document.getElementById('selbar'); bar.style.display = selected.size ? 'flex' : 'none'; - const text = selected.size ? 'Выбрано ' + selected.size + ' из ' + LIVE.length : ''; + const text = selected.size ? 'Выбрано ' + selected.size : ''; document.getElementById('sel-count').textContent = text; document.getElementById('users-sr').textContent = text; } diff --git a/tests/test_customers_api.py b/tests/test_customers_api.py index 1d0a983..11b807d 100644 --- a/tests/test_customers_api.py +++ b/tests/test_customers_api.py @@ -86,3 +86,10 @@ def test_exhausted_filter_and_accounts_failure(env, monkeypatch): assert client.get("/api/admin/v2/customers?status=exhausted", headers=h).status_code == 503 assert client.get("/api/admin/v2/customers", headers=h).status_code == 200 + + +def test_emails_by_filter(env): + db, client, h, auth = env + d = client.get("/api/admin/v2/customer-emails?q=joe", headers=h).json() + assert d["emails"] == ["joe@x"] + assert "ex@x" in client.get("/api/admin/v2/customer-emails", headers=h).json()["emails"]