diff --git a/main.py b/main.py index 7d6505d..38e7ca6 100644 --- a/main.py +++ b/main.py @@ -545,7 +545,7 @@ MAX_MESSAGE_LEN = 10_000 # ⚠️ Версия UI — единый источник. БАМПАТЬ ПРИ КАЖДОМ ДЕПЛОЕ (формат: YYYY-MM-DD + буква). # Фронт берёт её через GET /api/version (chat.html + admin.html, элемент .app-version). -APP_VERSION = "2026-11-21j" +APP_VERSION = "2026-11-21k" # Audit: path → action name mapping _AUDIT_MAP = [ diff --git a/static/changelog.json b/static/changelog.json index 2f3c7da..8ffcf47 100644 --- a/static/changelog.json +++ b/static/changelog.json @@ -1,4 +1,11 @@ [ + { + "version": "2026-11-21k", + "date": "2026-11-21", + "changes": [ + "Логин и выход собраны в меню аккаунта справа: кружок с инициалом и почта, внутри — полный адрес и «Выйти»" + ] + }, { "version": "2026-11-21j", "date": "2026-11-21", @@ -6,13 +13,6 @@ "После пополнения счёта пробный доступ снимается: значок показывает баланс, а не «4 из 5 вопросов»" ] }, - { - "version": "2026-11-21i", - "date": "2026-11-21", - "changes": [ - "В шапке видно, под каким логином вы вошли — длинный адрес сокращается, полный в подсказке" - ] - }, { "version": "2026-11-21h", "date": "2026-11-21", diff --git a/static/chat.html b/static/chat.html index 821e39b..f046de2 100644 --- a/static/chat.html +++ b/static/chat.html @@ -211,10 +211,18 @@ button { font-family: inherit; } .header-actions button { padding: .38rem .8rem; background: transparent; border: 1.5px solid var(--border); border-radius: var(--radius); cursor: pointer; font-size: .78rem; color: var(--text-muted); font-weight: 500; transition: all .15s; } .header-actions button:hover { background: var(--bg); border-color: var(--accent); color: var(--accent); } .header-actions button:active { transform: translateY(1px); } -/* Кто вошёл — видно сразу: почта в шапке, длинная сокращается, полная в подсказке - (Хозяин, 21.11.2026: «вошёл под логином и нигде его не вижу»). */ -.user-chip { max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: .38rem .6rem; font-size: .78rem; color: var(--text-muted); background: var(--bg-sunken); border: 1px solid var(--border-light); border-radius: var(--radius); } -@media (max-width: 720px) { .user-chip { max-width: 140px; } } +/* Аккаунт — крайняя правая кнопка: кружок с инициалом и почтой, по нажатию меню с полным + адресом и «Выйти». Логин кнопкой среди действий — не дизайн (Хозяин, 21.11.2026). */ +.account { position: relative; flex: 0 0 auto; } +.account-btn { display: inline-flex; align-items: center; gap: .45rem; max-width: 220px; padding: .26rem .7rem .26rem .26rem; background: transparent; border: 1.5px solid var(--border); border-radius: 999px; cursor: pointer; font: inherit; font-size: .78rem; color: var(--text-muted); } +.account-btn:hover { background: var(--bg); border-color: var(--accent); color: var(--accent); } +.account-avatar { width: 1.5rem; height: 1.5rem; border-radius: 50%; background: var(--money); color: #fff; font-weight: 700; font-size: .74rem; display: inline-flex; align-items: center; justify-content: center; text-transform: uppercase; } +.account-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.account-menu { position: fixed; min-width: 240px; max-width: calc(100vw - 24px); background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-md); padding: .4rem; z-index: 1200; } +.account-menu-email { padding: .5rem .6rem; font-size: .8rem; color: var(--text-muted); border-bottom: 1px solid var(--border-light); margin-bottom: .35rem; word-break: break-all; } +.account-menu button { width: 100%; text-align: left; padding: .5rem .6rem; background: transparent; border: 0; border-radius: 6px; cursor: pointer; font: inherit; font-size: .85rem; color: var(--text); } +.account-menu button:hover, .account-menu button:focus-visible { background: var(--bg); } +@media (max-width: 720px) { .account-email { display: none; } .account-btn { padding: .26rem; } } #header .mode-on { border-color: var(--accent); color: var(--accent); font-weight: 650; } #messages { flex: 1; overflow-y: auto; padding: 1.2rem 1.6rem; display: flex; flex-direction: column; gap: .7rem; width: 100%; } @@ -713,8 +721,17 @@ html { color-scheme: light; } - - + @@ -1235,17 +1252,52 @@ const API = ''; // («Cannot access '_boxTimers' before initialization», видел на боевом 17.09.2026). const _boxTimers = {}; let token = localStorage.getItem('token'); -// Кто вошёл — в шапке с первой отрисовки, а не только после входа (оба пути ниже зовут это же). +// Кто вошёл — меню аккаунта справа с первой отрисовки, а не только после входа. function renderUserChip() { - const el = document.getElementById('user-chip'); - if (!el) return; + const box = document.getElementById('account'); + if (!box) return; let email = ''; try { email = token ? (_jwtPayload(token).sub || '') : ''; } catch (e) {} - if (!email) { el.style.display = 'none'; el.textContent = ''; el.removeAttribute('title'); return; } - el.textContent = email; - el.title = 'Вы вошли как ' + email; - el.style.display = ''; + if (!email) { + box.style.display = 'none'; + closeAccountMenu(); + return; + } + const btn = document.getElementById('account-btn'); + const av = document.getElementById('account-avatar'); + const em = document.getElementById('account-email'); + const menuEmail = document.getElementById('account-menu-email'); + if (av) av.textContent = email.trim().charAt(0) || '?'; + if (em) em.textContent = email; + if (menuEmail) menuEmail.textContent = email; + if (btn) { btn.title = 'Вы вошли как ' + email; btn.setAttribute('aria-expanded', 'false'); } + box.style.display = ''; } +function closeAccountMenu() { + const menu = document.getElementById('account-menu'); + const btn = document.getElementById('account-btn'); + if (menu) menu.style.display = 'none'; + if (btn) btn.setAttribute('aria-expanded', 'false'); +} +function toggleAccountMenu(ev) { + if (ev) ev.stopPropagation(); + const menu = document.getElementById('account-menu'); + const btn = document.getElementById('account-btn'); + if (!menu || !btn) return; + if (menu.style.display !== 'none') { closeAccountMenu(); return; } + // fixed-позиция под кнопкой: на телефоне шапка прокручивается вбок, и абсолютное меню + // внутри неё обрезалось бы (не дизайн, а ловушка вёрстки). + const r = btn.getBoundingClientRect(); + menu.style.display = ''; + const w = menu.offsetWidth; + menu.style.top = (r.bottom + 6) + 'px'; + menu.style.left = Math.max(8, Math.min(r.right - w, window.innerWidth - w - 8)) + 'px'; + btn.setAttribute('aria-expanded', 'true'); +} +document.addEventListener('click', (e) => { + if (!e.target.closest || !e.target.closest('.account')) closeAccountMenu(); +}); +document.addEventListener('keydown', (e) => { if (e.key === 'Escape') closeAccountMenu(); }); try { renderUserChip(); } catch (e) {} // Причина, по которой сервер выставил человека (блокировка). Объявлена здесь, до первого // показа формы входа: гостю без пропуска форму показывают сразу при загрузке (01.10.2026). diff --git a/tests/test_chat_user_chip_ui.py b/tests/test_chat_user_chip_ui.py index 220ca2f..4eb51bd 100644 --- a/tests/test_chat_user_chip_ui.py +++ b/tests/test_chat_user_chip_ui.py @@ -1,9 +1,11 @@ -"""Шапка чата показывает, кто вошёл. +"""Аккаунт в шапке чата: кто вошёл и выход — в меню справа, а не кнопкой среди действий. -Живой случай 21.11.2026 (Хозяин): вошёл под sale@teplodv.ru и нигде не увидел свой логин. -Проверка ведёт настоящую страницу чата в браузере; в подсказке — полный адрес. +Живой случай 21.11.2026 (Хозяин): вошёл под sale@teplodv.ru и не увидел логина; первая +правка поставила почту кнопкой между действиями — Хозяин справедливо назвал это уродством. +Здесь проверяется меню аккаунта: кружок с инициалом и почта, по нажатию — полный адрес +и «Выйти», закрытие по Escape и по клику мимо. -Mutation: убрать вызов отрисовки при загрузке — падает видимость; скрыть подсказку — падает title. +Mutation: убрать отрисовку при загрузке — падает видимость; убрать «Выйти» из меню — падает состав. """ import functools import http.server @@ -41,16 +43,45 @@ def site(tmp_path_factory): srv.server_close() -def test_header_shows_logged_in_email(browser, site): +def test_account_menu_shows_email_and_logout(browser, site): ctx = browser.new_context(viewport={"width": 1280, "height": 900}) pg = ctx.new_page() pg.set_default_timeout(8000) try: pg.goto(site) pg.wait_for_selector("#chat-screen", state="visible") - chip = pg.locator("#user-chip") - assert chip.is_visible(), "в шапке нет логина вошедшего" - assert chip.inner_text() == "stub@user", chip.inner_text() - assert pg.get_attribute("#user-chip", "title") == "Вы вошли как stub@user" + btn = pg.locator("#account-btn") + assert btn.is_visible(), "в шапке нет меню аккаунта" + assert "stub@user" in btn.inner_text(), btn.inner_text() + assert pg.locator("#account-avatar").inner_text().strip() == "S" + assert pg.get_attribute("#account-btn", "title") == "Вы вошли как stub@user" + menu = pg.locator("#account-menu") + assert not menu.is_visible(), "меню открыто до нажатия" + btn.click() + assert menu.is_visible(), "меню не открылось" + текст = menu.inner_text() + assert "stub@user" in текст and "Выйти" in текст, текст + pg.keyboard.press("Escape") + assert not menu.is_visible(), "Escape не закрыл меню" + btn.click() + assert menu.is_visible() + pg.mouse.click(3, 300) + assert not menu.is_visible(), "клик мимо не закрыл меню" + finally: + ctx.close() + + +def test_account_menu_fits_phone(browser, site): + """На телефоне шапка прокручивается вбок — меню обязано открыться целиком, не обрезаясь.""" + ctx = browser.new_context(viewport={"width": 390, "height": 844}) + pg = ctx.new_page() + pg.set_default_timeout(8000) + try: + pg.goto(site) + pg.wait_for_selector("#chat-screen", state="visible") + pg.locator("#account-btn").click() + box = pg.locator("#account-menu").bounding_box() + assert box, "меню не открылось на телефоне" + assert box["x"] >= 0 and box["x"] + box["width"] <= 390 + 0.5, box finally: ctx.close()