mirror of https://github.com/interlegis/sapl.git
Browse Source
Implements the URL decoupling layer described in the RFC:
sapl/base/views.py
serve_file(request, file_uuid)
Resolves UUID → FileMetadata → storage_name; issues X-Accel-Redirect
to nginx with dual-param Content-Disposition (ASCII + UTF-8 encoded).
Currently passes all files unconditionally; the permission-check hook
is in place for when DocumentoAdministrativo.nivel_restricao is wired.
serve_model_file(request, app_label, model_name, pk, field_name)
Semantic alias handler: validates (app, model, field) against an explicit
SERVE_FILE_FIELDS allowlist, fetches the parent instance, resolves the
_metadata FK, then delegates to serve_file. Allowlist prevents the
generic URL from accidentally exposing arbitrary model fields.
sapl/base/fields.py
MetadataFieldFile(FieldFile) — overrides .url:
• saved instance → /<app>/<model>/<pk>/<field>/download (semantic alias)
• unsaved instance → /documentos/<uuid>/ (canonical fallback)
• no metadata row → raw storage URL (pre-backfill fallback, nothing breaks)
MetadataFileField.attr_class = MetadataFieldFile
sapl/urls.py
path('documentos/<uuid:file_uuid>/', serve_file, name='serve_file')
path('<app>/<model>/<pk>/<field>/download', serve_model_file, ...)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
file-metafields
3 changed files with 157 additions and 0 deletions
Loading…
Reference in new issue