Skip to content

Site: Editor delegations API — GET /editeur/api/v1/delegations + rswag bootstrap#144

Merged
Un3x merged 5 commits into
developfrom
feature/api-6627-t8-api-editeur-get-editeurapidelegations
May 26, 2026
Merged

Site: Editor delegations API — GET /editeur/api/v1/delegations + rswag bootstrap#144
Un3x merged 5 commits into
developfrom
feature/api-6627-t8-api-editeur-get-editeurapidelegations

Conversation

@Un3x
Copy link
Copy Markdown
Contributor

@Un3x Un3x commented May 23, 2026

Summary

  • Adds GET /editeur/api/v1/delegations — first endpoint of the editor-facing API. SaaS clients authenticate with their JWT editor token (Bearer), get back the list of their delegations as flat JSON, and map siret → delegation_id to set X-Delegation-Id on métier calls.
  • Introduces a reusable Editor::API::BaseController that decodes the JWT via AccessToken.decode, enforces the editor: true claim (so admin tokens cannot cross into the editor API surface), and looks up an active EditorToken by jti. Any failure on the auth path returns 401 before reaching the action body.
  • Bootstraps rswag in site/ (gems + initializers + generators) — Swagger UI mounted at /editeur/api-docs, generated YAML at site/swagger/v1/openapi-editor.yaml, regenerate via bin/generate_swagger.sh.
  • Pagination: default 50 / page, hard-capped at 100 to keep the query bounded. Cross-editor isolation enforced by scoping through current_editor.editor_delegations.

Closes API-6627 (T8).

Notes

  • Host = entreprise.api.gouv.fr (option 2, confirmed by @skelz0r). The host-level routing/CORS configuration is handled separately by Loïc on the site/ side.
  • Clients SDKs (clients/ruby/, clients/node/) are not updated: those target the métier APIs (siade/) per clients/SPECS.md, not the editor admin surface. This new endpoint is a separate API class that editors call once at startup.

Test plan

🤖 Generated with Claude Code

@linear
Copy link
Copy Markdown

linear Bot commented May 23, 2026

API-6627

@Un3x Un3x requested review from Samuelfaure and skelz0r May 26, 2026 08:46
Copy link
Copy Markdown
Member

@skelz0r skelz0r left a comment

Choose a reason for hiding this comment

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

Y'a les quelques issues que je pointe + il faudrait à mon sens vérifier qu'on régénère bien le swagger si il y a des modifications (comme ce qu'on fait sur siade/)

Comment thread site/app/controllers/editor/api/v1/delegations_controller.rb Outdated
Comment thread site/app/lib/editor/api/v1/delegation_serializer.rb Outdated
Comment thread site/spec/requests/editor/api/v1/delegations_spec.rb
Comment thread site/spec/requests/editor/api/v1/host_routing_spec.rb
@Un3x Un3x force-pushed the feature/api-6627-t8-api-editeur-get-editeurapidelegations branch from 42662d9 to 0af557c Compare May 26, 2026 12:36
Un3x added 5 commits May 26, 2026 14:45
Establish the editor API namespace at /editeur/api/v1, gated by an
EditorAPIDomainConstraint that restricts access to entreprise/particulier
hosts, and shared with a base controller that authenticates editor JWT
bearer tokens and exposes the calling API to subclasses.

Open CORS on /editeur/api/* so SaaS éditeurs can call the API from
arbitrary origins.
Expose the authenticated editor's delegations (active and revoked)
as the integration channel for SaaS éditeurs: callers map
siret → id and pass X-Delegation-Id on subsequent metier calls.

The endpoint is scoped to the API matching the calling host
(entreprise.api.* vs particulier.api.*), so an editor with
delegations on both APIs sees only the relevant slice per host.

Pagination follows the shared editor API conventions (default 50,
max 100). The payload is a flat JSON document with delegation id,
DataPass authorization_request_id, SIRET, intitule, scopes, statut
and creation timestamp.
Drive the editor API OpenAPI spec from RSpec integration specs via
rswag, mirroring siade/'s approach. The integration spec is the
source of truth for swagger/v1/openapi-editor.yaml; bin/generate_swagger.sh
regenerates the file from the spec.

Mount Rswag::Ui at /editeur/api-docs so éditeurs can browse the spec
directly from the editor API host.
Mirror siade/'s swagger drift check on site/: bin/test_swagger.sh
snapshots the committed OpenAPI file, regenerates it from the rswag
specs and fails if the two differ. A new check-swagger CI job runs
this on every push and gates the merge and deploy jobs, so an editor
API contract change can never land without its OpenAPI counterpart.
Surface GET /editeur/api/v1/delegations on the public changelog so
SaaS éditeurs know the dashboard-only siret → id mapping can now be
automated end-to-end.
@Un3x Un3x force-pushed the feature/api-6627-t8-api-editeur-get-editeurapidelegations branch from 0af557c to 2eb9aa9 Compare May 26, 2026 12:48
@Un3x Un3x requested a review from skelz0r May 26, 2026 13:34
Copy link
Copy Markdown
Member

@skelz0r skelz0r left a comment

Choose a reason for hiding this comment

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

:shipit:

Copy link
Copy Markdown
Contributor

@Samuelfaure Samuelfaure left a comment

Choose a reason for hiding this comment

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

LGTM en dehors des remarques du Skelz0r

@Un3x Un3x merged commit a8ea7ea into develop May 26, 2026
44 of 52 checks passed
@Un3x Un3x deleted the feature/api-6627-t8-api-editeur-get-editeurapidelegations branch May 26, 2026 16:16
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.

3 participants