"""
05.10.2026 — найдено при сверке описания LOGIKA_PROSTO с кодом (Claude).
"""

import pathlib

ROOT = pathlib.Path(__file__).resolve().parents[2]
ENGINE = ROOT / "engine" / "timesheet"
SQL = (ROOT / "sql" / "117_password_guard_and_depot_roles.sql").read_text(encoding="utf-8")


def test_password_change_checks_rights_again():
    assert "PERFORM app.check_can_touch_user(p_user_id)" in SQL
    assert "password_changed_at = now()" in SQL


def test_depot_loses_role_granting():
    assert "r.code IN ('rc_head', 'rc_deputy')" in SQL
    assert "p.code = 'access.grant_below'" in SQL


def test_saving_matrix_keeps_hidden_rights():
    from timesheet.settingsdb import INERT_PERMISSIONS
    src = (ENGINE / "settingsdb.py").read_text(encoding="utf-8")
    assert "audit.read" not in INERT_PERMISSIONS
    assert 'if r["perm_code"] not in INERT_PERMISSIONS' in src


def test_depot_sees_account_form_for_new_hire():
    t = (ENGINE / "templates" / "staff_card.html").read_text(encoding="utf-8")
    assert "{% if can_users or (can_draft and person.confirmed_at is none" in t
