Skip to content

feat(admin): API gestione ruoli utenti /admin/users (backend #235 Fase 2) - #240

Merged
gzileni merged 1 commit into
mainfrom
feat/backend-admin-api-235
Jul 21, 2026
Merged

feat(admin): API gestione ruoli utenti /admin/users (backend #235 Fase 2)#240
gzileni merged 1 commit into
mainfrom
feat/backend-admin-api-235

Conversation

@gzileni

@gzileni gzileni commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Fase 2 della gestione utenti: la API admin che alimenterà la dashboard admin (Fase 4).

Endpoint (tutti require_admin)

  • GET /admin/users — elenco utenti registrati (id, email, display_name, role, tier, created_at), newest-first, con filtro ?role= e paginazione limit/offset.
  • PATCH /admin/users/{id}/role — cambia il ruolo (validato su admin/regione/comune/cittadino), 404 se utente sconosciuto, guardia anti-lockout: un admin non può auto-degradarsi.

Note

  • Autenticazione resta all'IdP OIDC; il ruolo vive in opendata.users.role (Fase 1). Un non-admin riceve 403 su entrambi.
  • Repo: list_users, get_by_id, set_role_by_id.

Test (tests/test_admin_users.py)

403 per non-admin, list+filtro (+422 ruolo ignoto), cambio ruolo persistito, 422/404 su PATCH, guardia auto-degrado. Suite backend 504 passed, 2 skipped; lint pulito.

Prossime fasi (#235)

  1. sync utente da Keycloak al primo login; 4) UI dashboard admin /admin; 5) UI registrazione SPID + email-OTP; 6) frontend OIDC.

Parte di #235.

🤖 Generated with Claude Code

Superficie admin-only (require_admin):
- GET /admin/users — elenco utenti (filtro per ruolo, paginazione), newest-first.
- PATCH /admin/users/{id}/role — cambia ruolo (validato su VALID_ROLES), 404 se
  utente inesistente, guardia anti-lockout (l'admin non può auto-degradarsi).
- repo: list_users, get_by_id, set_role_by_id.
- router registrato in main.py.

Autenticazione resta all'IdP; il ruolo vive in opendata.users.role. Suite 504 passed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b7753ccebf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

stmt = stmt.where(User.deleted_at.is_(None))
if role:
stmt = stmt.where(User.role == role)
stmt = stmt.order_by(User.created_at.desc()).limit(limit).offset(offset)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Add a deterministic tie-breaker to pagination

When multiple users have the same created_at value (for example rows inserted in one transaction, since the model uses a database now() default), this ordering leaves their relative order undefined. With limit/offset pagination on /admin/users, page boundaries can then repeat or skip users between requests; add a stable tie-breaker such as User.id.desc() after created_at.desc().

Useful? React with 👍 / 👎.

@gzileni
gzileni merged commit e35a720 into main Jul 21, 2026
27 checks passed
@gzileni
gzileni deleted the feat/backend-admin-api-235 branch July 21, 2026 13:55
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