The second half of the superadministrator's job: not just who may do things, but
what they get to do that nobody else does.
**Identidad** is everything that used to be frozen in config.yaml — the name and
the one-line tagline in all three languages, the association's accounts
elsewhere, a public email, a city and street, a share picture and the footer
line. It commits data/site.yaml the way Marca commits data/brand.yaml.
Hugo cannot have config.yaml overridden by a data file, so the name and tagline
are read through two new partials that prefer the data file and fall back to the
config; every template showing either calls one, so they cannot drift. A site
with no data/site.yaml builds byte-for-byte what it built before — asserted by
building both ways and diffing with the stylesheet fingerprint normalised.
The contact fields are not decoration: they become ContactPoint and
PostalAddress in the Organization schema, which is what puts an association in a
local result rather than only a web one, and the social links become sameAs,
which is how an engine knows an Instagram account and this site are one body.
**Marca** grows a typeface and a roundness. Four system stacks — nothing
downloaded, which is deliberate and a GDPR matter — or an uploaded .woff2,
sniffed by its wOF2 signature, capped at 400 KB, named ahead of the old stack so
a font that fails to load leaves a readable site. The fold-out warning covers
missing accented glyphs, file size, synthesised bold, and licensing: a font is
software, a desktop licence is not a webfont licence, and that liability follows
the platform to every organisation it is installed for. SIL OFL and Apache-2.0
are named, with seven places to find them.
**Three tools.** Estado del sistema exercises the content token against the
repository rather than checking it is non-empty — "present" was never the
problem, a wrong scope broke publishing for three phases while looking fine —
and reports mail, backups, disk and every documented setting the container does
not have. It changes nothing on purpose. Registro de actividad records the dozen
acts that change who can do what; the actor is cleared and not cascaded on
erasure, and log() never raises, because an administrator who could not be
appointed because the note about it could not be saved is worse than a gap in
the notes. Biblioteca de medios lists every picture with the posts that use it
and, finally, shows the orphans — a picture whose post was deleted has stayed in
the repository, deployed and unreferenced, for the life of this site with no way
to see one.
Two bugs found by looking at the rendered pages rather than at the tests:
**Gestión had disappeared from the superadministrator's own navigation.**
base.html asked `g.member.role in ('owner', 'admin')`, right until a role
appeared above both. 622 tests passed while it was broken, because every one of
them signed in as an admin or below. The templates now call the same
`is_at_least` the handlers do, and test_navigation.py covers the tier above
admin — verified by reintroducing the tuple and watching it fail.
And the status screen counted the tombstone as a suspended member.
Migration 8 is plain ADD COLUMNs; `activity` and `site` are new tables, so
CREATE TABLE IF NOT EXISTS covers them with no step at all. The erase guard
caught both the moment they existed, which is that test doing its job.
627 tests pass. Hugo builds clean with the pipeline's flags, both with and
without the two data files.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NizVpJ2dwzCbjCrTLCjeHn
257 lines
10 KiB
Python
257 lines
10 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: private messages, *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",
|
|
"Miembros": "/comunidad/miembros",
|
|
"Publicaciones": "/comunidad/publicaciones",
|
|
"Calendario": "/comunidad/calendario",
|
|
}
|
|
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_five_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", "Miembros", "Publicaciones", "Calendario"]
|
|
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"))
|
|
|
|
|
|
# --- the tier above admin -------------------------------------------------
|
|
|
|
def test_the_superadmin_sees_gestion(nav, superadmin_id):
|
|
"""The regression this file exists for, one tier higher.
|
|
|
|
`base.html` asked `g.member.role in ('owner', 'admin')`, which was right
|
|
until a role appeared above both — and then Gestión vanished from the
|
|
navigation of the one account that owns every screen on it. 622 tests
|
|
passed while it was broken, because every one of them signed in as an
|
|
admin or below.
|
|
"""
|
|
body = nav(superadmin_id)
|
|
assert "Gestión" in body
|
|
assert "/comunidad/gestion" in body
|
|
|
|
|
|
@pytest.mark.parametrize("role", ["superadmin", "owner", "admin"])
|
|
def test_gestion_opens_for_every_role_that_can_see_it(role, client, db,
|
|
superadmin_id, make_member,
|
|
sign_in):
|
|
"""Seeing the link and reaching the page are two different checks, and a
|
|
role that passes one and fails the other is the worst of both."""
|
|
member_id = superadmin_id if role == "superadmin" else make_member("x", role=role)
|
|
sign_in(member_id)
|
|
assert client.get("/comunidad/gestion").status_code == 200
|
|
|
|
|
|
def test_the_public_strip_offers_gestion_to_the_superadmin(client, superadmin_id,
|
|
sign_in):
|
|
"""`sesion.json` draws the bar on vienalatina.com from its own list, so it
|
|
is a second place the same rule can be got wrong."""
|
|
sign_in(superadmin_id)
|
|
labels = [s["label"] for s in
|
|
client.get("/comunidad/sesion.json").get_json()["sections"]]
|
|
assert "Gestión" in labels
|