Publishing has never worked: one line, two wrong answers
gitea.py answered a 401 or 403 from the git server by raising
PermissionError("gitea-unauthorised"), with a comment saying the caller would
refresh and retry. That caller was tokens.py, deleted two phases ago when the
members area took over its own logins. Nothing has caught it since, so a
refused token arrived as a 500 on Contenido — Flask's own page, in English,
saying nothing — and, when approving a submission, as "no se encontró la imagen
en el disco", because PermissionError is a subclass of OSError and the approve
path caught OSError to mean a missing file. The page was displaying the
photograph two lines above the message.
Underneath both: a site-admin token cannot write to a repository. Gitea's
scopes are per category and `admin` does not contain `repository`, so the
editor has never been able to commit and nothing written in the members area
has ever reached the site. server-setup.md said the fallback to
GITEA_ADMIN_TOKEN "keeps an existing install working", which was the sentence
that hid it; it now says what that token can and cannot do.
Fixed: 401/403 raises a GiteaError naming the scope to check; approve reads the
picture before the try and catches only FileNotFoundError, so "the image is
missing" is said only when it is; and a 500 handler renders the site's own page
and logs the traceback with the request path.
Then the three wall pieces:
Every name — wall, thread, comment, private message, dashboard, directory —
renders through templates/_person.html, which links to vienalatina.com/<login>
only when that person has published a page. Both failure modes are silent, so
the rule lives in one macro instead of nine templates. A profile also has one
canonical address now: /<name>/ redirects to /<name>, which is what url_for had
been quietly preferring.
One 👍 per member per thread or comment, clicking again takes it back. The
table is shaped like attachments — two nullable parents, a CHECK that exactly
one is set — and uniqueness is two partial indexes, because UNIQUE across a
NULL column would make every comment reaction unique by accident. The `back`
field goes through auth.safe_next (renamed from _safe_next), since a redirect
somebody can type is an open redirect.
Miembros is a directory: a card per person with photo, username, role, the
first line of their bio, somewhere to write from and a link to their page.
Admin controls fold into a per-card Gestionar block. That is also the fix for
the misaligned row in the screenshot — four forms in a column two inches wide
was the cause, and the table is gone. Photos inside the members area are served
by a login-gated route even when the public page is unpublished, and the
profile form now says so.
404 tests pass.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NizVpJ2dwzCbjCrTLCjeHn
This commit is contained in:
parent
5ea6b1ac98
commit
28dd23e444
@ -191,6 +191,11 @@ included. Removing a post is visible to its author, quietly rewriting it is not.
|
||||
The same line runs through moderation: a moderator approves or returns a
|
||||
proposal, and never rewrites it to publish under somebody else's name.
|
||||
|
||||
The wall carries one 👍 per member per post or comment, every name links to that
|
||||
person's page when they have published one, and *Miembros* is a directory of
|
||||
cards rather than an admin table — the controls are there, folded into each card
|
||||
for admins.
|
||||
|
||||
Its SQLite database is the only state on the server that git does not hold.
|
||||
`scripts/backup-board.sh` takes a consistent snapshot nightly — see
|
||||
`docs/server-setup.md` §11.
|
||||
|
||||
@ -10,7 +10,7 @@ from __future__ import annotations
|
||||
import os
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from flask import Flask, render_template
|
||||
from flask import Flask, render_template, request
|
||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||
|
||||
from .db import close_db, init_db
|
||||
@ -173,5 +173,26 @@ def create_app(overrides: dict | None = None) -> Flask:
|
||||
return render_template("error.html", code=413,
|
||||
message="El mensaje es demasiado largo."), 413
|
||||
|
||||
@app.errorhandler(500)
|
||||
def _crashed(error):
|
||||
"""The page an unexpected exception produces.
|
||||
|
||||
Without this Flask prints its own, in English, with no way back into the
|
||||
site — which is what a stray PermissionError from the git client looked
|
||||
like for two phases: a white page reading "Internal Server Error", giving
|
||||
no hint that the cause was a token scope. The traceback goes to the log
|
||||
with the path beside it, and the member gets the site's own page.
|
||||
|
||||
`original_exception` is what Flask hands the handler; logging it here
|
||||
rather than relying on the default keeps the request path in the same
|
||||
line, which is the difference between a searchable log and a pile of
|
||||
tracebacks.
|
||||
"""
|
||||
app.logger.error("Unhandled error at %s: %s", request.path,
|
||||
getattr(error, "original_exception", error), exc_info=True)
|
||||
return render_template(
|
||||
"error.html", code=500,
|
||||
message="Algo falló de nuestro lado. Ya ha quedado anotado."), 500
|
||||
|
||||
init_db(app)
|
||||
return app
|
||||
|
||||
@ -54,13 +54,17 @@ def load_member() -> None:
|
||||
g.member = row
|
||||
|
||||
|
||||
def _safe_next(target: str) -> str:
|
||||
def safe_next(target: str) -> str:
|
||||
"""Only ever inside this app.
|
||||
|
||||
An absolute or protocol-relative URL here would make the login form an open
|
||||
redirect: a crafted link signs somebody in and drops them on a page
|
||||
somebody else controls, with the trust of having just arrived from their
|
||||
own community site.
|
||||
|
||||
Public rather than private now, because the login form is not the only place
|
||||
that sends somebody back where they came from: any form carrying a `back`
|
||||
field has the same hole, and two copies of this rule is one copy too many.
|
||||
"""
|
||||
prefix = current_app.config["URL_PREFIX"] + "/"
|
||||
return target if target.startswith(prefix) else url_for("home.index")
|
||||
@ -117,7 +121,7 @@ def login():
|
||||
passwords.prune_attempts()
|
||||
get_db().execute("UPDATE members SET last_seen_at = datetime('now') WHERE id = ?",
|
||||
(member["id"],))
|
||||
return redirect(_safe_next(target))
|
||||
return redirect(safe_next(target))
|
||||
|
||||
|
||||
def invite_url(token: str) -> str:
|
||||
|
||||
@ -18,7 +18,7 @@ from __future__ import annotations
|
||||
from flask import (Blueprint, abort, current_app, flash, g, redirect,
|
||||
render_template, request, url_for)
|
||||
|
||||
from . import uploads
|
||||
from . import auth, uploads
|
||||
from .db import get_db
|
||||
from .render import excerpt, to_html
|
||||
from .security import admin_required, login_required
|
||||
@ -75,6 +75,36 @@ def _clean(title: str, body: str) -> tuple[str, str] | None:
|
||||
return title, body
|
||||
|
||||
|
||||
# --- reactions ------------------------------------------------------------
|
||||
#
|
||||
# One 👍 per member per thread or comment, and clicking it again takes it back.
|
||||
# Counted in one query per page rather than one per card: a wall of twenty
|
||||
# posts should not be forty round trips to SQLite for a number beside a thumb.
|
||||
|
||||
def _reactions(column: str, ids: list[int]) -> dict[int, dict]:
|
||||
"""{parent id: {"count": n, "mine": bool}} for a whole page at once."""
|
||||
if not ids:
|
||||
return {}
|
||||
marks = ",".join("?" * len(ids))
|
||||
rows = get_db().execute(
|
||||
f"""SELECT {column} AS parent, COUNT(*) AS total,
|
||||
MAX(member_id = ?) AS mine
|
||||
FROM reactions WHERE {column} IN ({marks})
|
||||
GROUP BY {column}""",
|
||||
(g.member["id"], *ids),
|
||||
).fetchall()
|
||||
return {row["parent"]: {"count": row["total"], "mine": bool(row["mine"])}
|
||||
for row in rows}
|
||||
|
||||
|
||||
def reactions_for_threads(ids: list[int]) -> dict[int, dict]:
|
||||
return _reactions("thread_id", ids)
|
||||
|
||||
|
||||
def reactions_for_comments(ids: list[int]) -> dict[int, dict]:
|
||||
return _reactions("comment_id", ids)
|
||||
|
||||
|
||||
def _thread_or_404(thread_id: int):
|
||||
row = get_db().execute(
|
||||
"SELECT * FROM threads WHERE id = ? AND deleted_at IS NULL", (thread_id,)
|
||||
@ -104,6 +134,7 @@ def threads():
|
||||
page = max(1, request.args.get("page", 1, type=int))
|
||||
rows = get_db().execute(
|
||||
"""SELECT t.*, m.display_name AS author,
|
||||
m.gitea_login AS author_login, m.profile_published AS author_published,
|
||||
(SELECT COUNT(*) FROM comments c
|
||||
WHERE c.thread_id = t.id AND c.deleted_at IS NULL) AS replies
|
||||
FROM threads t JOIN members m ON m.id = t.author_id
|
||||
@ -115,8 +146,10 @@ def threads():
|
||||
# One row past the page size answers "is there a next page" without a
|
||||
# second COUNT(*) over the whole table.
|
||||
has_next = len(rows) > PER_PAGE
|
||||
return render_template("threads.html", threads=rows[:PER_PAGE], page=page,
|
||||
has_next=has_next, excerpt=excerpt)
|
||||
shown = rows[:PER_PAGE]
|
||||
return render_template("threads.html", threads=shown, page=page,
|
||||
has_next=has_next, excerpt=excerpt,
|
||||
reactions=reactions_for_threads([t["id"] for t in shown]))
|
||||
|
||||
|
||||
@bp.route("/tema/<int:thread_id>")
|
||||
@ -124,21 +157,27 @@ def threads():
|
||||
def thread(thread_id: int):
|
||||
row = _thread_or_404(thread_id)
|
||||
db = get_db()
|
||||
author = db.execute("SELECT display_name FROM members WHERE id = ?",
|
||||
(row["author_id"],)).fetchone()
|
||||
author = db.execute(
|
||||
"""SELECT display_name, gitea_login, profile_published
|
||||
FROM members WHERE id = ?""",
|
||||
(row["author_id"],)).fetchone()
|
||||
comments = db.execute(
|
||||
"""SELECT c.*, m.display_name AS author
|
||||
"""SELECT c.*, m.display_name AS author,
|
||||
m.gitea_login AS author_login, m.profile_published AS author_published
|
||||
FROM comments c JOIN members m ON m.id = c.author_id
|
||||
WHERE c.thread_id = ? AND c.deleted_at IS NULL
|
||||
ORDER BY c.created_at""",
|
||||
(thread_id,),
|
||||
).fetchall()
|
||||
return render_template("thread.html", thread=row, author=author["display_name"],
|
||||
return render_template("thread.html", thread=row, author=author,
|
||||
comments=comments, body_html=to_html(row["body_md"]),
|
||||
to_html=to_html, may_edit=may_edit, may_delete=may_delete,
|
||||
is_admin=is_admin(),
|
||||
thread_images=uploads.for_threads([thread_id]).get(thread_id, []),
|
||||
comment_images=uploads.for_comments([c["id"] for c in comments]))
|
||||
comment_images=uploads.for_comments([c["id"] for c in comments]),
|
||||
reactions=reactions_for_threads([thread_id]),
|
||||
comment_reactions=reactions_for_comments(
|
||||
[c["id"] for c in comments]))
|
||||
|
||||
|
||||
@bp.route("/nuevo", methods=["GET", "POST"])
|
||||
@ -265,6 +304,52 @@ def delete_comment(comment_id: int):
|
||||
return redirect(url_for("board.thread", thread_id=row["thread_id"]))
|
||||
|
||||
|
||||
@bp.route("/reaccion", methods=["POST"])
|
||||
@login_required
|
||||
def react():
|
||||
"""Add my reaction, or take it back if it is already there.
|
||||
|
||||
One route for both parents, because the form posts which kind it is and the
|
||||
alternative is two routes that differ by a column name. `kind` is checked
|
||||
against a fixed pair before it reaches the statement, so nothing a member
|
||||
types gets near the SQL.
|
||||
|
||||
The parent is checked for real: a thread that has been deleted, or an id
|
||||
that never existed, is a 404 rather than a row pointing at nothing.
|
||||
"""
|
||||
kind = request.form.get("kind")
|
||||
if kind not in ("thread", "comment"):
|
||||
abort(400, "Campo desconocido.")
|
||||
target_id = request.form.get("id", type=int)
|
||||
if not target_id:
|
||||
abort(400, "Falta el identificador.")
|
||||
|
||||
if kind == "thread":
|
||||
row = _thread_or_404(target_id)
|
||||
column, anchor = "thread_id", url_for("board.thread", thread_id=row["id"])
|
||||
else:
|
||||
row = _comment_or_404(target_id)
|
||||
column = "comment_id"
|
||||
anchor = url_for("board.thread", thread_id=row["thread_id"]) + f"#c{row['id']}"
|
||||
|
||||
db = get_db()
|
||||
existing = db.execute(
|
||||
f"SELECT id FROM reactions WHERE {column} = ? AND member_id = ?",
|
||||
(target_id, g.member["id"]),
|
||||
).fetchone()
|
||||
if existing:
|
||||
db.execute("DELETE FROM reactions WHERE id = ?", (existing["id"],))
|
||||
else:
|
||||
db.execute(f"INSERT INTO reactions ({column}, member_id) VALUES (?, ?)",
|
||||
(target_id, g.member["id"]))
|
||||
|
||||
# Back where they were, including which comment: a reaction should not move
|
||||
# the page, and there is no JavaScript here to stop the form navigating.
|
||||
# Through safe_next, because a `back` field taken at face value is an open
|
||||
# redirect — the same hole the login form's `next` is checked for.
|
||||
return redirect(auth.safe_next(request.form.get("back") or anchor))
|
||||
|
||||
|
||||
@bp.route("/tema/<int:thread_id>/estado", methods=["POST"])
|
||||
@admin_required
|
||||
def set_state(thread_id: int):
|
||||
|
||||
@ -22,7 +22,7 @@ from __future__ import annotations
|
||||
import base64
|
||||
import secrets
|
||||
import string
|
||||
from urllib.parse import quote, urlencode
|
||||
from urllib.parse import quote
|
||||
|
||||
import requests
|
||||
from flask import current_app
|
||||
@ -59,8 +59,6 @@ def _branch() -> str:
|
||||
return current_app.config["CONTENT_BRANCH"]
|
||||
|
||||
|
||||
# --- sign-in -------------------------------------------------------------
|
||||
|
||||
# --- account creation (site-admin token) ---------------------------------
|
||||
|
||||
def admin_configured() -> bool:
|
||||
@ -204,6 +202,22 @@ def _identity(member) -> dict:
|
||||
|
||||
|
||||
def _content_request(method: str, url: str, token: str, **kwargs):
|
||||
"""Every content call goes through here, and every refusal comes back as a
|
||||
GiteaError the caller already knows how to show.
|
||||
|
||||
This used to raise `PermissionError("gitea-unauthorised")` on a 401 or 403,
|
||||
with a comment saying the caller would refresh the token and retry. That
|
||||
caller was `tokens.py`, which refreshed OAuth tokens and was deleted when
|
||||
the members area took over its own logins — so for two phases the refusal
|
||||
was an exception nothing caught. It escaped `content.index` as a 500, and
|
||||
`submissions.approve` mistook it for a missing file, because PermissionError
|
||||
is a subclass of OSError. One line, two wrong answers, and a whole feature
|
||||
that had never worked: the token in .env was a site-admin token, and Gitea's
|
||||
scopes are per category, so `admin` grants nothing over a repository.
|
||||
|
||||
Hence the message: the thing to check is the token's scope, and it should
|
||||
say so on the screen rather than in a traceback nobody reads.
|
||||
"""
|
||||
response = requests.request(
|
||||
method, url,
|
||||
headers={"Authorization": f"Bearer {token}"},
|
||||
@ -211,7 +225,11 @@ def _content_request(method: str, url: str, token: str, **kwargs):
|
||||
**kwargs,
|
||||
)
|
||||
if response.status_code in (401, 403):
|
||||
raise PermissionError("gitea-unauthorised") # caller refreshes and retries
|
||||
raise GiteaError(
|
||||
"El servidor de git rechazó el token del editor. Comprueba que "
|
||||
"CONTENT_TOKEN existe y tiene permiso de escritura sobre el "
|
||||
"repositorio (repository: Read and Write), no sólo de administración."
|
||||
)
|
||||
return response
|
||||
|
||||
|
||||
|
||||
@ -31,6 +31,7 @@ def index():
|
||||
db = get_db()
|
||||
threads = db.execute(
|
||||
"""SELECT t.id, t.title, t.body_md, t.created_at, m.display_name AS author,
|
||||
m.gitea_login AS author_login, m.profile_published AS author_published,
|
||||
(SELECT COUNT(*) FROM comments c
|
||||
WHERE c.thread_id = t.id AND c.deleted_at IS NULL) AS replies
|
||||
FROM threads t JOIN members m ON m.id = t.author_id
|
||||
@ -41,6 +42,8 @@ def index():
|
||||
|
||||
conversations = db.execute(
|
||||
"""SELECT other.id AS other_id, other.display_name AS other_name,
|
||||
other.gitea_login AS other_login,
|
||||
other.profile_published AS other_published,
|
||||
(SELECT COUNT(*) FROM messages msg
|
||||
WHERE msg.conversation_id = c.id AND msg.author_id != mine.member_id
|
||||
AND msg.deleted_at IS NULL
|
||||
@ -69,7 +72,9 @@ def index():
|
||||
queue = []
|
||||
if submissions.may_moderate():
|
||||
queue = db.execute(
|
||||
"""SELECT s.id, s.title, s.created_at, m.display_name AS author
|
||||
"""SELECT s.id, s.title, s.created_at, m.display_name AS author,
|
||||
m.gitea_login AS author_login,
|
||||
m.profile_published AS author_published
|
||||
FROM submissions s JOIN members m ON m.id = s.author_id
|
||||
WHERE s.state = 'pending' AND s.author_id != ?
|
||||
ORDER BY s.created_at LIMIT ?""",
|
||||
|
||||
@ -121,6 +121,10 @@ REMOVED_ON_ERASE = {
|
||||
("messages", "author_id"),
|
||||
("blocks", "blocker_id"),
|
||||
("blocks", "blocked_id"),
|
||||
# A reaction is a fact about a person, not about the post: the thread
|
||||
# survives as "Miembro eliminado", the thumbs-up does not survive as
|
||||
# somebody's thumbs-up.
|
||||
("reactions", "member_id"),
|
||||
# A submission is private writing until a moderator approves it, so it goes
|
||||
# with the rest of the private writing. The remainder of an approved one is
|
||||
# the published post in the site repository, which already carries this
|
||||
@ -179,6 +183,7 @@ def erase_member(db: sqlite3.Connection, member_id: int) -> list[str]:
|
||||
)
|
||||
db.execute("DELETE FROM blocks WHERE blocker_id = ? OR blocked_id = ?",
|
||||
(member_id, member_id))
|
||||
db.execute("DELETE FROM reactions WHERE member_id = ?", (member_id,))
|
||||
orphaned += [row["photo_name"] for row in db.execute(
|
||||
"SELECT photo_name FROM submissions WHERE author_id = ? AND photo_name IS NOT NULL",
|
||||
(member_id,),
|
||||
@ -217,7 +222,9 @@ def _load(member_id: int):
|
||||
@login_required
|
||||
def index():
|
||||
rows = get_db().execute(
|
||||
"""SELECT m.*, c.display_name AS creator
|
||||
"""SELECT m.*, c.display_name AS creator,
|
||||
(SELECT COUNT(*) FROM threads t
|
||||
WHERE t.author_id = m.id AND t.deleted_at IS NULL) AS posts
|
||||
FROM members m
|
||||
LEFT JOIN members c ON c.id = m.created_by
|
||||
WHERE m.role != 'tombstone'
|
||||
|
||||
@ -96,6 +96,8 @@ def inbox():
|
||||
"""SELECT c.id,
|
||||
other.display_name AS other_name,
|
||||
other.id AS other_id,
|
||||
other.gitea_login AS other_login,
|
||||
other.profile_published AS other_published,
|
||||
(SELECT body_md FROM messages
|
||||
WHERE conversation_id = c.id AND deleted_at IS NULL
|
||||
ORDER BY created_at DESC LIMIT 1) AS last_body,
|
||||
@ -201,7 +203,9 @@ def talk(member_id: int):
|
||||
rows = []
|
||||
if conversation_id is not None:
|
||||
rows = db.execute(
|
||||
"""SELECT m.*, a.display_name AS author
|
||||
"""SELECT m.*, a.display_name AS author,
|
||||
a.gitea_login AS author_login,
|
||||
a.profile_published AS author_published
|
||||
FROM messages m JOIN members a ON a.id = m.author_id
|
||||
WHERE m.conversation_id = ? AND m.deleted_at IS NULL
|
||||
ORDER BY m.created_at""",
|
||||
|
||||
@ -92,8 +92,20 @@ def _published(login: str):
|
||||
|
||||
# --- the public page ------------------------------------------------------
|
||||
|
||||
@public_bp.route("/<name>")
|
||||
@public_bp.route("/<name>/")
|
||||
def show_with_slash(name: str):
|
||||
"""One canonical address per profile.
|
||||
|
||||
Both spellings have always worked, but `url_for` picked whichever was
|
||||
registered last, so links inside the members area pointed at `/maria/`
|
||||
while everything written by hand said `/maria`. Two URLs for one page is a
|
||||
small thing until a search engine indexes both. This one sends people to
|
||||
the other and nothing renders here.
|
||||
"""
|
||||
return redirect(url_for("profiles_public.show", name=name), code=301)
|
||||
|
||||
|
||||
@public_bp.route("/<name>")
|
||||
def show(name: str):
|
||||
"""404 for anything that is not a published profile.
|
||||
|
||||
@ -138,6 +150,33 @@ def photo(stored_name: str):
|
||||
return send_from_directory(uploads.directory(), stored_name)
|
||||
|
||||
|
||||
@bp.route("/miembro/foto/<stored_name>")
|
||||
@login_required
|
||||
def member_photo(stored_name: str):
|
||||
"""The same picture, for the people inside.
|
||||
|
||||
`profiles.photo` above serves only photos belonging to a *published* page,
|
||||
which is right for the open internet and wrong for Miembros: somebody who
|
||||
has not published a public page has still chosen a face for the community
|
||||
they joined, and a directory of grey squares is not a directory. So this one
|
||||
is behind the login and asks only that the member is active.
|
||||
|
||||
The profile form says so in as many words, because a picture turning up
|
||||
somewhere its owner did not expect is exactly the surprise a profile form
|
||||
exists to prevent.
|
||||
"""
|
||||
if not uploads.STORED_NAME.match(stored_name):
|
||||
abort(404)
|
||||
row = get_db().execute(
|
||||
"""SELECT 1 FROM members
|
||||
WHERE photo_name = ? AND active = 1 AND role != 'tombstone'""",
|
||||
(stored_name,),
|
||||
).fetchone()
|
||||
if row is None:
|
||||
abort(404)
|
||||
return send_from_directory(uploads.directory(), stored_name)
|
||||
|
||||
|
||||
# --- editing it -----------------------------------------------------------
|
||||
|
||||
@bp.route("/mi-perfil", methods=["GET", "POST"])
|
||||
|
||||
@ -265,3 +265,30 @@ CREATE INDEX IF NOT EXISTS submissions_queue
|
||||
ON submissions(created_at) WHERE state = 'pending';
|
||||
CREATE INDEX IF NOT EXISTS submissions_author
|
||||
ON submissions(author_id, created_at);
|
||||
|
||||
-- A 👍 on a thread or a comment.
|
||||
--
|
||||
-- Shaped like `attachments`: two nullable parents and a CHECK that exactly one
|
||||
-- is set, so a reaction cannot belong to both or to neither, and both parents
|
||||
-- keep real foreign keys.
|
||||
--
|
||||
-- The uniqueness rule — one reaction per member per thing — cannot be a plain
|
||||
-- UNIQUE(member_id, thread_id, comment_id), because SQLite treats NULLs as
|
||||
-- distinct and every comment reaction would have a NULL thread_id, making every
|
||||
-- row unique by accident. Two partial indexes say what is meant instead.
|
||||
--
|
||||
-- There is one kind of reaction and no notifications. A count and a toggle is
|
||||
-- the whole feature: anything more is a second inbox nobody asked for.
|
||||
CREATE TABLE IF NOT EXISTS reactions (
|
||||
id INTEGER PRIMARY KEY,
|
||||
thread_id INTEGER REFERENCES threads(id),
|
||||
comment_id INTEGER REFERENCES comments(id),
|
||||
member_id INTEGER NOT NULL REFERENCES members(id),
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
||||
CHECK ((thread_id IS NOT NULL) + (comment_id IS NOT NULL) = 1)
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS reactions_one_per_thread
|
||||
ON reactions(member_id, thread_id) WHERE thread_id IS NOT NULL;
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS reactions_one_per_comment
|
||||
ON reactions(member_id, comment_id) WHERE comment_id IS NOT NULL;
|
||||
|
||||
@ -336,6 +336,11 @@ input[type="file"] {
|
||||
border: 1px solid var(--border-light);
|
||||
}
|
||||
|
||||
/* A name that leads somewhere. Underlined only on hover, because on a busy
|
||||
wall every name being a permanent link turns the page into a rash. */
|
||||
.who-link { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--border); }
|
||||
.who-link:hover { color: var(--brand-dark); border-bottom-color: var(--brand); }
|
||||
|
||||
/* --- the corner account menu ----------------------------------------- */
|
||||
/*
|
||||
* A <details> element, because the Content-Security-Policy has no
|
||||
@ -433,3 +438,102 @@ input[type="file"] {
|
||||
white-space: nowrap;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
/* --- 👍 ---------------------------------------------------------------- */
|
||||
|
||||
.reaction { margin: 0; }
|
||||
.reaction__button {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
padding: 0.2rem 0.6rem;
|
||||
border: 1px solid var(--border-light);
|
||||
border-radius: 999px;
|
||||
background: var(--surface);
|
||||
color: var(--muted);
|
||||
font-size: 0.85rem;
|
||||
cursor: pointer;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.reaction__button:hover { border-color: var(--brand); color: var(--brand-dark); }
|
||||
/* Mine: filled, so "did I already?" is answered at a glance rather than by
|
||||
counting. */
|
||||
.reaction__button--mine {
|
||||
background: var(--brand-soft);
|
||||
border-color: var(--brand);
|
||||
color: var(--brand-dark);
|
||||
}
|
||||
.reaction__count { font-variant-numeric: tabular-nums; }
|
||||
|
||||
.card__foot { display: flex; align-items: center; gap: 0.75rem; }
|
||||
|
||||
/* --- the member directory --------------------------------------------- */
|
||||
|
||||
.people {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: grid;
|
||||
/* auto-fill with a minimum, so it is three across on a laptop and one on a
|
||||
phone without a media query deciding where the breaks are. */
|
||||
grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
.person-card {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border-light);
|
||||
border-radius: var(--radius-lg);
|
||||
box-shadow: var(--shadow-sm);
|
||||
padding: 1rem;
|
||||
}
|
||||
.person-card--off { opacity: 0.55; }
|
||||
.person-card__head { display: flex; align-items: center; gap: 0.75rem; }
|
||||
.person-card__photo {
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
flex: 0 0 56px;
|
||||
border-radius: 50%;
|
||||
object-fit: cover;
|
||||
border: 1px solid var(--border-light);
|
||||
}
|
||||
.person-card__photo--none {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: var(--brand-soft);
|
||||
color: var(--brand-dark);
|
||||
font-size: 1.4rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
.person-card__who { min-width: 0; } /* so a long name wraps instead of pushing */
|
||||
.person-card__name { margin: 0; font-size: 1.05rem; }
|
||||
.person-card__name .muted { font-weight: 400; }
|
||||
.person-card__who p { margin: 0.15rem 0 0; }
|
||||
.person-card__bio {
|
||||
margin: 0.75rem 0 0;
|
||||
color: var(--muted);
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
.person-card__foot {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.75rem;
|
||||
margin-top: 0.75rem;
|
||||
}
|
||||
.person-card__admin { margin-top: 0.75rem; border-top: 1px solid var(--border-light); padding-top: 0.5rem; }
|
||||
.person-card__admin summary {
|
||||
cursor: pointer;
|
||||
color: var(--subtle);
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
/* The one place the old table went wrong: four forms in a column two inches
|
||||
wide. Here they are one per line, with room for the words. */
|
||||
.person-card__actions {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 0.5rem;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
.person-card__actions form { margin: 0; }
|
||||
.person-card__actions p { margin: 0; }
|
||||
|
||||
@ -70,7 +70,7 @@ def pending_count() -> int:
|
||||
def _load(submission_id: int):
|
||||
row = get_db().execute(
|
||||
"""SELECT s.*, m.display_name AS author, m.email AS author_email,
|
||||
m.gitea_login AS author_login,
|
||||
m.gitea_login AS author_login, m.profile_published AS author_published,
|
||||
r.display_name AS reviewer
|
||||
FROM submissions s
|
||||
JOIN members m ON m.id = s.author_id
|
||||
@ -127,7 +127,9 @@ def index():
|
||||
queue = []
|
||||
if may_moderate():
|
||||
queue = db.execute(
|
||||
"""SELECT s.*, m.display_name AS author
|
||||
"""SELECT s.*, m.display_name AS author,
|
||||
m.gitea_login AS author_login,
|
||||
m.profile_published AS author_published
|
||||
FROM submissions s JOIN members m ON m.id = s.author_id
|
||||
WHERE s.state = 'pending' AND s.author_id != ?
|
||||
ORDER BY s.created_at""",
|
||||
@ -308,19 +310,30 @@ def approve(submission_id: int):
|
||||
"image": "",
|
||||
"manual_translation": False,
|
||||
}
|
||||
# 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
|
||||
# also catches PermissionError and every `requests` failure — so a git
|
||||
# server refusing the token was reported as a missing photograph, on a page
|
||||
# displaying that photograph. An except clause wide enough to catch the
|
||||
# network is wide enough to lie.
|
||||
picture = None
|
||||
if row["photo_name"]:
|
||||
try:
|
||||
picture = (uploads.directory() / row["photo_name"]).read_bytes()
|
||||
except FileNotFoundError:
|
||||
current_app.logger.warning("submission %s: %s is not on disk",
|
||||
submission_id, row["photo_name"])
|
||||
flash("No se encontró la imagen en el disco. Pide al autor que la "
|
||||
"vuelva a subir.", "error")
|
||||
return redirect(url_for("submissions.show", submission_id=submission_id))
|
||||
|
||||
try:
|
||||
if row["photo_name"]:
|
||||
data = (uploads.directory() / row["photo_name"]).read_bytes()
|
||||
fields["image"] = content.commit_picture(data, row["photo_name"], author)
|
||||
if picture is not None:
|
||||
fields["image"] = content.commit_picture(picture, row["photo_name"], author)
|
||||
path = content.publish("post", fields, row["body_md"], author)
|
||||
except gitea.GiteaError as exc:
|
||||
flash(str(exc), "error")
|
||||
return redirect(url_for("submissions.show", submission_id=submission_id))
|
||||
except OSError:
|
||||
current_app.logger.exception("submission %s: picture missing on disk", submission_id)
|
||||
flash("No se encontró la imagen en el disco. Pide al autor que la vuelva a subir.",
|
||||
"error")
|
||||
return redirect(url_for("submissions.show", submission_id=submission_id))
|
||||
|
||||
get_db().execute(
|
||||
"""UPDATE submissions
|
||||
|
||||
13
apps/board/templates/_person.html
Normal file
13
apps/board/templates/_person.html
Normal file
@ -0,0 +1,13 @@
|
||||
{# A member's name, as a link to their page when they have one.
|
||||
|
||||
The rule is in one place because it is easy to get wrong in two directions:
|
||||
a name that never links makes the profiles invisible, and a name that always
|
||||
links sends people to a 404 for everybody who has not published theirs. So
|
||||
every screen calls this, and none of them has to remember. #}
|
||||
{% macro person(name, login=None, published=False) %}
|
||||
{%- if published and login -%}
|
||||
<a class="who-link" href="{{ url_for('profiles_public.show', name=login) }}">{{ name }}</a>
|
||||
{%- else -%}
|
||||
{{ name }}
|
||||
{%- endif -%}
|
||||
{% endmacro %}
|
||||
20
apps/board/templates/_reaction.html
Normal file
20
apps/board/templates/_reaction.html
Normal file
@ -0,0 +1,20 @@
|
||||
{# The 👍 button, for a thread or a comment.
|
||||
|
||||
A form rather than a link, because it changes something and a GET that
|
||||
changes something is a thing a prefetching browser will do on its own. It
|
||||
carries where it was pressed so the page does not jump to the top, and the
|
||||
handler puts that through the same open-redirect check as the login form. #}
|
||||
{% macro reaction(kind, target_id, state, back) %}
|
||||
<form class="reaction" method="post" action="{{ url_for('board.react') }}">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<input type="hidden" name="kind" value="{{ kind }}">
|
||||
<input type="hidden" name="id" value="{{ target_id }}">
|
||||
<input type="hidden" name="back" value="{{ back }}">
|
||||
<button class="reaction__button {{ 'reaction__button--mine' if state and state.mine }}"
|
||||
type="submit"
|
||||
aria-label="{{ 'Quitar mi me gusta' if state and state.mine else 'Me gusta' }}">
|
||||
<span aria-hidden="true">👍</span>
|
||||
{% if state and state.count %}<span class="reaction__count">{{ state.count }}</span>{% endif %}
|
||||
</button>
|
||||
</form>
|
||||
{% endmacro %}
|
||||
@ -1,17 +1,18 @@
|
||||
{% extends "base.html" %}
|
||||
{% from "_person.html" import person %}
|
||||
{% from "_attachments.html" import attachments %}
|
||||
{% block title %}{{ other.display_name }}{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
<div class="feed-head">
|
||||
<h1>{{ other.display_name }}</h1>
|
||||
<h1>{{ person(other.display_name, other.gitea_login, other.profile_published) }}</h1>
|
||||
<a class="linkish" href="{{ url_for('messages.inbox') }}">Volver</a>
|
||||
</div>
|
||||
|
||||
{% for m in messages %}
|
||||
<article class="card card--comment">
|
||||
<div class="card__meta">
|
||||
<span>{{ m.author }}</span> · <time>{{ m.created_at }}</time>
|
||||
<span>{{ person(m.author, m.author_login, m.author_published) }}</span> · <time>{{ m.created_at }}</time>
|
||||
</div>
|
||||
<div class="prose">{{ to_html(m.body_md) }}</div>
|
||||
{{ attachments(images.get(m.id, [])) }}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{% extends "base.html" %}
|
||||
{% from "_person.html" import person %}
|
||||
{% block title %}Inicio{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
@ -18,7 +19,7 @@
|
||||
{% for item in queue %}
|
||||
<p class="panel__row">
|
||||
<a href="{{ url_for('submissions.show', submission_id=item.id) }}">{{ item.title }}</a>
|
||||
<span class="muted small">{{ item.author }} · {{ item.created_at }}</span>
|
||||
<span class="muted small">{{ person(item.author, item.author_login, item.author_published) }} · {{ item.created_at }}</span>
|
||||
</p>
|
||||
{% endfor %}
|
||||
</section>
|
||||
@ -52,7 +53,7 @@
|
||||
{% for t in threads %}
|
||||
<p class="panel__row">
|
||||
<a href="{{ url_for('board.thread', thread_id=t.id) }}">{{ t.title }}</a>
|
||||
<span class="muted small">{{ t.author }} · {{ t.replies }} respuesta{{ '' if t.replies == 1 else 's' }}</span>
|
||||
<span class="muted small">{{ person(t.author, t.author_login, t.author_published) }} · {{ t.replies }} respuesta{{ '' if t.replies == 1 else 's' }}</span>
|
||||
</p>
|
||||
{% endfor %}
|
||||
</section>
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{% extends "base.html" %}
|
||||
{% from "_person.html" import person %}
|
||||
{% block title %}Miembros{% endblock %}
|
||||
|
||||
{% set me = g.member %}
|
||||
@ -13,86 +14,127 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr><th>Nombre</th><th>Usuario</th><th>Rol</th><th>Estado</th>{% if is_admin %}<th></th>{% endif %}</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{# People, not rows. This was a five-column table whose last column held four
|
||||
forms, which is how the actions ended up wrapping on top of each other in a
|
||||
column two inches wide. A card has room for a face and somewhere to write
|
||||
from, and the admin controls fold away into a <details> so that the page is
|
||||
a directory first and a control panel second. #}
|
||||
<ul class="people">
|
||||
{% for m in members %}
|
||||
<tr class="{{ '' if m.active else 'row--off' }}">
|
||||
<td>{{ m.display_name }}{% if m.id == me.id %} <span class="muted small">(tú)</span>{% endif %}</td>
|
||||
<td class="mono">{{ m.gitea_login }}</td>
|
||||
<td>{{ labels[m.role] }}</td>
|
||||
<td>{{ 'Activo' if m.active else 'Suspendido' }}</td>
|
||||
{% if is_admin %}
|
||||
<td class="actions actions--row">
|
||||
{# The owner is untouchable, so the row shows nothing rather than
|
||||
buttons that would only produce a 403. #}
|
||||
{% if m.role != 'owner' %}
|
||||
<form method="post" action="{{ url_for('members.set_active', member_id=m.id) }}">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<input type="hidden" name="active" value="{{ 0 if m.active else 1 }}">
|
||||
<button class="linkish" type="submit">{{ 'Suspender' if m.active else 'Reactivar' }}</button>
|
||||
</form>
|
||||
|
||||
{# Any admin can re-send, not just the owner: the usual reason
|
||||
somebody needs this is that the admin who added them made
|
||||
the account by hand, and waiting for the owner to be
|
||||
around defeats the point. Hidden without an address,
|
||||
because the handler would only refuse. #}
|
||||
{% if m.email and m.active %}
|
||||
<form method="post" action="{{ url_for('members.invite', member_id=m.id) }}"
|
||||
data-confirm="Se enviará un enlace nuevo a {{ m.email }} y el anterior dejará de servir. ¿Seguro?">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<button class="linkish" type="submit">Enviar invitación</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
{# A toggle worked while there were two roles. With three it has to
|
||||
be a choice, and the options are the ones this person may
|
||||
actually grant — the handler checks the same thing. #}
|
||||
{% if is_owner or m.role != 'admin' %}
|
||||
<form class="inline-form" method="post"
|
||||
action="{{ url_for('members.set_role', member_id=m.id) }}">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<label class="sr-only" for="role-{{ m.id }}">Rol de {{ m.display_name }}</label>
|
||||
<select id="role-{{ m.id }}" name="role">
|
||||
<option value="user" {{ 'selected' if m.role == 'user' }}>Miembro</option>
|
||||
<option value="moderator" {{ 'selected' if m.role == 'moderator' }}>Moderador</option>
|
||||
{% if is_owner %}
|
||||
<option value="admin" {{ 'selected' if m.role == 'admin' }}>Administrador</option>
|
||||
{% endif %}
|
||||
</select>
|
||||
<button class="linkish" type="submit">Cambiar rol</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
{% if is_owner %}
|
||||
{% if m.role == 'admin' and m.active %}
|
||||
<form method="post" action="{{ url_for('members.transfer', member_id=m.id) }}"
|
||||
data-confirm="Vas a dejar de ser el responsable y {{ m.display_name }} pasará a serlo. ¿Seguro?">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<button class="linkish" type="submit">Transferir titularidad</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
<form method="post" action="{{ url_for('members.erase', member_id=m.id) }}"
|
||||
data-confirm="Se borrarán sus datos personales. Sus mensajes quedarán como «Miembro eliminado». ¿Seguro?">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<button class="linkish linkish--danger" type="submit">Eliminar</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</td>
|
||||
<li class="person-card {{ '' if m.active else 'person-card--off' }}">
|
||||
<div class="person-card__head">
|
||||
{% if m.photo_name %}
|
||||
<img class="person-card__photo"
|
||||
src="{{ url_for('profiles.member_photo', stored_name=m.photo_name) }}"
|
||||
alt="" loading="lazy">
|
||||
{% else %}
|
||||
{# Their initial rather than a silhouette: a placeholder that is at
|
||||
least theirs. #}
|
||||
<span class="person-card__photo person-card__photo--none" aria-hidden="true">
|
||||
{{ m.display_name[:1]|upper }}
|
||||
</span>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="person-card__who">
|
||||
<h2 class="person-card__name">
|
||||
{{ person(m.display_name, m.gitea_login, m.profile_published) }}
|
||||
{% if m.id == me.id %}<span class="muted small">(tú)</span>{% endif %}
|
||||
</h2>
|
||||
{# The username is shown to everyone: it is not a secret, it is
|
||||
their address — vienalatina.com/<usuario> — and somebody
|
||||
looking for a person's page needs to know how it is spelled.
|
||||
The email stays inside the admin block. #}
|
||||
<p class="muted small">
|
||||
<span class="mono">{{ m.gitea_login }}</span> · {{ labels[m.role] }}
|
||||
{% if not m.active %} · Suspendido{% endif %}
|
||||
{% if m.posts %} · {{ m.posts }} en el muro{% endif %}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if m.bio %}<p class="person-card__bio">{{ m.bio.split('\n')[0][:160] }}</p>{% endif %}
|
||||
|
||||
<div class="person-card__foot">
|
||||
{% if m.id != me.id and m.active %}
|
||||
<a class="linkish" href="{{ url_for('messages.talk', member_id=m.id) }}">Escribir</a>
|
||||
{% endif %}
|
||||
{% if m.profile_published %}
|
||||
<a class="linkish" href="{{ url_for('profiles_public.show', name=m.gitea_login) }}">Su página</a>
|
||||
{% elif m.id == me.id %}
|
||||
<a class="linkish" href="{{ url_for('profiles.edit') }}">Editar mi perfil</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if is_admin and m.role != 'owner' %}
|
||||
{# A <details>, not a script: the CSP has no 'unsafe-inline'. Closed by
|
||||
default, so the directory reads as a directory. #}
|
||||
<details class="person-card__admin">
|
||||
<summary>Gestionar</summary>
|
||||
<div class="person-card__actions">
|
||||
<form method="post" action="{{ url_for('members.set_active', member_id=m.id) }}">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<input type="hidden" name="active" value="{{ 0 if m.active else 1 }}">
|
||||
<button class="linkish" type="submit">{{ 'Suspender' if m.active else 'Reactivar' }}</button>
|
||||
</form>
|
||||
|
||||
{# Any admin can re-send, not just the owner: the usual reason
|
||||
somebody needs this is that the admin who added them made the
|
||||
account by hand, and waiting for the owner defeats the point.
|
||||
Hidden without an address, because the handler would refuse. #}
|
||||
{% if m.email and m.active %}
|
||||
<form method="post" action="{{ url_for('members.invite', member_id=m.id) }}"
|
||||
data-confirm="Se enviará un enlace nuevo a {{ m.email }} y el anterior dejará de servir. ¿Seguro?">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<button class="linkish" type="submit">Enviar invitación</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
{% if is_owner or m.role != 'admin' %}
|
||||
<form class="inline-form" method="post"
|
||||
action="{{ url_for('members.set_role', member_id=m.id) }}">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<label class="sr-only" for="role-{{ m.id }}">Rol de {{ m.display_name }}</label>
|
||||
<select id="role-{{ m.id }}" name="role">
|
||||
<option value="user" {{ 'selected' if m.role == 'user' }}>Miembro</option>
|
||||
<option value="moderator" {{ 'selected' if m.role == 'moderator' }}>Moderador</option>
|
||||
{% if is_owner %}
|
||||
<option value="admin" {{ 'selected' if m.role == 'admin' }}>Administrador</option>
|
||||
{% endif %}
|
||||
</select>
|
||||
<button class="linkish" type="submit">Cambiar rol</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
{% if is_owner %}
|
||||
{% if m.role == 'admin' and m.active %}
|
||||
<form method="post" action="{{ url_for('members.transfer', member_id=m.id) }}"
|
||||
data-confirm="Vas a dejar de ser el responsable y {{ m.display_name }} pasará a serlo. ¿Seguro?">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<button class="linkish" type="submit">Transferir titularidad</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
<form method="post" action="{{ url_for('members.erase', member_id=m.id) }}"
|
||||
data-confirm="Se borrarán sus datos personales. Sus mensajes quedarán como «Miembro eliminado». ¿Seguro?">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<button class="linkish linkish--danger" type="submit">Eliminar</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
{% if m.email %}<p class="muted small">{{ m.email }}</p>{% endif %}
|
||||
</div>
|
||||
</details>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
{% if is_admin %}
|
||||
<p class="muted small">
|
||||
Hay un solo responsable. El responsable da de alta administradores; los
|
||||
administradores dan de alta usuarios. Nadie puede suspender ni degradar al
|
||||
responsable: para dejar el cargo hay que transferirlo a un administrador.
|
||||
administradores dan de alta miembros y moderadores. Nadie puede suspender ni
|
||||
degradar al responsable: para dejar el cargo hay que transferirlo a un
|
||||
administrador.
|
||||
</p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
@ -35,6 +35,11 @@
|
||||
{% if g.member.photo_name %}
|
||||
<p class="muted small">Ya tienes una. Subir otra la reemplaza.</p>
|
||||
{% endif %}
|
||||
<p class="muted small">
|
||||
Tu foto aparece en <a href="{{ url_for('members.index') }}">Miembros</a>,
|
||||
que sólo ven las personas que han entrado. Fuera del sitio sólo se ve si
|
||||
publicas tu página, abajo.
|
||||
</p>
|
||||
|
||||
<label class="check">
|
||||
<input type="checkbox" name="published" {{ 'checked' if g.member.profile_published }}>
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{% extends "base.html" %}
|
||||
{% from "_person.html" import person %}
|
||||
{% block title %}{{ item.title }}{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
@ -10,7 +11,7 @@
|
||||
<article class="card">
|
||||
<div class="card__meta">
|
||||
<span class="tag tag--{{ item.state }}">{{ labels[item.state] }}</span>
|
||||
<span>{{ item.author }}</span> · <time>{{ item.created_at }}</time>
|
||||
<span>{{ person(item.author, item.author_login, item.author_published) }}</span> · <time>{{ item.created_at }}</time>
|
||||
{% if item.categories %} · <span>{{ item.categories }}</span>{% endif %}
|
||||
</div>
|
||||
{% if item.description %}<p class="muted">{{ item.description }}</p>{% endif %}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{% extends "base.html" %}
|
||||
{% from "_person.html" import person %}
|
||||
{% block title %}Publicaciones{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
@ -30,7 +31,7 @@
|
||||
{% for item in queue %}
|
||||
<article class="card">
|
||||
<div class="card__meta">
|
||||
<span>{{ item.author }}</span> · <time>{{ item.created_at }}</time>
|
||||
<span>{{ person(item.author, item.author_login, item.author_published) }}</span> · <time>{{ item.created_at }}</time>
|
||||
</div>
|
||||
<h3 class="card__title">
|
||||
<a href="{{ url_for('submissions.show', submission_id=item.id) }}">{{ item.title }}</a>
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
{% extends "base.html" %}
|
||||
{% from "_person.html" import person %}
|
||||
{% from "_reaction.html" import reaction %}
|
||||
{% from "_attachments.html" import attachments %}
|
||||
{% block title %}{{ thread.title }}{% endblock %}
|
||||
|
||||
@ -7,7 +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 %}
|
||||
<span>{{ author }}</span> · <time>{{ thread.created_at }}</time>
|
||||
<span>{{ person(author.display_name, author.gitea_login, author.profile_published) }}</span> · <time>{{ thread.created_at }}</time>
|
||||
{% if thread.edited_at %}<span class="muted small">(editado)</span>{% endif %}
|
||||
</div>
|
||||
<h1 class="card__title">{{ thread.title }}</h1>
|
||||
@ -15,6 +17,8 @@
|
||||
{{ attachments(thread_images) }}
|
||||
|
||||
<div class="actions">
|
||||
{{ reaction('thread', thread.id, reactions.get(thread.id),
|
||||
url_for('board.thread', thread_id=thread.id)) }}
|
||||
{% if may_edit(thread) %}
|
||||
<a class="linkish" href="{{ url_for('board.edit_thread', thread_id=thread.id) }}">Editar</a>
|
||||
{% endif %}
|
||||
@ -45,14 +49,16 @@
|
||||
<h2 class="section-head">{{ comments|length }} respuesta{{ '' if comments|length == 1 else 's' }}</h2>
|
||||
|
||||
{% for c in comments %}
|
||||
<article class="card card--comment">
|
||||
<article class="card card--comment" id="c{{ c.id }}">
|
||||
<div class="card__meta">
|
||||
<span>{{ c.author }}</span> · <time>{{ c.created_at }}</time>
|
||||
<span>{{ person(c.author, c.author_login, c.author_published) }}</span> · <time>{{ c.created_at }}</time>
|
||||
{% if c.edited_at %}<span class="muted small">(editado)</span>{% endif %}
|
||||
</div>
|
||||
<div class="prose">{{ to_html(c.body_md) }}</div>
|
||||
{{ attachments(comment_images.get(c.id, [])) }}
|
||||
<div class="actions">
|
||||
{{ reaction('comment', c.id, comment_reactions.get(c.id),
|
||||
url_for('board.thread', thread_id=thread.id) ~ '#c' ~ c.id) }}
|
||||
{% if may_edit(c) %}
|
||||
<a class="linkish" href="{{ url_for('board.edit_comment', comment_id=c.id) }}">Editar</a>
|
||||
{% endif %}
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
{% extends "base.html" %}
|
||||
{% from "_person.html" import person %}
|
||||
{% from "_reaction.html" import reaction %}
|
||||
{% block title %}Muro{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
@ -18,13 +20,16 @@
|
||||
<div class="card__meta">
|
||||
{% if t.pinned %}<span class="tag">Fijado</span>{% endif %}
|
||||
{% if t.locked %}<span class="tag tag--quiet">Cerrado</span>{% endif %}
|
||||
<span>{{ t.author }}</span> · <time>{{ t.created_at }}</time>
|
||||
<span>{{ person(t.author, t.author_login, t.author_published) }}</span> · <time>{{ t.created_at }}</time>
|
||||
</div>
|
||||
<h2 class="card__title">
|
||||
<a href="{{ url_for('board.thread', thread_id=t.id) }}">{{ t.title }}</a>
|
||||
</h2>
|
||||
<p class="card__excerpt">{{ excerpt(t.body_md) }}</p>
|
||||
<p class="card__foot">{{ t.replies }} respuesta{{ '' if t.replies == 1 else 's' }}</p>
|
||||
<div class="card__foot">
|
||||
{{ reaction('thread', t.id, reactions.get(t.id), url_for('board.threads', page=page)) }}
|
||||
<span>{{ t.replies }} respuesta{{ '' if t.replies == 1 else 's' }}</span>
|
||||
</div>
|
||||
</article>
|
||||
{% endfor %}
|
||||
|
||||
|
||||
@ -356,3 +356,76 @@ def test_the_tabs_only_offer_what_this_member_may_open(repo, client, make_member
|
||||
|
||||
sign_in(make_member("admina", role="admin"))
|
||||
assert "Páginas" in client.get("/comunidad/contenido").get_data(as_text=True)
|
||||
|
||||
|
||||
# --- when the git server refuses the token -------------------------------
|
||||
#
|
||||
# This is the shape of a real outage, and it went undiagnosed for two phases.
|
||||
# `_content_request` answered 401/403 with PermissionError, for a caller
|
||||
# (tokens.py) that had been deleted — so the editor 500ed and approving a
|
||||
# submission blamed a missing photograph. Both are asserted here, from the
|
||||
# outside, because both were invisible from the inside.
|
||||
|
||||
class RefusingRepo:
|
||||
"""Gitea with a token that has no repository scope: 403 to everything."""
|
||||
|
||||
class Response:
|
||||
status_code = 403
|
||||
|
||||
@staticmethod
|
||||
def json():
|
||||
return {}
|
||||
|
||||
def request(self, *args, **kwargs):
|
||||
return self.Response()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def refused(monkeypatch):
|
||||
monkeypatch.setattr(gitea, "requests", RefusingRepo())
|
||||
|
||||
|
||||
def test_the_editor_says_what_is_wrong_instead_of_500ing(
|
||||
refused, client, make_member, sign_in):
|
||||
sign_in(make_member("admina", role="admin"))
|
||||
|
||||
for path in ("/comunidad/contenido", "/comunidad/contenido/page"):
|
||||
response = client.get(path)
|
||||
assert response.status_code == 200, path
|
||||
body = response.get_data(as_text=True)
|
||||
assert "CONTENT_TOKEN" in body and "repository" in body, path
|
||||
|
||||
|
||||
def test_a_refused_write_does_not_escape_as_a_permission_error(
|
||||
refused, client, post, make_member, sign_in):
|
||||
"""PermissionError is an OSError, which is how it ended up being reported as
|
||||
a missing file somewhere else entirely. It must not leave gitea.py."""
|
||||
sign_in(make_member("admina", role="admin"))
|
||||
|
||||
response = post("/comunidad/contenido/post/nuevo",
|
||||
{"title": "Aviso", "body": "Texto.", "date": "2026-09-25"})
|
||||
|
||||
assert response.status_code == 400 # back to the form, not a 500
|
||||
assert "rechazó el token" in response.get_data(as_text=True)
|
||||
|
||||
|
||||
def test_an_unexpected_error_renders_the_site_is_own_page(app, client, make_member,
|
||||
sign_in, monkeypatch):
|
||||
"""Flask's default 500 page is in English, has no way back, and says nothing.
|
||||
Ours says something and is logged with the path.
|
||||
|
||||
PROPAGATE_EXCEPTIONS off on purpose: the fixture sets TESTING, which re-raises
|
||||
instead of running the handler, and the handler is the subject here."""
|
||||
app.config["PROPAGATE_EXCEPTIONS"] = False
|
||||
sign_in(make_member("maria"))
|
||||
|
||||
def explode():
|
||||
raise RuntimeError("something nobody anticipated")
|
||||
monkeypatch.setattr("apps.board.board.get_db", explode)
|
||||
|
||||
response = client.get("/comunidad/muro")
|
||||
|
||||
assert response.status_code == 500
|
||||
body = response.get_data(as_text=True)
|
||||
assert "Algo falló de nuestro lado" in body
|
||||
assert "Viena Latina" in body # the site's chrome, not Flask's
|
||||
|
||||
@ -6,7 +6,6 @@ import sqlite3
|
||||
|
||||
import pytest
|
||||
|
||||
from apps.board import gitea
|
||||
from apps.board.members import may_create, may_manage
|
||||
|
||||
|
||||
@ -352,3 +351,82 @@ def test_erasing_a_member_lets_the_name_be_used_again(
|
||||
|
||||
assert db.execute(
|
||||
"SELECT 1 FROM members WHERE gitea_login = 'salvador'").fetchone() is not None
|
||||
|
||||
|
||||
# --- the directory --------------------------------------------------------
|
||||
#
|
||||
# Miembros used to be a five-column admin table whose last column held four
|
||||
# forms, wrapping on top of each other. It is a directory now: everybody sees
|
||||
# the people, admins open a per-card block for the controls. Both halves are
|
||||
# asserted, because "the table is gone" is only an improvement if the controls
|
||||
# came with it.
|
||||
|
||||
def test_everybody_sees_the_people(client, db, make_member, sign_in):
|
||||
maria = make_member("maria")
|
||||
db.execute("UPDATE members SET bio = ? WHERE id = ?",
|
||||
("Vivo en Ottakring.\nSegunda línea.", maria))
|
||||
sign_in(make_member("otra"))
|
||||
|
||||
body = client.get("/comunidad/miembros").get_data(as_text=True)
|
||||
|
||||
assert "Maria" in body and "maria" in body
|
||||
assert "Vivo en Ottakring." in body
|
||||
assert "Segunda línea." not in body # the first line only, as a summary
|
||||
assert f'/comunidad/privados/con/{maria}' in body # somewhere to write from
|
||||
|
||||
|
||||
def test_a_plain_member_sees_no_controls_and_no_addresses(client, make_member, sign_in):
|
||||
make_member("maria")
|
||||
sign_in(make_member("otra"))
|
||||
|
||||
body = client.get("/comunidad/miembros").get_data(as_text=True)
|
||||
|
||||
for control in ("Gestionar", "Suspender", "Cambiar rol", "Eliminar",
|
||||
"Enviar invitación", "maria@example.com"):
|
||||
assert control not in body, control
|
||||
|
||||
|
||||
def test_an_admin_keeps_every_control(client, make_member, sign_in):
|
||||
make_member("maria")
|
||||
sign_in(make_member("admina", role="admin"))
|
||||
|
||||
body = client.get("/comunidad/miembros").get_data(as_text=True)
|
||||
|
||||
for control in ("Gestionar", "Suspender", "Cambiar rol", "Enviar invitación",
|
||||
"maria@example.com"):
|
||||
assert control in body, control
|
||||
assert "Eliminar" not in body # erasure is the owner's alone
|
||||
|
||||
|
||||
def test_a_photo_shows_inside_even_when_the_page_is_not_published(
|
||||
app, client, db, make_member, sign_in):
|
||||
"""profiles.photo serves only published pages, which is right for the open
|
||||
internet and wrong for a directory behind the login."""
|
||||
from apps.board import uploads
|
||||
maria = make_member("maria")
|
||||
stored = "foto-abcdefabcdef.png"
|
||||
db.execute("UPDATE members SET photo_name = ?, profile_published = 0 WHERE id = ?",
|
||||
(stored, maria))
|
||||
with app.app_context():
|
||||
uploads.directory().joinpath(stored).write_bytes(b"\x89PNG\r\n\x1a\n" + b"\0" * 32)
|
||||
|
||||
sign_in(make_member("otra"))
|
||||
|
||||
assert stored in client.get("/comunidad/miembros").get_data(as_text=True)
|
||||
assert client.get(f"/comunidad/miembro/foto/{stored}").status_code == 200
|
||||
# …and it is still not public, which is the whole distinction.
|
||||
assert client.get(f"/comunidad/foto/{stored}").status_code == 404
|
||||
|
||||
|
||||
def test_the_members_area_photo_needs_a_session(app, client, db, make_member):
|
||||
from apps.board import uploads
|
||||
maria = make_member("maria")
|
||||
stored = "foto-abcdefabcdef.png"
|
||||
db.execute("UPDATE members SET photo_name = ? WHERE id = ?", (stored, maria))
|
||||
with app.app_context():
|
||||
uploads.directory().joinpath(stored).write_bytes(b"\x89PNG\r\n\x1a\n")
|
||||
|
||||
response = client.get(f"/comunidad/miembro/foto/{stored}")
|
||||
|
||||
assert response.status_code == 302
|
||||
assert "/login" in response.headers["Location"]
|
||||
|
||||
@ -215,3 +215,47 @@ def test_the_form_says_what_publishing_means(client, make_member, sign_in):
|
||||
body = client.get("/comunidad/mi-perfil").get_data(as_text=True)
|
||||
assert "cualquiera puede verla" in body
|
||||
assert "buscadores" in body
|
||||
|
||||
|
||||
# --- names as doors -------------------------------------------------------
|
||||
#
|
||||
# A profile nobody can reach from inside the members area is a profile nobody
|
||||
# visits. Every screen renders names through the one macro in
|
||||
# templates/_person.html, which links only when there is a page to link to —
|
||||
# the rule is in one place because both failures are silent: never linking
|
||||
# hides the profiles, always linking sends people to a 404.
|
||||
|
||||
def test_a_name_on_the_wall_links_to_a_published_page(client, post, published, sign_in):
|
||||
author = published("maria")
|
||||
sign_in(author)
|
||||
post("/comunidad/nuevo", {"title": "Hola", "body": "Qué tal"})
|
||||
|
||||
for url in ("/comunidad/muro", "/comunidad/tema/1", "/comunidad/"):
|
||||
assert 'href="/maria"' in client.get(url).get_data(as_text=True), url
|
||||
|
||||
|
||||
def test_a_name_without_a_page_is_not_a_link(client, post, published, sign_in):
|
||||
author = published("maria", profile_published=0)
|
||||
sign_in(author)
|
||||
post("/comunidad/nuevo", {"title": "Hola", "body": "Qué tal"})
|
||||
|
||||
for url in ("/comunidad/muro", "/comunidad/tema/1"):
|
||||
body = client.get(url).get_data(as_text=True)
|
||||
assert 'href="/maria"' not in body, url
|
||||
assert "Maria" in body, url # the name is still there
|
||||
|
||||
|
||||
def test_a_comment_and_a_private_message_link_too(client, post, published,
|
||||
make_member, sign_in):
|
||||
maria = published("maria")
|
||||
jose = make_member("jose")
|
||||
sign_in(jose)
|
||||
post("/comunidad/nuevo", {"title": "Hola", "body": "Qué tal"})
|
||||
sign_in(maria)
|
||||
post("/comunidad/tema/1/comentar", {"body": "Yo también"})
|
||||
post("/comunidad/privados/con/%d" % jose, {"body": "Hola José"})
|
||||
|
||||
sign_in(jose)
|
||||
assert 'href="/maria"' in client.get("/comunidad/tema/1").get_data(as_text=True)
|
||||
assert 'href="/maria"' in client.get(
|
||||
f"/comunidad/privados/con/{maria}").get_data(as_text=True)
|
||||
|
||||
150
apps/board/tests/test_reactions.py
Normal file
150
apps/board/tests/test_reactions.py
Normal file
@ -0,0 +1,150 @@
|
||||
"""One 👍 per member per thing, and clicking it again takes it back.
|
||||
|
||||
The whole feature is a count and a toggle. What is worth testing is not that a
|
||||
row appears — it is that a member cannot react twice (the database says so, not
|
||||
the handler), that the button goes back where it was pressed without becoming an
|
||||
open redirect, and that reacting to something that has been deleted is a 404
|
||||
rather than a row pointing at nothing.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlite3
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def react(post, kind, target_id, back=None):
|
||||
data = {"kind": kind, "id": target_id}
|
||||
if back is not None:
|
||||
data["back"] = back
|
||||
return post("/comunidad/reaccion", data)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def thread(post, make_member, sign_in):
|
||||
"""A thread by José, for somebody else to react to."""
|
||||
jose = make_member("jose")
|
||||
sign_in(jose)
|
||||
post("/comunidad/nuevo", {"title": "Hola", "body": "Qué tal"})
|
||||
return 1
|
||||
|
||||
|
||||
def test_reacting_adds_one_and_reacting_again_takes_it_back(
|
||||
db, post, thread, make_member, sign_in):
|
||||
sign_in(make_member("maria"))
|
||||
|
||||
react(post, "thread", thread)
|
||||
assert db.execute("SELECT COUNT(*) AS n FROM reactions").fetchone()["n"] == 1
|
||||
|
||||
react(post, "thread", thread)
|
||||
assert db.execute("SELECT COUNT(*) AS n FROM reactions").fetchone()["n"] == 0
|
||||
|
||||
|
||||
def test_two_members_each_get_one(db, post, thread, make_member, sign_in):
|
||||
for name in ("maria", "luisa"):
|
||||
sign_in(make_member(name))
|
||||
react(post, "thread", thread)
|
||||
|
||||
assert db.execute("SELECT COUNT(*) AS n FROM reactions").fetchone()["n"] == 2
|
||||
|
||||
|
||||
def test_the_database_refuses_a_second_one(db, thread, make_member):
|
||||
"""A partial unique index rather than a check in the handler, because the
|
||||
handler is one bug away from inserting twice and the index is not.
|
||||
|
||||
UNIQUE(member_id, thread_id) on its own would not do it: SQLite treats NULLs
|
||||
as distinct, so every comment reaction — all with a NULL thread_id — would
|
||||
be unique by accident."""
|
||||
maria = make_member("maria")
|
||||
db.execute("INSERT INTO reactions (thread_id, member_id) VALUES (?, ?)", (thread, maria))
|
||||
|
||||
with pytest.raises(sqlite3.IntegrityError):
|
||||
db.execute("INSERT INTO reactions (thread_id, member_id) VALUES (?, ?)",
|
||||
(thread, maria))
|
||||
|
||||
|
||||
def test_a_reaction_belongs_to_exactly_one_thing(db, thread, make_member):
|
||||
maria = make_member("maria")
|
||||
for columns, values in (("", ""), ("thread_id, comment_id", f"{thread}, 1")):
|
||||
with pytest.raises(sqlite3.IntegrityError):
|
||||
db.execute(
|
||||
f"INSERT INTO reactions ({columns + ', ' if columns else ''}member_id) "
|
||||
f"VALUES ({values + ', ' if values else ''}{maria})")
|
||||
|
||||
|
||||
def test_comments_can_be_reacted_to_as_well(db, post, thread, make_member, sign_in):
|
||||
sign_in(make_member("maria"))
|
||||
post(f"/comunidad/tema/{thread}/comentar", {"body": "Yo también"})
|
||||
|
||||
react(post, "comment", 1)
|
||||
|
||||
row = db.execute("SELECT thread_id, comment_id FROM reactions").fetchone()
|
||||
assert (row["thread_id"], row["comment_id"]) == (None, 1)
|
||||
|
||||
|
||||
def test_the_count_and_my_own_mark_show_on_the_page(client, post, thread,
|
||||
make_member, sign_in):
|
||||
sign_in(make_member("maria"))
|
||||
react(post, "thread", thread)
|
||||
|
||||
for url in (f"/comunidad/tema/{thread}", "/comunidad/muro"):
|
||||
body = client.get(url).get_data(as_text=True)
|
||||
assert "reaction__button--mine" in body, url
|
||||
assert ">1<" in body, url
|
||||
|
||||
# Somebody else sees the count but not the filled button.
|
||||
sign_in(make_member("luisa"))
|
||||
body = client.get("/comunidad/muro").get_data(as_text=True)
|
||||
assert "reaction__button--mine" not in body
|
||||
assert ">1<" in body
|
||||
|
||||
|
||||
def test_reacting_to_something_that_is_gone_is_a_404(db, post, thread,
|
||||
owner_id, make_member, sign_in):
|
||||
sign_in(owner_id)
|
||||
post(f"/comunidad/tema/{thread}/eliminar")
|
||||
|
||||
sign_in(make_member("maria"))
|
||||
assert react(post, "thread", thread).status_code == 404
|
||||
assert react(post, "thread", 9999).status_code == 404
|
||||
assert db.execute("SELECT COUNT(*) AS n FROM reactions").fetchone()["n"] == 0
|
||||
|
||||
|
||||
def test_an_unknown_kind_is_refused(post, thread, make_member, sign_in):
|
||||
sign_in(make_member("maria"))
|
||||
assert react(post, "members", thread).status_code == 400
|
||||
|
||||
|
||||
def test_the_back_field_cannot_leave_the_site(post, thread, make_member, sign_in):
|
||||
"""`back` is a redirect somebody can type, which is an open redirect unless
|
||||
it is checked — the same hole the login form's `next` has, so it goes
|
||||
through the same function."""
|
||||
sign_in(make_member("maria"))
|
||||
|
||||
response = react(post, "thread", thread, back="https://ejemplo.invalid/premio")
|
||||
|
||||
assert response.status_code == 302
|
||||
assert "ejemplo.invalid" not in response.headers["Location"]
|
||||
|
||||
|
||||
def test_the_button_comes_back_to_the_comment_it_was_pressed_on(
|
||||
post, thread, make_member, sign_in):
|
||||
sign_in(make_member("maria"))
|
||||
post(f"/comunidad/tema/{thread}/comentar", {"body": "Yo también"})
|
||||
|
||||
response = react(post, "comment", 1, back=f"/comunidad/tema/{thread}#c1")
|
||||
|
||||
assert response.headers["Location"].endswith(f"/comunidad/tema/{thread}#c1")
|
||||
|
||||
|
||||
def test_erasing_a_member_takes_their_reactions(db, post, thread, owner_id,
|
||||
make_member, sign_in):
|
||||
maria = make_member("maria")
|
||||
sign_in(maria)
|
||||
react(post, "thread", thread)
|
||||
|
||||
sign_in(owner_id)
|
||||
post(f"/comunidad/miembros/{maria}/eliminar")
|
||||
|
||||
assert db.execute("SELECT COUNT(*) AS n FROM reactions").fetchone()["n"] == 0
|
||||
@ -397,3 +397,54 @@ def test_erasing_a_reviewer_keeps_the_submission(db, post, owner_id, maria,
|
||||
row = only_submission(db)
|
||||
assert (row["state"], row["reviewed_by"], row["note"]) == (
|
||||
"rejected", None, "Falta el dónde.")
|
||||
|
||||
|
||||
# --- the two ways approving can fail, told apart --------------------------
|
||||
|
||||
def test_a_refused_token_is_not_reported_as_a_missing_picture(
|
||||
app, db, post, maria, luisa, sign_in, monkeypatch):
|
||||
"""The bug in the screenshot. `except OSError` caught PermissionError from
|
||||
the git client and blamed the photograph — on a page that was displaying the
|
||||
photograph. The message has to name the thing that is actually wrong."""
|
||||
sign_in(maria)
|
||||
propose(post, picture=(io.BytesIO(PNG), "feria.png"))
|
||||
row = only_submission(db)
|
||||
|
||||
class Refused:
|
||||
class Response:
|
||||
status_code = 403
|
||||
|
||||
@staticmethod
|
||||
def json():
|
||||
return {}
|
||||
|
||||
def request(self, *args, **kwargs):
|
||||
return self.Response()
|
||||
|
||||
monkeypatch.setattr(gitea, "requests", Refused())
|
||||
sign_in(luisa)
|
||||
response = post(f"/comunidad/publicaciones/{row['id']}/aprobar",
|
||||
follow_redirects=True)
|
||||
|
||||
body = response.get_data(as_text=True)
|
||||
assert "rechazó el token" in body
|
||||
assert "imagen en el disco" not in body
|
||||
assert only_submission(db)["state"] == "pending" # nothing was recorded
|
||||
# And the picture is still there, so a second attempt can succeed.
|
||||
assert (Path(app.config["UPLOAD_DIR"]) / row["photo_name"]).exists()
|
||||
|
||||
|
||||
def test_a_genuinely_missing_picture_still_says_so(
|
||||
app, repo, db, post, maria, luisa, sign_in):
|
||||
sign_in(maria)
|
||||
propose(post, picture=(io.BytesIO(PNG), "feria.png"))
|
||||
row = only_submission(db)
|
||||
(Path(app.config["UPLOAD_DIR"]) / row["photo_name"]).unlink()
|
||||
|
||||
sign_in(luisa)
|
||||
response = post(f"/comunidad/publicaciones/{row['id']}/aprobar",
|
||||
follow_redirects=True)
|
||||
|
||||
assert "imagen en el disco" in response.get_data(as_text=True)
|
||||
assert repo.files == {}
|
||||
assert only_submission(db)["state"] == "pending"
|
||||
|
||||
@ -356,11 +356,23 @@ Gitea → as **pablo** → Settings → Applications → *Generate New Token*, s
|
||||
CONTENT_TOKEN=
|
||||
```
|
||||
|
||||
It falls back to `GITEA_ADMIN_TOKEN` if left empty, so an existing install
|
||||
keeps working — but they should not stay the same. The admin token can create
|
||||
and modify every account on the instance; publishing a post needs one
|
||||
repository. Since members no longer have accounts to create, the admin token
|
||||
has no remaining job and can be revoked once `CONTENT_TOKEN` is in place.
|
||||
**The scope matters more than this page used to admit.** Gitea's scopes are per
|
||||
category, and `admin` does not contain `repository` — a site-admin token gets a
|
||||
403 from the contents API, no matter how powerful it is elsewhere. So the
|
||||
fallback to `GITEA_ADMIN_TOKEN` when `CONTENT_TOKEN` is empty keeps the app
|
||||
*running*, but it does not keep publishing working: with an admin-only token the
|
||||
editor cannot commit at all. That is exactly what happened here, and it went
|
||||
undiagnosed for three phases because the refusal escaped as a 500 on
|
||||
*Contenido* and, when approving a submission, as a message blaming a missing
|
||||
photograph. Both now say what is wrong, but the fix is this token.
|
||||
|
||||
Once `CONTENT_TOKEN` is in place, **revoke `GITEA_ADMIN_TOKEN`**: it can create
|
||||
and modify every account on the instance, members no longer have accounts to
|
||||
create, and it has no remaining job.
|
||||
|
||||
If *Contenido* says *"El servidor de git rechazó el token del editor"*, this
|
||||
section is the answer: the token is missing, revoked, or scoped to something
|
||||
other than the repository.
|
||||
|
||||
**Commits still say who wrote them.** One token does the committing, and each
|
||||
commit names its author, so `git log` shows the member and there is somebody to
|
||||
@ -799,6 +811,20 @@ Editing a returned proposal puts it back in the queue automatically. An approved
|
||||
one can no longer be edited from there — the file is in the repository, and that
|
||||
is what *Contenido* is for.
|
||||
|
||||
**On the wall itself**: one 👍 per member per post or comment, which clicking
|
||||
again takes back, and every name is a link to that person's page — but only when
|
||||
they have published one, so nobody is sent to a 404. Both rules live in one place
|
||||
each (`templates/_reaction.html`, `templates/_person.html`) so no screen has to
|
||||
remember them.
|
||||
|
||||
**Miembros is a directory**, not an admin table: a card per person with their
|
||||
photo, username, role, the first line of their bio, somewhere to write to them
|
||||
and a link to their page. Admins get the controls — suspend, re-invite, change
|
||||
role, erase — inside a *Gestionar* block on each card, closed by default. A
|
||||
member's photo shows here even when their public page is unpublished, because
|
||||
this side is behind the login; `profiles.member_photo` serves it and the profile
|
||||
form says so in plain words.
|
||||
|
||||
## 12. Make Gitea look like the site
|
||||
|
||||
Members sign in to `/comunidad/` through Gitea, so Gitea's sign-in form and its
|
||||
|
||||
Loading…
Reference in New Issue
Block a user