Skip to content

Administració d'usuaris, prompts i inferències - #104

Open
lequims wants to merge 19 commits into
mainfrom
feat/admin-access
Open

lequims wants to merge 19 commits into
mainfrom
feat/admin-access

Conversation

@lequims

@lequims lequims commented Nov 1, 2026

Copy link
Copy Markdown
Member
  • Depèn de la Menú del compte a la capçalera, logotip i descàrrega de dades #103 (menú del compte): fins que s'integri, aquesta PR es basa en feat/account-menu
  • Afegeix el rol d'administrador (users.is_admin) i el bloqueig de comptes (users.blocked_at); un compte bloquejat perd les sessions i no pot tornar a entrar, i una restricció CHECK impedeix que un compte donat de baixa sigui administrador
  • El rol no es pot canviar des de cap endpoint: s'assigna amb l'script scripts/fes_administrador.py, que concedeix o revoca el rol i exigeix un compte existent, amb el correu verificat i no bloquejat. La migració no fa administrador ningú; GET /api/auth/session exposa is_admin
  • Afegeix l'API /api/admin/* per llistar usuaris (amb la darrera activitat) i bloquejar-los o desbloquejar-los, i per crear, filtrar, activar, desactivar i esborrar prompts i inferències; les llistes són paginades i l'esborrat es rebutja si hi ha inferències o vots
  • Un prompt desactivat deixa de servir-se i els seus vots surten del rànquing; la versió torna a ser l'anterior activa
  • Cada inferència té dos interruptors independents: active (es mostra a qui avalua) i included_in_ranking (els seus vots compten al rànquing i a la confiança). La memòria cau del rànquing s'invalida amb les dates de modificació
  • Afegeix prompts.content_sha256 (únic per versió, amb migració que omple els existents), que impedeix repetir el mateix text dins d'una versió; scripts/carrega_inferencies.py també ho detecta
  • Afegeix la importació de fitxers YAML d'inferència, amb les mateixes regles que scripts/carrega_inferencies.py: cada fitxer és independent, el prompt es busca per versió i codi, les respostes idèntiques s'ometen, les que canvien una resposta existent es rebutgen i, si hi ha prompt.sha256, ha de coincidir amb el text del prompt
  • Afegeix la pàgina d'Administració (/admin) amb les pestanyes Usuaris, Prompts i Inferències, accessible només per a administradors des del menú del compte
  • Afegeix quatre migracions d'Alembic encadenades, amb les seves proves, i actualitza docs/db_schema.md, docs/usuaris_autenticacio.md i els README del backend i del frontend

🤖 Generated with Claude Code

lequims and others added 18 commits November 1, 2026 16:22
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…count deletion

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…and stop caching the data export

Drop the ARIA menu roles (no arrow-key navigation is implemented), close the
dropdown when focus leaves it, keep it inside the viewport and right-align the
header controls when they wrap. Send Cache-Control: no-store on /auth/export.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Users gain `is_admin` and `blocked_at`. A `CurrentAdmin` dependency guards the new
`/api/admin` endpoints, which list users and block or unblock them. Blocking revokes
the user's sessions and rejects further logins; account deletion removes the role.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Admins can list, create and delete prompts under `/api/admin/prompts`. Each prompt
stores the SHA-256 of its text, unique per version, so the same content cannot be
published twice in one version. A prompt can only be deleted while it has no
inferences. The inference loader reports repeated content as an error instead of failing.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Admins can list, create, delete and patch responses under `/api/admin/responses`.
A response can be deactivated, so it is no longer shown or counted in task progress,
and excluded from the ranking, so votes involving it stop counting. A response with
votes or skips cannot be deleted. The ranking cache is also invalidated when a
response changes, since toggling a flag does not change any id.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A new /admin page, shown only to administrators, lets them block users, manage
prompts and manage inferences (activate, exclude from the ranking, delete). The
session endpoint now reports `is_admin` so the header can link to it, and the API
client handles empty 204 responses.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The date is the latest of the user's last login, vote and task skip, computed
from existing tables, so no column or migration is needed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A deactivated prompt is no longer served and its votes stop counting in the
ranking. Version selection skips inactive prompts, so deactivating the newest
version falls back to the previous one, which undoes a faulty release without
deleting anything. The ranking cache is invalidated on each change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The confirm and cancel buttons wrapped onto a second line, which made the row
taller and shifted the rows below.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Admins can pick the YAML files produced by the inference pipeline and import them
under a version. Each file is independent and follows the same rules as the command
line loader: a response that already exists is skipped, a changed one is rejected,
and the prompt hash recorded in the file must match the prompt text. A test checks
that the parsed result equals the loader's. Files travel as JSON so no new
dependency is needed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…menu

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Base automatically changed from feat/account-menu to main November 1, 2026 20:11

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant