feat(админка): выбор всех по фильтру
This commit is contained in:
@@ -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"):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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` отдельно, не в рамках выравнивания).
|
||||
|
||||
+17
-1
@@ -651,6 +651,7 @@ document.addEventListener('DOMContentLoaded',function(){applyThemeIcon();applyDe
|
||||
</div>
|
||||
<div class="toolbar note">
|
||||
Выбрать на странице:
|
||||
<button class="btn-sm" onclick="selectFiltered()">всех по фильтру</button>
|
||||
<button class="btn-sm" onclick="selectGroup('all')">всех живых на странице</button>
|
||||
<button class="btn-sm" onclick="selectGroup('admin')">всех admin</button>
|
||||
<button class="btn-sm" onclick="selectGroup('user')">всех user</button>
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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"]
|
||||
|
||||
Reference in New Issue
Block a user