Aduce toate suprafetele dashboard-ului la grila tabelului Trimiteri, muta
navigarea intr-un meniu de cont (hamburger) si da panoului admin actiuni
reale de ciclu de viata. 9 stories, 3 valuri. UI pur (reskin + reasezare)
cu O SINGURA exceptie backend: modelul de stare a contului.
- US-001 sectiunea "Ajutor" eliminata din Acasa (wayfinding redundant).
- US-002 Nomenclator la grila standard (_submissions.html ca referinta).
- US-003 macro autosend compact (Manual<->Auto). Semantica de PREZENTA
`auto_send` (bifat->true, absent->false) NEALTERATA — compatibil cu ambele
parsere (Form(bool) la /mapari, bool(form.get()) la import). Zero backend.
- US-004 accounts.status (pending/active/blocked/archived/deleted), migrare
defensiva idempotenta derivata din `active`, gate worker claim_one pe
status='active' (echivalenta active=1 <=> status='active' pastrata).
- US-005 tabel Mapari compact + panou Ajutor (<details>, proza o singura data),
coloana "In coada".
- US-006 meniu hamburger dropdown (Cont/Integrare/Nomenclator/Admin/logout) +
context is_authenticated/is_admin/csrf_token defensiv in base.html.
- US-007 tab-bar redus la Acasa+Mapari; rutele /_fragments/{cont,integrare,
nomenclator} + deep-link ?tab= raman valide.
- US-008 rute admin block/archive/delete + bulk pe lista account_id,
require_admin + CSRF + PRG, dev id=1 sarit in bulk.
- US-009 admin UI: selectie bife + master + bara bulk + kebab per-rand,
grupare pe stare (bloc nou blocate/arhivate), nota "cont dev implicit" scoasa.
Stergere = SOFT: tombstone (status='deleted'), dar PII purjata IMEDIAT
(rar_creds_enc + chei API revocate + CUI eliberat pentru re-inregistrare),
GDPR/L.142.
VERIFY: 671 teste pass (+40). E2E browser (Playwright) a prins 2 bug-uri
invizibile la TestClient: bara bulk cu display:flex inline invingea [hidden]
(mutat in CSS .bulk-bar[hidden]); conturi arhivate cadeau sub "in asteptare"
(grupare pe status). /code-review high a prins 2 bug-uri reale: soft delete
pastra creds RAR + CUI la nesfarsit fara purjare accounts (GDPR neonorat);
apostrof in numele firmei rupea confirm() inline din kebab — ambele reparate,
plus cleanup boilerplate rute (_lifecycle_route).
Backend trimitere (worker masina stari/idempotenta/mapping) neatins, cu
exceptia gate-ului de cont. Design: docs/design/5.5-uniformizare-ui.md.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
138 lines
4.4 KiB
Python
138 lines
4.4 KiB
Python
"""Teste US-008 (PRD 5.5): rute admin pentru ciclul de viata al conturilor —
|
|
block/archive/delete + bulk pe lista account_id, require_admin + CSRF + PRG, dev id=1 protejat.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import re
|
|
import tempfile
|
|
|
|
import pytest
|
|
from starlette.testclient import TestClient
|
|
|
|
|
|
@pytest.fixture()
|
|
def client(monkeypatch):
|
|
tmp = tempfile.mkdtemp()
|
|
monkeypatch.setenv("AUTOPASS_DB_PATH", os.path.join(tmp, "test_admin_lifecycle.db"))
|
|
monkeypatch.setenv("AUTOPASS_WEB_AUTH_REQUIRED", "true")
|
|
monkeypatch.setenv("AUTOPASS_SIGNUP_RATE_MAX", "100")
|
|
from app.config import get_settings
|
|
get_settings.cache_clear()
|
|
from app.web import ratelimit
|
|
ratelimit._hits.clear()
|
|
from app.main import app
|
|
with TestClient(app, follow_redirects=False) as c:
|
|
yield c
|
|
get_settings.cache_clear()
|
|
|
|
|
|
def _csrf(client, url="/admin"):
|
|
resp = client.get(url, follow_redirects=True)
|
|
m = re.search(r'name="csrf_token"\s+value="([^"]+)"', resp.text)
|
|
assert m, f"csrf negasit in {url}"
|
|
return m.group(1)
|
|
|
|
|
|
def _signup(client, name, email, password="parola_test_001"):
|
|
tok = _csrf(client, "/signup")
|
|
resp = client.post("/signup", data={"name": name, "email": email, "parola": password,
|
|
"csrf_token": tok}, follow_redirects=True)
|
|
assert resp.status_code == 200
|
|
from app.db import get_connection
|
|
conn = get_connection()
|
|
try:
|
|
row = conn.execute("SELECT account_id FROM users WHERE email=? COLLATE NOCASE",
|
|
(email,)).fetchone()
|
|
return int(row["account_id"])
|
|
finally:
|
|
conn.close()
|
|
|
|
|
|
def _make_admin(account_id):
|
|
from app.db import get_connection
|
|
from app.users import set_admin
|
|
conn = get_connection()
|
|
try:
|
|
set_admin(conn, account_id, is_admin=True)
|
|
conn.commit()
|
|
finally:
|
|
conn.close()
|
|
|
|
|
|
def _login(client, email, password="parola_test_001"):
|
|
tok = _csrf(client, "/login")
|
|
resp = client.post("/login", data={"email": email, "parola": password, "csrf_token": tok})
|
|
assert resp.status_code == 303
|
|
|
|
|
|
def _status(account_id):
|
|
from app.db import get_connection
|
|
conn = get_connection()
|
|
try:
|
|
row = conn.execute("SELECT status FROM accounts WHERE id=?", (account_id,)).fetchone()
|
|
return row["status"] if row else None
|
|
finally:
|
|
conn.close()
|
|
|
|
|
|
def _admin_login(client):
|
|
admin_id = _signup(client, "Admin SA", "admin@test.ro")
|
|
_make_admin(admin_id)
|
|
_login(client, "admin@test.ro")
|
|
return admin_id
|
|
|
|
|
|
@pytest.mark.parametrize("verb,expected", [
|
|
("block", "blocked"),
|
|
("archive", "archived"),
|
|
("delete", "deleted"),
|
|
])
|
|
def test_lifecycle_single(client, verb, expected):
|
|
target = _signup(client, "Tinta SRL", "tinta@test.ro")
|
|
_admin_login(client)
|
|
tok = _csrf(client)
|
|
resp = client.post(f"/admin/{verb}", data={"account_id": target, "csrf_token": tok})
|
|
assert resp.status_code == 303
|
|
assert _status(target) == expected
|
|
|
|
|
|
def test_bulk_pe_lista_account_id(client):
|
|
a = _signup(client, "A SRL", "a@test.ro")
|
|
b = _signup(client, "B SRL", "b@test.ro")
|
|
_admin_login(client)
|
|
tok = _csrf(client)
|
|
resp = client.post("/admin/block", data={"account_id": [a, b], "csrf_token": tok})
|
|
assert resp.status_code == 303
|
|
assert _status(a) == "blocked" and _status(b) == "blocked"
|
|
|
|
|
|
def test_bulk_sare_contul_dev(client):
|
|
target = _signup(client, "Tinta SRL", "t2@test.ro")
|
|
_admin_login(client)
|
|
tok = _csrf(client)
|
|
# include id=1 (cont de sistem) in selectie -> sarit, fara eroare; tinta procesata
|
|
resp = client.post("/admin/archive", data={"account_id": [1, target], "csrf_token": tok})
|
|
assert resp.status_code == 303
|
|
assert _status(1) == "active", "contul dev id=1 trebuie sa ramana neatins"
|
|
assert _status(target) == "archived"
|
|
|
|
|
|
def test_non_admin_403(client):
|
|
target = _signup(client, "Tinta SRL", "t3@test.ro")
|
|
_signup(client, "Neadmin SRL", "plain@test.ro")
|
|
_login(client, "plain@test.ro")
|
|
# csrf de pe o pagina accesibila non-admin
|
|
tok = _csrf(client, "/")
|
|
resp = client.post("/admin/block", data={"account_id": target, "csrf_token": tok})
|
|
assert resp.status_code == 403
|
|
|
|
|
|
def test_csrf_obligatoriu(client):
|
|
target = _signup(client, "Tinta SRL", "t4@test.ro")
|
|
_admin_login(client)
|
|
resp = client.post("/admin/delete", data={"account_id": target}) # fara csrf_token
|
|
assert resp.status_code != 303
|
|
assert _status(target) != "deleted"
|