A post can say that a machine wrote it
A switch beside the button that publishes — on the editor, on a member's proposal and on a wall thread — and a pill next to the date wherever the post is read: the article, the cards in the listings, the thread, the wall's list, and the moderator's review screen. Next to the date rather than under the text, because a disclosure somebody meets after reading the thing is not a disclosure. Where it lives follows what the thing is. A public post carries `ai_generated: true` in its own frontmatter, written only when true — the file in the repository is the record, and `ai_generated: false` on every post ever written is noise in git and a question in the mind of whoever reads one. A thread carries a column. A proposal carries a column too, and that is the one place it has to be moved by hand: a proposal is a draft in SQLite until it is approved, so the frontmatter it will end up in does not exist while the decision is being made, and losing it there would lose it exactly when the text stops being private. `content.edit` loads the flag back into the form, for the same reason the byline is carried through: a field read but not written back is a field that one corrected typo silently removes. The pipeline needs nothing. translate.py copies the whole frontmatter and rewrites only TRANSLATED_KEYS, so the flag reaches the German and Portuguese siblings by itself — right rather than lucky, since a translated post was still machine-written. Asserted against the real list, so a key quietly added to it fails the suite. Migration 9: three plain ADD COLUMNs, tested against a database with a thread, a proposal and a cached post already in it. The three words are in partials/t.html with the theme's other labels. This is also the shape the EU AI Act's Article 50 asks for, which is worth knowing for whoever installs this for a second organisation. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NizVpJ2dwzCbjCrTLCjeHn
This commit is contained in:
parent
8e1ef8831c
commit
ff115c1d6b
@ -204,8 +204,10 @@ def new_thread():
|
||||
|
||||
title, body = cleaned
|
||||
cursor = get_db().execute(
|
||||
"INSERT INTO threads (author_id, title, body_md) VALUES (?, ?, ?)",
|
||||
(g.member["id"], title, body),
|
||||
"""INSERT INTO threads (author_id, title, body_md, ai_generated)
|
||||
VALUES (?, ?, ?, ?)""",
|
||||
(g.member["id"], title, body,
|
||||
1 if request.form.get("ai_generated") == "on" else 0),
|
||||
)
|
||||
uploads.save(staged, g.member["id"], thread_id=cursor.lastrowid)
|
||||
return redirect(url_for("board.thread", thread_id=cursor.lastrowid))
|
||||
@ -225,8 +227,11 @@ def edit_thread(thread_id: int):
|
||||
return redirect(url_for("board.edit_thread", thread_id=thread_id))
|
||||
title, body = cleaned
|
||||
get_db().execute(
|
||||
"UPDATE threads SET title = ?, body_md = ?, edited_at = datetime('now') WHERE id = ?",
|
||||
(title, body, thread_id),
|
||||
"""UPDATE threads SET title = ?, body_md = ?, ai_generated = ?,
|
||||
edited_at = datetime('now')
|
||||
WHERE id = ?""",
|
||||
(title, body, 1 if request.form.get("ai_generated") == "on" else 0,
|
||||
thread_id),
|
||||
)
|
||||
return redirect(url_for("board.thread", thread_id=thread_id))
|
||||
|
||||
|
||||
@ -159,6 +159,11 @@ def frontmatter_for(collection: str, form: dict) -> dict:
|
||||
fields["author"] = form["author"]
|
||||
if form.get("author_url"):
|
||||
fields["author_url"] = form["author_url"]
|
||||
# Only when true, for both collections: a line reading `ai_generated: false`
|
||||
# on every post ever written is noise in the repository and a question in
|
||||
# the mind of anybody reading the file.
|
||||
if form.get("ai_generated"):
|
||||
fields["ai_generated"] = True
|
||||
return fields
|
||||
|
||||
|
||||
@ -173,13 +178,15 @@ def _cache_read(path: str, sha: str):
|
||||
def _cache_write(path: str, sha: str, fm: dict) -> None:
|
||||
get_db().execute(
|
||||
"""INSERT INTO content_cache (path, sha, title, date, generated, image,
|
||||
event_date, event_time, event_location)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
event_date, event_time, event_location,
|
||||
ai_generated)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT(path) DO UPDATE SET
|
||||
sha = excluded.sha, title = excluded.title, date = excluded.date,
|
||||
generated = excluded.generated, image = excluded.image,
|
||||
event_date = excluded.event_date, event_time = excluded.event_time,
|
||||
event_location = excluded.event_location,
|
||||
ai_generated = excluded.ai_generated,
|
||||
updated_at = datetime('now')""",
|
||||
(path, sha, str(fm.get("title", "")), str(fm.get("date", "")),
|
||||
1 if fm.get("translated_from") else 0,
|
||||
@ -192,7 +199,8 @@ def _cache_write(path: str, sha: str, fm: dict) -> None:
|
||||
# internal ones and would otherwise read every post's frontmatter on
|
||||
# every page view to find out when they are.
|
||||
str(fm.get("event_date", "") or ""), str(fm.get("event_time", "") or ""),
|
||||
str(fm.get("event_location", "") or "")),
|
||||
str(fm.get("event_location", "") or ""),
|
||||
1 if fm.get("ai_generated") else 0),
|
||||
)
|
||||
|
||||
|
||||
@ -220,6 +228,7 @@ def listing(collection: str) -> list[dict]:
|
||||
"name": name, "path": path, "sha": sha,
|
||||
"title": row["title"] or name,
|
||||
"date": row["date"],
|
||||
"ai_generated": bool(row["ai_generated"]),
|
||||
"event_date": row["event_date"] or "",
|
||||
"event_time": row["event_time"] or "",
|
||||
"event_location": row["event_location"] or "",
|
||||
@ -320,6 +329,10 @@ def _read_form(collection: str) -> tuple[dict, str, list[str]]:
|
||||
"description": request.form.get("description", "").strip(),
|
||||
"image": image,
|
||||
"manual_translation": request.form.get("manual_translation") == "on",
|
||||
# Said by whoever is publishing, about this post. It travels in the
|
||||
# frontmatter rather than in a database, because the file in the
|
||||
# repository is the record of what was published.
|
||||
"ai_generated": request.form.get("ai_generated") == "on",
|
||||
"author": author, "author_url": author_url,
|
||||
"parent": parent, "weight": weight,
|
||||
"faq": faq, "image_alt": image_alt,
|
||||
@ -551,6 +564,11 @@ def edit(collection: str, name: str):
|
||||
"description": fm.get("description", ""),
|
||||
"image": fm.get("image", ""),
|
||||
"manual_translation": bool(fm.get("manual_translation")),
|
||||
# Loaded so the switch comes back the way it was left. A flag read
|
||||
# into the form but not written back out again is a flag that one
|
||||
# correction quietly removes — which is the whole failure the
|
||||
# byline below was given its comment for.
|
||||
"ai_generated": bool(fm.get("ai_generated")),
|
||||
# Carried through the form untouched. Correcting a typo in somebody
|
||||
# else's post must not re-sign it with the name of whoever is
|
||||
# fixing it — the same rule the board has about editing other
|
||||
|
||||
@ -338,6 +338,32 @@ def _room_for_identity_and_a_typeface(db: sqlite3.Connection) -> None:
|
||||
db.execute(f"ALTER TABLE {table} ADD COLUMN {column} TEXT")
|
||||
|
||||
|
||||
def _room_to_say_a_machine_wrote_it(db: sqlite3.Connection) -> None:
|
||||
"""One flag per place a post can live, so the disclosure survives the trip.
|
||||
|
||||
Plain ADD COLUMNs again. A public post carries the flag in its own
|
||||
frontmatter — the file in the repository is the record, not this database —
|
||||
and `content_cache.ai_generated` is only the copy that lets the editor's
|
||||
list show it without re-reading every file from the git server.
|
||||
|
||||
`submissions.ai_generated` is the one that has to exist rather than be
|
||||
derived: a proposal is a draft in SQLite for as long as it is in the queue,
|
||||
and the flag has to survive moderation to reach the frontmatter of the post
|
||||
it becomes.
|
||||
"""
|
||||
for table, columns in (("threads", ("ai_generated",)),
|
||||
("submissions", ("ai_generated",)),
|
||||
("content_cache", ("ai_generated",))):
|
||||
existing = _columns(db, table)
|
||||
if not existing:
|
||||
continue
|
||||
for column in columns:
|
||||
if column not in existing:
|
||||
db.execute(
|
||||
f"ALTER TABLE {table} ADD COLUMN {column} "
|
||||
"INTEGER NOT NULL DEFAULT 0")
|
||||
|
||||
|
||||
# (number, description, function). The number is the value written to
|
||||
# user_version once the step succeeds.
|
||||
STEPS = [
|
||||
@ -350,6 +376,7 @@ STEPS = [
|
||||
(7, "a superadministrator above the responsable", _a_superadmin_above_the_owner),
|
||||
(8, "room for the identity, a typeface and the media library",
|
||||
_room_for_identity_and_a_typeface),
|
||||
(9, "a post can say a machine wrote it", _room_to_say_a_machine_wrote_it),
|
||||
]
|
||||
|
||||
|
||||
|
||||
@ -54,6 +54,10 @@ CREATE TABLE IF NOT EXISTS threads (
|
||||
edited_at TEXT,
|
||||
pinned INTEGER NOT NULL DEFAULT 0 CHECK (pinned IN (0, 1)),
|
||||
locked INTEGER NOT NULL DEFAULT 0 CHECK (locked IN (0, 1)),
|
||||
-- Said out loud where the post is read. The association's own words and a
|
||||
-- machine's are both welcome here; which is which is not the reader's job
|
||||
-- to guess.
|
||||
ai_generated INTEGER NOT NULL DEFAULT 0 CHECK (ai_generated IN (0, 1)),
|
||||
-- Soft delete: a moderator's mistake stays recoverable, and removing one
|
||||
-- comment does not tear a hole in the conversation around it.
|
||||
deleted_at TEXT
|
||||
@ -202,6 +206,10 @@ CREATE TABLE IF NOT EXISTS content_cache (
|
||||
-- draft. Recorded here so the listing can skip them without re-reading
|
||||
-- every file to find out what it already knew.
|
||||
generated INTEGER NOT NULL DEFAULT 0 CHECK (generated IN (0, 1)),
|
||||
-- A copy of the post's own frontmatter flag, so the editor's list can show
|
||||
-- it without re-reading every file from the git server. The file is the
|
||||
-- record; this is the cache.
|
||||
ai_generated INTEGER NOT NULL DEFAULT 0 CHECK (ai_generated IN (0, 1)),
|
||||
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
);
|
||||
|
||||
@ -260,6 +268,10 @@ CREATE TABLE IF NOT EXISTS submissions (
|
||||
event_time TEXT,
|
||||
event_location TEXT,
|
||||
photo_name TEXT,
|
||||
-- Carried through moderation into the published post's frontmatter: a
|
||||
-- proposal is a draft in this database until it is approved, so the flag
|
||||
-- has nowhere else to wait.
|
||||
ai_generated INTEGER NOT NULL DEFAULT 0 CHECK (ai_generated IN (0, 1)),
|
||||
state TEXT NOT NULL DEFAULT 'pending'
|
||||
CHECK (state IN ('pending', 'approved', 'rejected')),
|
||||
-- Why it was rejected, in the moderator's words, shown to the author. A
|
||||
|
||||
@ -1018,6 +1018,12 @@ input[type="file"] {
|
||||
summary { padding: 0.95rem 0; }
|
||||
.account__name { padding: 0.9rem 0; }
|
||||
|
||||
/* The disclosure switch: 16px of words and a 13px box before this. The
|
||||
checkbox itself grows too — a label you can hit around a box you
|
||||
cannot is a control that looks broken when it misses. */
|
||||
.switch { padding: 0.7rem 0; }
|
||||
.switch input { width: 20px; height: 20px; }
|
||||
|
||||
.cal__add {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
|
||||
@ -97,6 +97,11 @@ def _read_proposal() -> tuple[dict, list[str]]:
|
||||
"title": request.form.get("title", "").strip()[:TITLE_MAX],
|
||||
"body": request.form.get("body", "").strip()[:BODY_MAX],
|
||||
"description": request.form.get("description", "").strip()[:300],
|
||||
# Said by the member about their own text, and carried through the queue
|
||||
# unchanged. A moderator can see it and can refuse the proposal; what
|
||||
# they cannot do is quietly publish it without the line, which is the
|
||||
# only way this disclosure is worth anything.
|
||||
"ai_generated": request.form.get("ai_generated") == "on",
|
||||
# The same three fields the editor asks for, read by the same function:
|
||||
# a member's event and a moderator's have to produce the same post.
|
||||
**content.read_event_fields(request.form, errors),
|
||||
@ -176,11 +181,12 @@ def propose():
|
||||
get_db().execute(
|
||||
"""INSERT INTO submissions
|
||||
(author_id, title, body_md, description, photo_name,
|
||||
event_date, event_time, event_location)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)""",
|
||||
event_date, event_time, event_location, ai_generated)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
||||
(g.member["id"], fields["title"], fields["body"], fields["description"],
|
||||
photo_name,
|
||||
fields["event_date"], fields["event_time"], fields["event_location"]),
|
||||
fields["event_date"], fields["event_time"], fields["event_location"],
|
||||
1 if fields["ai_generated"] else 0),
|
||||
)
|
||||
flash("Enviado. Un moderador lo leerá antes de publicarlo.", "ok")
|
||||
return redirect(url_for("submissions.index"))
|
||||
@ -242,13 +248,15 @@ def edit(submission_id: int):
|
||||
"""UPDATE submissions
|
||||
SET title = ?, body_md = ?, description = ?,
|
||||
photo_name = ?, event_date = ?, event_time = ?,
|
||||
event_location = ?, state = 'pending', note = NULL,
|
||||
event_location = ?, ai_generated = ?,
|
||||
state = 'pending', note = NULL,
|
||||
reviewed_by = NULL, reviewed_at = NULL,
|
||||
updated_at = datetime('now')
|
||||
WHERE id = ?""",
|
||||
(fields["title"], fields["body"], fields["description"],
|
||||
photo_name, fields["event_date"],
|
||||
fields["event_time"], fields["event_location"], submission_id),
|
||||
fields["event_time"], fields["event_location"],
|
||||
1 if fields["ai_generated"] else 0, submission_id),
|
||||
)
|
||||
# Back to pending on every edit, including one made after a rejection: a
|
||||
# rejected post that has been rewritten is waiting again, and leaving it
|
||||
@ -322,6 +330,10 @@ def approve(submission_id: int):
|
||||
"event_date": row["event_date"] or "",
|
||||
"event_time": row["event_time"] or "",
|
||||
"event_location": row["event_location"] or "",
|
||||
# The one field here the author set about their own writing. It has to
|
||||
# survive the queue or the disclosure is lost at the exact moment the
|
||||
# text stops being private.
|
||||
"ai_generated": bool(row["ai_generated"]),
|
||||
}
|
||||
# Read the picture before the try, and catch only the error that means what
|
||||
# it says. The first version wrapped everything in `except OSError`, which
|
||||
|
||||
@ -138,6 +138,14 @@
|
||||
|
||||
<div class="actions">
|
||||
<button class="btn" type="submit">{{ 'Guardar' if item else 'Publicar' }}</button>
|
||||
{#- Beside the button that publishes, because that is the moment it is
|
||||
answered. One line rather than a fieldset: it has to be seen, not
|
||||
to take up the form. -#}
|
||||
<label class="switch">
|
||||
<input type="checkbox" name="ai_generated" {{ 'checked' if f.ai_generated }}>
|
||||
Contenido generado con IA
|
||||
</label>
|
||||
|
||||
<button class="linkish" type="submit"
|
||||
formaction="{{ url_for('content.preview', collection=collection) }}">
|
||||
Vista previa
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
<td>
|
||||
<a href="{{ url_for('content.edit', collection=collection, name=item.name) }}">{{ item.title }}</a>
|
||||
<div class="muted small mono">{{ item.name }}</div>
|
||||
{% if item.ai_generated %}<span class="tag tag--ai" title="Quien lo publicó marcó este texto como generado con inteligencia artificial.">Generado con IA</span>{% endif %}
|
||||
</td>
|
||||
{# data-label is drawn by board.css under 640px, where the header row
|
||||
is hidden and a bare date in a stacked card says nothing. #}
|
||||
|
||||
@ -13,6 +13,9 @@
|
||||
<span class="tag tag--{{ item.state }}">{{ labels[item.state] }}</span>
|
||||
<span>{{ person(item.author, item.author_login) }}</span> · <time>{{ item.created_at }}</time>
|
||||
{% if item.event_date %} · <span>Evento el {{ item.event_date }}</span>{% endif %}
|
||||
{#- Shown to the moderator before they decide: a disclosure the reviewer
|
||||
cannot see is one they cannot weigh. -#}
|
||||
{% if item.ai_generated %}<span class="tag tag--ai" title="Quien lo publicó marcó este texto como generado con inteligencia artificial.">Generado con IA</span>{% endif %}
|
||||
</div>
|
||||
{% if item.description %}<p class="muted">{{ item.description }}</p>{% endif %}
|
||||
{% if item.photo_name %}
|
||||
|
||||
@ -66,6 +66,14 @@
|
||||
|
||||
<div class="actions">
|
||||
<button class="btn" type="submit">{{ 'Guardar' if item else 'Enviar a revisión' }}</button>
|
||||
{#- Beside the button that publishes, because that is the moment it is
|
||||
answered. One line rather than a fieldset: it has to be seen, not
|
||||
to take up the form. -#}
|
||||
<label class="switch">
|
||||
<input type="checkbox" name="ai_generated" {{ 'checked' if (fields.ai_generated if fields else False) }}>
|
||||
Contenido generado con IA
|
||||
</label>
|
||||
|
||||
<a class="linkish" href="{{ url_for('submissions.index') }}">Cancelar</a>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
<div class="card__meta">
|
||||
{% if thread.pinned %}<span class="tag">Fijado</span>{% endif %}
|
||||
{% if thread.locked %}<span class="tag tag--quiet">Cerrado</span>{% endif %}
|
||||
{% if thread.ai_generated %}<span class="tag tag--ai" title="Quien lo publicó marcó este texto como generado con inteligencia artificial.">Generado con IA</span>{% endif %}
|
||||
<span>{{ person(author.display_name, author.gitea_login) }}</span> · <time>{{ thread.created_at }}</time>
|
||||
{% if thread.edited_at %}<span class="muted small">(editado)</span>{% endif %}
|
||||
</div>
|
||||
|
||||
@ -30,6 +30,14 @@
|
||||
|
||||
<div class="actions">
|
||||
<button class="btn" type="submit">{{ 'Guardar' if thread else 'Publicar' }}</button>
|
||||
{#- Beside the button that publishes, because that is the moment it is
|
||||
answered. One line rather than a fieldset: it has to be seen, not
|
||||
to take up the form. -#}
|
||||
<label class="switch">
|
||||
<input type="checkbox" name="ai_generated" {{ 'checked' if (thread.ai_generated if thread else False) }}>
|
||||
Contenido generado con IA
|
||||
</label>
|
||||
|
||||
<a class="linkish" href="{{ url_for('board.thread', thread_id=thread.id) if thread else url_for('board.threads') }}">Cancelar</a>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
<div class="card__meta">
|
||||
{% if t.pinned %}<span class="tag">Fijado</span>{% endif %}
|
||||
{% if t.locked %}<span class="tag tag--quiet">Cerrado</span>{% endif %}
|
||||
{% if t.ai_generated %}<span class="tag tag--ai" title="Quien lo publicó marcó este texto como generado con inteligencia artificial.">Generado con IA</span>{% endif %}
|
||||
<span>{{ person(t.author, t.author_login) }}</span> · <time>{{ t.created_at }}</time>
|
||||
</div>
|
||||
<h2 class="card__title">
|
||||
|
||||
@ -145,3 +145,41 @@ def test_the_preview_is_never_cached(post, make_member, sign_in):
|
||||
sign_in(make_member("maria"))
|
||||
response = post("/comunidad/previsualizar", {"body": "hola"})
|
||||
assert response.headers["Cache-Control"] == "no-store"
|
||||
|
||||
|
||||
# --- said out loud on the wall too ----------------------------------------
|
||||
|
||||
def test_a_thread_can_say_a_machine_wrote_it(client, post, make_member, sign_in):
|
||||
"""The same disclosure inside the members area as on the public site. The
|
||||
people here know each other, which makes it more useful rather than less:
|
||||
nobody wants to answer a machine thinking they are answering a neighbour.
|
||||
"""
|
||||
sign_in(make_member("maria"))
|
||||
post("/comunidad/nuevo", {"title": "Resumen de la reunión",
|
||||
"body": "Lo que se decidió.", "ai_generated": "on"})
|
||||
|
||||
page = client.get("/comunidad/muro").get_data(as_text=True)
|
||||
assert "Generado con IA" in page
|
||||
assert "Generado con IA" in client.get("/comunidad/tema/1").get_data(as_text=True)
|
||||
|
||||
|
||||
def test_an_ordinary_thread_says_nothing_of_the_kind(client, post, make_member, sign_in):
|
||||
sign_in(make_member("maria"))
|
||||
post("/comunidad/nuevo", {"title": "Resumen", "body": "Escrito a mano."})
|
||||
assert "Generado con IA" not in client.get("/comunidad/muro").get_data(as_text=True)
|
||||
|
||||
|
||||
def test_editing_a_thread_can_add_or_remove_the_disclosure(client, post, make_member, sign_in):
|
||||
"""It is the author's statement about their own text, so it stays theirs
|
||||
to change — and an edit that forgets the field must not silently keep a
|
||||
mark the author has taken off."""
|
||||
member = make_member("maria")
|
||||
sign_in(member)
|
||||
post("/comunidad/nuevo", {"title": "Resumen", "body": "Primera versión.",
|
||||
"ai_generated": "on"})
|
||||
post("/comunidad/tema/1/editar", {"title": "Resumen", "body": "Reescrito a mano."})
|
||||
assert "Generado con IA" not in client.get("/comunidad/tema/1").get_data(as_text=True)
|
||||
|
||||
post("/comunidad/tema/1/editar", {"title": "Resumen", "body": "Otra vez con ayuda.",
|
||||
"ai_generated": "on"})
|
||||
assert "Generado con IA" in client.get("/comunidad/tema/1").get_data(as_text=True)
|
||||
|
||||
@ -629,3 +629,72 @@ def test_an_event_keeps_its_date_when_edited(repo, editor, post, client):
|
||||
front = yaml.safe_load(
|
||||
repo.files["content/post/2026-10-03-feria.es.md"].decode().split("---")[1])
|
||||
assert front["event_date"] == "2026-10-24"
|
||||
|
||||
|
||||
# --- said out loud: a machine wrote this ----------------------------------
|
||||
|
||||
def test_a_post_marked_as_ai_says_so_in_its_own_frontmatter(repo, editor, post):
|
||||
"""The file in the repository is the record of what was published, so the
|
||||
disclosure travels with it rather than living in a database the public
|
||||
site cannot read."""
|
||||
publish(post, ai_generated="on")
|
||||
path, = repo.files
|
||||
fm, _ = translate.split_frontmatter(repo.files[path].decode())
|
||||
assert fm["ai_generated"] is True
|
||||
|
||||
|
||||
def test_an_ordinary_post_carries_no_such_line(repo, editor, post):
|
||||
"""`ai_generated: false` on every post ever written is noise in the
|
||||
repository and a question in the mind of whoever reads the file."""
|
||||
publish(post)
|
||||
path, = repo.files
|
||||
fm, _ = translate.split_frontmatter(repo.files[path].decode())
|
||||
assert "ai_generated" not in fm
|
||||
|
||||
|
||||
def test_correcting_a_typo_does_not_quietly_remove_the_disclosure(
|
||||
repo, editor, post, client):
|
||||
"""The failure this is shaped around: a flag loaded into the form but not
|
||||
written back out again survives exactly until somebody fixes a comma.
|
||||
"""
|
||||
publish(post, ai_generated="on")
|
||||
path, = repo.files
|
||||
name = path.rsplit("/", 1)[1]
|
||||
|
||||
form = client.get(f"/comunidad/contenido/post/editar/{name}").get_data(as_text=True)
|
||||
assert 'name="ai_generated" checked' in form.replace(" ", " ")
|
||||
|
||||
post(f"/comunidad/contenido/post/editar/{name}",
|
||||
{"title": "Sabores del barrio", "body": "Texto corregido.",
|
||||
"date": "2026-09-25", "sha": repo._sha(repo.files[path]), "ai_generated": "on"})
|
||||
fm, _ = translate.split_frontmatter(repo.files[path].decode())
|
||||
assert fm["ai_generated"] is True
|
||||
|
||||
|
||||
def test_the_disclosure_can_be_taken_off_again(repo, editor, post, client):
|
||||
"""Somebody rewrites the text themselves. The switch is theirs to turn
|
||||
off, and the line goes with it."""
|
||||
publish(post, ai_generated="on")
|
||||
path, = repo.files
|
||||
name = path.rsplit("/", 1)[1]
|
||||
post(f"/comunidad/contenido/post/editar/{name}",
|
||||
{"title": "Sabores del barrio", "body": "Reescrito a mano.",
|
||||
"date": "2026-09-25", "sha": repo._sha(repo.files[path])})
|
||||
fm, _ = translate.split_frontmatter(repo.files[path].decode())
|
||||
assert "ai_generated" not in fm
|
||||
|
||||
|
||||
def test_the_disclosure_is_not_one_of_the_keys_translation_rewrites(repo, editor, post):
|
||||
"""A translated post was still machine-written, so the flag has to reach
|
||||
the German and Portuguese siblings untouched.
|
||||
|
||||
`translate_file` copies the whole frontmatter (`new_fm = dict(fm)`) and
|
||||
rewrites only TRANSLATED_KEYS, so this needs no change to the pipeline —
|
||||
asserted against the real list rather than assumed, because a key quietly
|
||||
added to it would send the flag through a translation engine.
|
||||
"""
|
||||
publish(post, ai_generated="on")
|
||||
path, = repo.files
|
||||
fm, _ = translate.split_frontmatter(repo.files[path].decode())
|
||||
assert fm["ai_generated"] is True
|
||||
assert "ai_generated" not in translate.TRANSLATED_KEYS
|
||||
|
||||
@ -440,3 +440,50 @@ def test_a_second_superadmin_is_not_seeded_over_the_first(tmp_path):
|
||||
assert db.execute(
|
||||
"SELECT COUNT(*) FROM members WHERE gitea_login = 'intruso'").fetchone()[0] == 0
|
||||
db.close()
|
||||
|
||||
|
||||
def test_step_nine_gives_every_post_somewhere_to_say_a_machine_wrote_it(tmp_path):
|
||||
"""Three plain ADD COLUMNs, and the rows around them untouched.
|
||||
|
||||
Built on the current schema and then wound back, like step six's test: the
|
||||
question here is not whether an old database survives — steps 5 and 7 cover
|
||||
that — but that a database with threads and proposals already in it gains
|
||||
the flag without losing any of them.
|
||||
"""
|
||||
from apps.board.app import create_app
|
||||
from apps.board.db import connect
|
||||
|
||||
path = str(tmp_path / "board.db")
|
||||
create_app({"SECRET_KEY": "x", "DB_PATH": path, "OWNER_LOGIN": "salvador",
|
||||
"UPLOAD_DIR": str(tmp_path / "uploads"), "TESTING": True})
|
||||
|
||||
db = connect(path)
|
||||
member = db.execute("SELECT id FROM members WHERE role = 'superadmin'").fetchone()["id"]
|
||||
db.execute("INSERT INTO threads (author_id, title, body_md) VALUES (?, ?, ?)",
|
||||
(member, "Un tema de antes", "Escrito antes de todo esto."))
|
||||
db.execute("""INSERT INTO submissions (author_id, title, body_md, description)
|
||||
VALUES (?, 'Una propuesta', 'Texto.', '')""", (member,))
|
||||
db.execute("""INSERT INTO content_cache (path, sha, title, date)
|
||||
VALUES ('content/post/2026-01-01-algo.es.md', 'abc', 'Algo', '2026-01-01')""")
|
||||
# Wind the version back and drop the columns, as a server that has been
|
||||
# running since before this phase has it.
|
||||
for table in ("threads", "submissions", "content_cache"):
|
||||
db.execute(f"ALTER TABLE {table} DROP COLUMN ai_generated")
|
||||
db.execute("PRAGMA user_version = 8")
|
||||
db.commit()
|
||||
db.close()
|
||||
|
||||
create_app({"SECRET_KEY": "x", "DB_PATH": path, "OWNER_LOGIN": "salvador",
|
||||
"UPLOAD_DIR": str(tmp_path / "uploads"), "TESTING": True})
|
||||
|
||||
db = connect(path)
|
||||
for table in ("threads", "submissions", "content_cache"):
|
||||
columns = {row[1] for row in db.execute(f"PRAGMA table_info({table})")}
|
||||
assert "ai_generated" in columns, table
|
||||
# Nothing written before the step is marked, and nothing is missing.
|
||||
assert db.execute("SELECT title, ai_generated FROM threads").fetchone()[:] == (
|
||||
"Un tema de antes", 0)
|
||||
assert db.execute("SELECT count(*) FROM submissions").fetchone()[0] == 1
|
||||
assert db.execute("PRAGMA user_version").fetchone()[0] == max(
|
||||
number for number, _, _ in migrations.STEPS)
|
||||
db.close()
|
||||
|
||||
@ -501,3 +501,55 @@ def test_a_proposal_with_a_nonsense_event_date_is_refused(db, post, maria, sign_
|
||||
|
||||
assert response.status_code == 400
|
||||
assert db.execute("SELECT COUNT(*) AS n FROM submissions").fetchone()["n"] == 0
|
||||
|
||||
|
||||
# --- the disclosure through the queue -------------------------------------
|
||||
|
||||
def test_a_members_disclosure_survives_moderation(repo, db, post, maria, luisa,
|
||||
sign_in):
|
||||
"""The member says it about their own writing; the moderator publishes it.
|
||||
|
||||
This is the only place the flag has to be carried by hand — a proposal is
|
||||
a draft in SQLite until it is approved, so the frontmatter it ends up in
|
||||
does not exist yet while the decision is being made. Losing it here would
|
||||
lose it at the exact moment the text stops being private.
|
||||
"""
|
||||
import yaml
|
||||
sign_in(maria)
|
||||
propose(post, ai_generated="on")
|
||||
submission_id = only_submission(db)["id"]
|
||||
assert only_submission(db)["ai_generated"] == 1
|
||||
|
||||
sign_in(luisa)
|
||||
post(f"/comunidad/publicaciones/{submission_id}/aprobar")
|
||||
|
||||
path, = repo.files
|
||||
front = yaml.safe_load(repo.files[path].decode("utf-8").split("---")[1])
|
||||
assert front["ai_generated"] is True
|
||||
|
||||
|
||||
def test_a_proposal_nobody_marked_publishes_without_the_line(repo, db, post,
|
||||
maria, luisa, sign_in):
|
||||
import yaml
|
||||
sign_in(maria)
|
||||
propose(post)
|
||||
submission_id = only_submission(db)["id"]
|
||||
|
||||
sign_in(luisa)
|
||||
post(f"/comunidad/publicaciones/{submission_id}/aprobar")
|
||||
|
||||
path, = repo.files
|
||||
front = yaml.safe_load(repo.files[path].decode("utf-8").split("---")[1])
|
||||
assert "ai_generated" not in front
|
||||
|
||||
|
||||
def test_the_moderator_can_see_what_they_are_approving(client, db, post, maria,
|
||||
luisa, sign_in):
|
||||
"""A disclosure the reviewer cannot see is one they cannot weigh."""
|
||||
sign_in(maria)
|
||||
propose(post, ai_generated="on")
|
||||
submission_id = only_submission(db)["id"]
|
||||
|
||||
sign_in(luisa)
|
||||
page = client.get(f"/comunidad/publicaciones/{submission_id}").get_data(as_text=True)
|
||||
assert "IA" in page
|
||||
|
||||
@ -1034,17 +1034,77 @@ the `|` survives.
|
||||
### 11.17 Writing boxes
|
||||
|
||||
Every box where somebody writes prose — the wall, a comment, a private message, a
|
||||
proposal, the editor, a profile bio — carries a markdown toolbar and a *Vista
|
||||
previa*, opted in with `data-markdown` and attached by `static/board.js`. The
|
||||
preview POSTs to `/comunidad/previsualizar`, which renders with `render.to_html`:
|
||||
the same function the board and the site use, so the preview cannot promise
|
||||
something publishing will not deliver. A markdown parser in the browser would be
|
||||
a second opinion about what somebody's text means.
|
||||
proposal, the editor, a profile bio — shows the formatting while it is being
|
||||
typed. Bold is bold, a heading is a heading. Opted in with `data-markdown` and
|
||||
attached by `static/board.js`; `data-rich="full"` on the four boxes that hold a
|
||||
post adds the three heading levels, both kinds of list and the quote, and the
|
||||
rest get bold, italic, link and clear formatting.
|
||||
|
||||
**Markdown is still the only thing stored.** That is what keeps the file in git,
|
||||
the pipeline, Decap and the XSS defence exactly as they were — and the two
|
||||
directions are deliberately not symmetrical:
|
||||
|
||||
- **opening** something to edit: the *server* renders the stored markdown into a
|
||||
`<template>` beside the box, which the editor adopts. There is no markdown
|
||||
parser in the browser, so there is no second opinion about what text means;
|
||||
- **saving**: the browser walks a closed set of elements back into markdown.
|
||||
Anything it does not recognise contributes its text and nothing else, and a
|
||||
paste arrives as plain text — so nothing anybody pastes brings markup in.
|
||||
|
||||
The **Markdown** button swaps the box for the raw text and back. It is the
|
||||
escape hatch if the editor ever mangles something, and the way to write a table
|
||||
or anything else the buttons do not offer. Coming back renders through
|
||||
`/comunidad/previsualizar` — the same `render.to_html`, for the same reason
|
||||
opening does. The editor's own *Vista previa*, which returns a whole page, is
|
||||
unrelated and still there: it needs no JavaScript and shows the published look.
|
||||
|
||||
**With scripting off the plain `<textarea>` is still there** and still the field
|
||||
that submits. Nothing is hidden by CSS; the script hides the textarea itself,
|
||||
and moves `required` off it first, because a hidden required field makes the
|
||||
browser refuse to submit and report the error on an element nobody can see.
|
||||
|
||||
The serializer is tested by running `static/board.js` in node against a table of
|
||||
documents (`apps/board/tests/test_editor.py`), including a round trip asserting
|
||||
markdown → HTML → markdown renders identically. Those tests skip where node is
|
||||
not installed.
|
||||
|
||||
**A line break means two different things**, so `render.py` has two renderers.
|
||||
Text this app stores and renders — the wall, messages, events — uses
|
||||
`breaks=True`: a newline somebody typed is a newline they meant. A public post
|
||||
is a file Hugo renders with hardWraps off, and the files are hard-wrapped at
|
||||
about 78 characters, so rendering those with breaks on would show a line break
|
||||
in the middle of every sentence. The editor writes the break CommonMark means,
|
||||
two spaces at the end of a line, which survives either way.
|
||||
|
||||
Choosing a picture shows a thumbnail with its name and size before anything is
|
||||
uploaded. That is the one reason `blob:` is in the `img-src` policy — a handle to
|
||||
bytes already in the page, which reaches no network.
|
||||
|
||||
### 11.17b «Contenido generado con IA»
|
||||
|
||||
A switch beside the button that publishes, on the three boxes that hold a post:
|
||||
the editor, a member's proposal and a wall thread. Where the post is read it is
|
||||
a pill next to the date — on the article, on the cards in the listings, on the
|
||||
thread and in the wall's list — because a disclosure somebody meets after
|
||||
reading the thing is not a disclosure.
|
||||
|
||||
| Where | How it is stored |
|
||||
|---|---|
|
||||
| A public post or page | `ai_generated: true` in the frontmatter, written only when true. The file in the repository is the record |
|
||||
| A member's proposal | `submissions.ai_generated`, carried into the published post on approval — the only place it has to be carried by hand, because a proposal is a draft in SQLite until the frontmatter exists |
|
||||
| A wall thread | `threads.ai_generated` |
|
||||
| The editor's list | `content_cache.ai_generated`, a copy so *Contenido* can show it without re-reading every file from the git server |
|
||||
|
||||
Migration 9, three plain `ADD COLUMN`s. The pipeline needs nothing: `translate.py`
|
||||
copies the whole frontmatter and rewrites only `TRANSLATED_KEYS`, so the flag
|
||||
reaches the German and Portuguese siblings by itself — which is right, since a
|
||||
translated post was still machine-written. The three words are in
|
||||
`partials/t.html` with the theme's other labels.
|
||||
|
||||
This is also the shape the EU AI Act's Article 50 asks for — telling people when
|
||||
they are reading machine-generated material — which is worth knowing for whoever
|
||||
installs this for the second organisation.
|
||||
|
||||
### 11.18 Marca: the superadministrator owns the look
|
||||
|
||||
*Gestión* → **Marca**, admins only. Colours, a logo and a favicon for both
|
||||
|
||||
@ -4140,3 +4140,23 @@ a.notif-card__message:hover {
|
||||
.back-link { display: inline-block; padding: 14px 0; }
|
||||
.agenda__move { min-width: 44px; min-height: 44px; }
|
||||
}
|
||||
|
||||
/* --- said out loud: a machine wrote this -------------------------------- */
|
||||
/*
|
||||
* Beside the date on the post and on its card. Quiet enough not to shout and
|
||||
* placed above the text rather than under it: a disclosure somebody meets
|
||||
* after reading the thing is not a disclosure. The words are in t.html, in
|
||||
* the three languages, because a post translated by the pipeline was still
|
||||
* machine-written and the label travels with it.
|
||||
*/
|
||||
.tag-ai {
|
||||
display: inline-block;
|
||||
padding: 2px 8px;
|
||||
border: 1px solid var(--border-light, #e0cec8);
|
||||
border-radius: 999px;
|
||||
background: var(--surface-soft, #faf2ef);
|
||||
color: var(--muted, #5c3d37);
|
||||
font-size: 0.72rem;
|
||||
letter-spacing: 0.02em;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
<article class="article-card">
|
||||
<div class="article-card__meta">
|
||||
<time datetime="{{ .Date.Format "2006-01-02" }}">{{ .Date.Format "2 Jan 2006" }}</time>
|
||||
{{ if .Params.ai_generated }}<span class="tag-ai" title="{{ partial "t.html" (dict "key" "aifull" "lang" .Site.Language.Lang) }}">{{ partial "t.html" (dict "key" "ai" "lang" .Site.Language.Lang) }}</span>{{ end }}
|
||||
</div>
|
||||
<h2 class="article-card__title"><a href="{{ .Permalink }}">{{ .Title }}</a></h2>
|
||||
<p class="article-card__excerpt">{{ .Description | default (.Summary | plainify | truncate 200) }}</p>
|
||||
|
||||
@ -27,6 +27,14 @@
|
||||
{{ end }}
|
||||
</span>
|
||||
{{ end }}
|
||||
{{/* Said where the post is read, beside the date — not under the text,
|
||||
where a disclosure arrives after the thing it discloses. Written by
|
||||
whoever published it, in the frontmatter; translate.py copies the key
|
||||
into the German and Portuguese siblings by itself, which is right:
|
||||
a translated post was still machine-written. */}}
|
||||
{{ if .Params.ai_generated }}
|
||||
<span class="tag-ai" title="{{ partial "t.html" (dict "key" "aifull" "lang" .Site.Language.Lang) }}">{{ partial "t.html" (dict "key" "ai" "lang" .Site.Language.Lang) }}</span>
|
||||
{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
<article class="article-card">
|
||||
<div class="article-card__meta">
|
||||
<time datetime="{{ .Date.Format "2006-01-02" }}">{{ .Date.Format "2 Jan 2006" }}</time>
|
||||
{{ if .Params.ai_generated }}<span class="tag-ai" title="{{ partial "t.html" (dict "key" "aifull" "lang" .Site.Language.Lang) }}">{{ partial "t.html" (dict "key" "ai" "lang" .Site.Language.Lang) }}</span>{{ end }}
|
||||
</div>
|
||||
<h2 class="article-card__title"><a href="{{ .Permalink }}">{{ .Title }}</a></h2>
|
||||
<p class="article-card__excerpt">{{ .Description | default (.Summary | plainify | truncate 200) }}</p>
|
||||
|
||||
@ -18,6 +18,10 @@
|
||||
"next" (dict "es" "Mes siguiente" "de" "Nächster Monat" "pt-br" "Próximo mês")
|
||||
"noevents" (dict "es" "No hay nada en este mes." "de" "In diesem Monat ist nichts geplant." "pt-br" "Nada marcado neste mês.")
|
||||
"allevents" (dict "es" "Todos los eventos" "de" "Alle Termine" "pt-br" "Todos os eventos")
|
||||
"ai" (dict "es" "Generado con IA" "de" "Mit KI erstellt" "pt-br" "Gerado com IA")
|
||||
"aifull" (dict "es" "Quien lo publicó marcó este texto como generado con inteligencia artificial."
|
||||
"de" "Wer diesen Beitrag veröffentlicht hat, hat ihn als mit künstlicher Intelligenz erstellt gekennzeichnet."
|
||||
"pt-br" "Quem publicou marcou este texto como gerado com inteligência artificial.")
|
||||
"community" (dict "es" "Comunidad" "de" "Community" "pt-br" "Comunidade")
|
||||
"menu" (dict "es" "Menú" "de" "Menü" "pt-br" "Menu")
|
||||
-}}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user