**A signed-in member sees the members area from anywhere.** A slim bar above the
public header, with the same five sections /comunidad/ has. Those pages are
files on disk and get cached, so it is drawn in the browser: memberbar.js asks
/comunidad/sesion.json who is reading, and that endpoint is the only thing that
decides — a visitor is told `{"signed_in": false}` and the answer is never
cached. Sign-in also sets vl_sesion=1, a cookie holding one digit that scripts
can read, and without it the script makes no request at all: a stranger reading
one article costs the app nothing. It is a hint, never a credential — the
session cookie stays HttpOnly and signed, and a forged hint earns a reply saying
you are not signed in. Comunidad is now in the public menu in all three
languages, signed in or not.
**The public menu is built from the pages.** It was three names per language in
config.yaml, so a page published through Contenido never appeared on the site at
all and the German and Portuguese menus had to be kept in step by hand. Pages
carry `parent` (another page's basename — the one translate.py already uses to
pair siblings, so it holds in all three languages) and `weight`, both chosen in
the editor, and header.html builds two levels from them. URLs do not change: a
subpage is still /page/<slug>/, only the menu nests, so nothing in the Caddyfile
or the pipeline learns about folders. The dropdown is the theme's own, ported
from WordPress — hover, focus-within, inline on a phone, no script. A parent that
has been deleted is kept and labelled rather than silently dropped on the next
save.
**Sharing and the rest of SEO/GEO.** The groundwork was already here — hreflang,
Open Graph, Twitter card, BlogPosting, llms.txt, robots.txt naming the AI
crawlers — so this closes the gaps. Static pages had *none* of it and shared as
bare links; they now carry WebPage schema and the full set of tags. Both branches
gain og:image with an alt and a twitter:image, falling back to params.defaultImage
(empty until there is a logo, which is the one line to fill in then). The home
page gains Organization with areaServed Wien and a sameAs list; posts and pages
gain BreadcrumbList, and an article's structured data now carries the author's
profile URL. An optional FAQ — `pregunta|respuesta` per line — renders at the
foot of the page and as FAQPage schema, because current guidance for generative
engines puts exactly that shape at the top of what gets quoted, and schema
describing something invisible is what search engines penalise. translate.py
carries both new fields: image_alt joins the translated keys, and faq is
translated half by half so the separator survives.
**The writing boxes.** A markdown toolbar and a Vista previa on every box where
somebody writes prose, opted in with data-markdown. The preview POSTs to
/comunidad/previsualizar and renders with render.to_html — the same function the
board and the site use, so it cannot promise something publishing will not
deliver; a markdown parser in the browser would be a second opinion about what
somebody's text means. Choosing a picture now shows a thumbnail with its name and
size before anything is uploaded, which is the only reason `blob:` joins img-src:
a handle to bytes already in the page, reaching no network.
All of it ours, no dependency added, under a policy that loads scripts from this
origin only. Verified by building the site with Hugo 0.135, the version the
pipeline runs: the nested menu, the page's share tags, the FAQ schema matching
the rendered section, and llms.txt listing the pages.
463 tests pass.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NizVpJ2dwzCbjCrTLCjeHn
219 lines
8.7 KiB
Python
219 lines
8.7 KiB
Python
"""What each role can see and reach.
|
|
|
|
This file exists because of a bug that no other test in this suite could have
|
|
caught: *Privados*, *Mi perfil* and *Contenido* were all inside one
|
|
`{% if g.member.role in ('owner', 'admin') %}` block in base.html, so an
|
|
ordinary member signed in to a wall and a member list and nothing else. Every
|
|
feature worked. Every test passed. Most of the members area was simply invisible
|
|
to the people it was built for.
|
|
|
|
So the navigation is now asserted per role, from the rendered page, and every
|
|
section is asserted from its route as well — because a link nobody can see and a
|
|
link that 403s are the same thing to whoever needed it.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
# Label -> the path it leads to. Both halves matter: the label is what a member
|
|
# looks for, the path is what has to answer.
|
|
SECTIONS = {
|
|
"Inicio": "/comunidad/",
|
|
"Muro": "/comunidad/muro",
|
|
"Privados": "/comunidad/privados",
|
|
"Publicaciones": "/comunidad/publicaciones",
|
|
}
|
|
ADMIN_ONLY = {"Gestión": "/comunidad/gestion"}
|
|
|
|
|
|
@pytest.fixture
|
|
def nav(client, sign_in):
|
|
def _nav(member_id):
|
|
sign_in(member_id)
|
|
page = client.get("/comunidad/")
|
|
assert page.status_code == 200
|
|
return page.get_data(as_text=True)
|
|
return _nav
|
|
|
|
|
|
@pytest.mark.parametrize("role", ["user", "moderator"])
|
|
def test_a_member_sees_the_four_shared_sections(role, nav, make_member):
|
|
"""The regression. Not one of these may depend on a role again."""
|
|
body = nav(make_member("maria", role=role))
|
|
for label in SECTIONS:
|
|
assert f">{label}" in body or f"{label}<" in body, label
|
|
|
|
|
|
@pytest.mark.parametrize("role", ["user", "moderator"])
|
|
def test_a_member_does_not_see_gestion(role, nav, make_member):
|
|
assert "Gestión" not in nav(make_member("maria", role=role))
|
|
|
|
|
|
def test_an_admin_sees_everything(nav, make_member):
|
|
body = nav(make_member("admina", role="admin"))
|
|
for label in list(SECTIONS) + list(ADMIN_ONLY):
|
|
assert label in body, label
|
|
|
|
|
|
@pytest.mark.parametrize("role", ["user", "moderator", "admin"])
|
|
def test_the_account_items_are_in_the_corner_for_everybody(role, nav, make_member):
|
|
"""They used to be navigation entries, and two of them admin-only. A member
|
|
with no way to reach their own profile or their own data export is the same
|
|
bug wearing a different hat."""
|
|
body = nav(make_member("maria", role=role))
|
|
assert "/comunidad/mi-perfil" in body
|
|
assert "/comunidad/mis-datos" in body
|
|
assert "Salir" in body
|
|
|
|
|
|
@pytest.mark.parametrize("role", ["user", "moderator", "admin"])
|
|
@pytest.mark.parametrize("path", sorted(SECTIONS.values()))
|
|
def test_every_shared_section_answers_for_every_role(role, path, client, make_member, sign_in):
|
|
sign_in(make_member("maria", role=role))
|
|
assert client.get(path).status_code == 200
|
|
|
|
|
|
@pytest.mark.parametrize("role", ["user", "moderator"])
|
|
def test_gestion_is_refused_below_admin(role, client, make_member, sign_in):
|
|
"""Refused by the route, not hidden by the template. A moderator who types
|
|
the address meets the same answer as one who cannot see the link."""
|
|
sign_in(make_member("maria", role=role))
|
|
assert client.get("/comunidad/gestion").status_code == 403
|
|
|
|
|
|
def test_gestion_opens_for_an_admin(client, make_member, sign_in):
|
|
sign_in(make_member("admina", role="admin"))
|
|
assert client.get("/comunidad/gestion").status_code == 200
|
|
|
|
|
|
def test_signing_in_lands_on_inicio(client, db, post, make_member):
|
|
"""It used to land on the wall, which is one of five places something may
|
|
have happened since the last visit."""
|
|
from apps.board import passwords
|
|
member_id = make_member("maria")
|
|
db.execute("UPDATE members SET password_hash = ? WHERE id = ?",
|
|
(passwords.hash_password("una-contraseña-larga"), member_id))
|
|
|
|
response = post("/comunidad/login",
|
|
{"identifier": "maria", "password": "una-contraseña-larga"})
|
|
|
|
assert response.status_code == 302
|
|
assert response.headers["Location"].rstrip("/").endswith("/comunidad")
|
|
|
|
|
|
def test_the_wall_keeps_its_thread_urls(client, post, make_member, sign_in):
|
|
"""The wall moved from /comunidad/ to /comunidad/muro. Thread addresses did
|
|
not, because people have linked to them from private messages."""
|
|
sign_in(make_member("maria"))
|
|
post("/comunidad/nuevo", {"title": "Hola", "body": "Qué tal"})
|
|
|
|
assert client.get("/comunidad/tema/1").status_code == 200
|
|
assert client.get("/comunidad/muro").status_code == 200
|
|
|
|
|
|
def test_signed_out_visitors_get_no_navigation(client):
|
|
body = client.get("/comunidad/login").get_data(as_text=True)
|
|
for label in list(SECTIONS) + list(ADMIN_ONLY):
|
|
assert f'>{label}<' not in body, label
|
|
|
|
|
|
# --- reaching the published articles --------------------------------------
|
|
#
|
|
# The screen worked and nothing linked to it: Gestión offered only the static
|
|
# pages, and the Artículos tab exists only once you are already on that screen.
|
|
# A moderator, who cannot open Gestión at all, had no route to it.
|
|
|
|
def test_an_admin_reaches_the_articles_from_gestion(client, make_member, sign_in):
|
|
sign_in(make_member("admina", role="admin"))
|
|
|
|
body = client.get("/comunidad/gestion").get_data(as_text=True)
|
|
|
|
assert "/comunidad/contenido/post" in body
|
|
assert "Artículos publicados" in body
|
|
|
|
|
|
def test_a_moderator_reaches_them_from_publicaciones(client, make_member, sign_in):
|
|
"""Their only way in, so it is a link in the heading rather than a clause in
|
|
a paragraph."""
|
|
sign_in(make_member("luisa", role="moderator"))
|
|
|
|
body = client.get("/comunidad/publicaciones").get_data(as_text=True)
|
|
|
|
assert "/comunidad/contenido/post" in body
|
|
assert "Ya publicado" in body
|
|
|
|
|
|
def test_a_plain_member_is_offered_neither(client, make_member, sign_in):
|
|
sign_in(make_member("maria"))
|
|
|
|
body = client.get("/comunidad/publicaciones").get_data(as_text=True)
|
|
|
|
assert "/comunidad/contenido" not in body
|
|
assert "Ya publicado" not in body
|
|
|
|
|
|
# --- the strip the public site draws --------------------------------------
|
|
#
|
|
# vienalatina.com is files on disk, so the bar is drawn by a script that asks
|
|
# this app who is reading. That makes this endpoint the whole privacy surface:
|
|
# it is the only thing on the public side that knows anything about anybody.
|
|
|
|
def test_a_visitor_is_told_nothing(client):
|
|
response = client.get("/comunidad/sesion.json")
|
|
|
|
assert response.status_code == 200
|
|
assert response.get_json() == {"signed_in": False}
|
|
assert response.headers["Cache-Control"] == "no-store"
|
|
|
|
|
|
def test_a_member_gets_their_name_and_their_sections(client, make_member, sign_in):
|
|
sign_in(make_member("maria"))
|
|
|
|
state = client.get("/comunidad/sesion.json").get_json()
|
|
|
|
assert state["signed_in"] is True
|
|
assert state["name"] == "Maria"
|
|
assert [s["label"] for s in state["sections"]] == [
|
|
"Inicio", "Muro", "Privados", "Publicaciones"]
|
|
assert state["csrf"] # the bar renders a real logout form
|
|
|
|
|
|
def test_the_sections_follow_the_same_rule_as_the_navigation(
|
|
client, make_member, sign_in):
|
|
"""Two places listing the sections would drift the first time one changed;
|
|
the navigation and this endpoint have to agree about Gestión."""
|
|
sign_in(make_member("admina", role="admin"))
|
|
labels = [s["label"] for s in client.get("/comunidad/sesion.json").get_json()["sections"]]
|
|
assert "Gestión" in labels
|
|
|
|
sign_in(make_member("luisa", role="moderator"))
|
|
labels = [s["label"] for s in client.get("/comunidad/sesion.json").get_json()["sections"]]
|
|
assert "Gestión" not in labels
|
|
|
|
|
|
def test_the_answer_is_never_cached(client, make_member, sign_in):
|
|
"""A cached answer is somebody else's name on a shared machine, or a bar
|
|
that stays up after signing out."""
|
|
sign_in(make_member("maria"))
|
|
assert client.get("/comunidad/sesion.json").headers["Cache-Control"] == "no-store"
|
|
|
|
|
|
def test_signing_in_sets_the_hint_and_signing_out_clears_it(client, db, post, make_member):
|
|
"""The hint is what keeps a stranger reading one article from costing a
|
|
request to this app on every page view."""
|
|
from apps.board import passwords
|
|
member_id = make_member("maria")
|
|
db.execute("UPDATE members SET password_hash = ? WHERE id = ?",
|
|
(passwords.hash_password("una-contraseña-larga"), member_id))
|
|
|
|
signed_in = post("/comunidad/login",
|
|
{"identifier": "maria", "password": "una-contraseña-larga"})
|
|
cookie = signed_in.headers.get_all("Set-Cookie")
|
|
assert any("vl_sesion=1" in header for header in cookie)
|
|
assert any("HttpOnly" not in header for header in cookie if "vl_sesion" in header)
|
|
|
|
signed_out = post("/comunidad/logout")
|
|
assert any("vl_sesion=;" in header or "vl_sesion=\"\"" in header
|
|
for header in signed_out.headers.get_all("Set-Cookie"))
|