From ff115c1d6bfcbb4812e614edb0626c4c138cddf9 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 6 Oct 2026 20:19:06 +0000 Subject: [PATCH] A post can say that a machine wrote it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Claude-Session: https://claude.ai/code/session_01NizVpJ2dwzCbjCrTLCjeHn --- apps/board/board.py | 13 ++-- apps/board/content.py | 24 ++++++- apps/board/migrations.py | 27 +++++++ apps/board/schema.sql | 12 ++++ apps/board/static/board.css | 6 ++ apps/board/submissions.py | 22 ++++-- apps/board/templates/content_form.html | 8 +++ apps/board/templates/content_list.html | 1 + apps/board/templates/submission.html | 3 + apps/board/templates/submission_form.html | 8 +++ apps/board/templates/thread.html | 1 + apps/board/templates/thread_form.html | 8 +++ apps/board/templates/threads.html | 1 + apps/board/tests/test_board.py | 38 ++++++++++ apps/board/tests/test_content.py | 69 ++++++++++++++++++ apps/board/tests/test_migrations.py | 47 ++++++++++++ apps/board/tests/test_submissions.py | 52 ++++++++++++++ docs/server-setup.md | 72 +++++++++++++++++-- themes/vienalatina/assets/css/main.css | 20 ++++++ themes/vienalatina/layouts/_default/list.html | 1 + .../vienalatina/layouts/_default/single.html | 8 +++ themes/vienalatina/layouts/index.html | 1 + themes/vienalatina/layouts/partials/t.html | 4 ++ 23 files changed, 428 insertions(+), 18 deletions(-) diff --git a/apps/board/board.py b/apps/board/board.py index 80b5cb1..5ea8dc9 100644 --- a/apps/board/board.py +++ b/apps/board/board.py @@ -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)) diff --git a/apps/board/content.py b/apps/board/content.py index ec46b5a..160401d 100644 --- a/apps/board/content.py +++ b/apps/board/content.py @@ -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 diff --git a/apps/board/migrations.py b/apps/board/migrations.py index cb04578..fcbc6c0 100644 --- a/apps/board/migrations.py +++ b/apps/board/migrations.py @@ -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), ] diff --git a/apps/board/schema.sql b/apps/board/schema.sql index 2e04691..aa07b31 100644 --- a/apps/board/schema.sql +++ b/apps/board/schema.sql @@ -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 diff --git a/apps/board/static/board.css b/apps/board/static/board.css index a83077f..4bcfdd3 100644 --- a/apps/board/static/board.css +++ b/apps/board/static/board.css @@ -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; diff --git a/apps/board/submissions.py b/apps/board/submissions.py index 1fcbf9b..ab62781 100644 --- a/apps/board/submissions.py +++ b/apps/board/submissions.py @@ -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 diff --git a/apps/board/templates/content_form.html b/apps/board/templates/content_form.html index 60a96d0..2dceabb 100644 --- a/apps/board/templates/content_form.html +++ b/apps/board/templates/content_form.html @@ -138,6 +138,14 @@
+ {#- 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. -#} + +
{% if item.description %}

{{ item.description }}

{% endif %} {% if item.photo_name %} diff --git a/apps/board/templates/submission_form.html b/apps/board/templates/submission_form.html index f703045..e78d706 100644 --- a/apps/board/templates/submission_form.html +++ b/apps/board/templates/submission_form.html @@ -66,6 +66,14 @@
+ {#- 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. -#} + + Cancelar
diff --git a/apps/board/templates/thread.html b/apps/board/templates/thread.html index b698cf0..71edc60 100644 --- a/apps/board/templates/thread.html +++ b/apps/board/templates/thread.html @@ -9,6 +9,7 @@
{% if thread.pinned %}Fijado{% endif %} {% if thread.locked %}Cerrado{% endif %} + {% if thread.ai_generated %}Generado con IA{% endif %} {{ person(author.display_name, author.gitea_login) }} · {% if thread.edited_at %}(editado){% endif %}
diff --git a/apps/board/templates/thread_form.html b/apps/board/templates/thread_form.html index cc34cd3..0d1d808 100644 --- a/apps/board/templates/thread_form.html +++ b/apps/board/templates/thread_form.html @@ -30,6 +30,14 @@
+ {#- 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. -#} + + Cancelar
diff --git a/apps/board/templates/threads.html b/apps/board/templates/threads.html index 0f2153e..a55595f 100644 --- a/apps/board/templates/threads.html +++ b/apps/board/templates/threads.html @@ -20,6 +20,7 @@
{% if t.pinned %}Fijado{% endif %} {% if t.locked %}Cerrado{% endif %} + {% if t.ai_generated %}Generado con IA{% endif %} {{ person(t.author, t.author_login) }} ·

diff --git a/apps/board/tests/test_board.py b/apps/board/tests/test_board.py index 9083695..b5fd62c 100644 --- a/apps/board/tests/test_board.py +++ b/apps/board/tests/test_board.py @@ -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) diff --git a/apps/board/tests/test_content.py b/apps/board/tests/test_content.py index a1b43da..2270efb 100644 --- a/apps/board/tests/test_content.py +++ b/apps/board/tests/test_content.py @@ -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 diff --git a/apps/board/tests/test_migrations.py b/apps/board/tests/test_migrations.py index 6306dd8..7efbecb 100644 --- a/apps/board/tests/test_migrations.py +++ b/apps/board/tests/test_migrations.py @@ -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() diff --git a/apps/board/tests/test_submissions.py b/apps/board/tests/test_submissions.py index 5518258..b7b4ce3 100644 --- a/apps/board/tests/test_submissions.py +++ b/apps/board/tests/test_submissions.py @@ -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 diff --git a/docs/server-setup.md b/docs/server-setup.md index 85d6b68..2f1cbf4 100644 --- a/docs/server-setup.md +++ b/docs/server-setup.md @@ -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 + `