Commit Graph

33 Commits

Author SHA1 Message Date
Jeremy Stretch a907ba2062
#21992: Additional cleanup (#22594) 2026-07-06 09:45:45 -05:00
Jeremy Stretch d28f0a2114 Merge branch 'main' into feature
Resolved conflicts:
- Dropped 4.7 deprecation shims (FutureWarning getattr/methods) re-introduced
  by main, which feature has already removed: pagination, constants, registry,
  forms utils/expandable, settings (Sentry), generic view mixins.
- dcim/signals.py: kept main's search-cache-on-VC-rename handler; dropped
  Prefix/Cluster/WirelessLAN imports for the scope-sync handler feature replaced
  with PostgreSQL triggers.
- extras test_management_commands.py: unioned ConfigContext + ImageAttachment
  imports.
- Rebuilt project-static dist bundles (netbox.js/.map/.css) from merged source.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-30 11:32:37 -04:00
mburggraf f9ce0a6741
Closes #22464: Update Documentation to use v2 Tokens in examples (#22477) 2026-06-17 13:44:29 -07:00
Jason Novinger 89504b2502
Closes #21992: Enable background job support for REST API bulk requests (#22452)
Bulk write operations (create/update/delete a JSON list at a model's list
endpoint) can opt into background processing with the ?background=true query
parameter. The request is validated synchronously and, if accepted, an
AsyncAPIJob is enqueued and a 202 Accepted is returned with the job id and
poll URL; the write is performed later by a worker that re-invokes the same
viewset action, so behavior matches the synchronous path (including
all-or-nothing transaction semantics).

- AsyncAPIJob reconstructs the request in the worker, re-applies object
  permissions, runs within the request processors (change logging/events),
  and captures the action's response into job.data as {status_code, data}.
- Handled rejections are translated to match the synchronous API: APIException
  via handle_exception(), and AbortRequest/ProtectedError/RestrictedError via a
  new NetBoxModelViewSet.exception_to_response() helper. These terminate the
  job as "failed" (reserving "errored" for unexpected crashes).
- Background processing is refused with 503 when no worker is servicing the
  queue, and rejected with 400 when combined with an If-Match precondition
  (which cannot be honored once execution is deferred).
- Single-object writes, GET requests, and non-list payloads ignore the
  parameter and run synchronously.

exception_to_response() intentionally duplicates the translation logic in
dispatch() rather than dispatch() being refactored to call it; consolidating
the two is left as a follow-up to keep this change off the synchronous hot path.

* Address code review feedback (#21992)

- Carry the request's scheme and host into the background worker so absolute
  URLs in the captured job result point at the real server instead of a
  hardcoded http://localhost/.
- Emit the same protected-delete warning log in exception_to_response() that
  dispatch() produces, restoring application-log parity for background failures.
- Drop the inert `_authenticator = None` assignment: setting request.user
  already prevents lazy re-authentication via the public API, and nothing on
  the worker's action path reads the authenticator.
- Remove the redundant success-path job.save() (JobRunner.handle() ->
  terminate() persists job.data) and hoist the AsyncAPIJob import in mixins.py
  to module level (no real import cycle through it).
- Add a test asserting result URLs reflect the request host.

* Fix IPv6 host parsing in background API request reconstruction

Parse the carried host with urlsplit (and pass it verbatim as HTTP_HOST)
instead of host.partition(':'), which split bracketed IPv6 hosts like
[::1]:8443 on their inner colons. Extract request construction into
AsyncAPIJob._build_request and add a test asserting the IPv6 host round-trips.

* Address review feedback (#21992)

- Make the bulk mixins safe to use without BackgroundOperationMixin: guard the
  _background_requested / _maybe_background_bulk_create calls with a getattr
  fallback so BulkUpdateModelMixin/BulkDestroyModelMixin/SequentialBulkCreatesMixin
  retain their standalone behavior in custom viewset composition.
- Add a test covering the background ProtectedError/RestrictedError path: a bulk
  delete of a protected object records the same 409 the synchronous API returns
  (job failed, status_code 409, object preserved), via exception_to_response().
2026-06-16 12:48:17 +02:00
Jeremy Stretch 814050a3c9 Closes #22409: Disallow chosen-plaintext API tokens 2026-06-08 14:14:30 -04:00
Jeremy Stretch 2703ff98a3
Closes #22128: Deprecate v1 API tokens (#22143)
Display a warning in the UI whenever a user goes to provision a v1
token (both via the admin token form and the user profile token form).
Update documentation to note that v1 tokens are deprecated and will be
removed in NetBox v5.0.
2026-05-07 08:48:25 -07:00
Jeremy Stretch e50aff8736
Documentation cleanup (#22127) 2026-05-06 16:58:08 -05:00
Jeremy Stretch 6659bb3abe
Closes #21363: Implement cursor-based pagination for the REST API (#21594) 2026-03-06 17:13:08 -08:00
Jeremy Stretch 1526e437f1
Closes #21244: Introduce ability to omit specific fields from REST API responses (#21312)
Introduce support for omitting specific serializer fields via an
`omit` parameter, acting as the inverse of `fields`.
Wire it through the API viewset and queryset optimization helpers
so omitted fields don’t trigger unnecessary annotations/prefetches,
and document the new behavior.
2026-01-28 22:06:46 +01:00
Mark Robert Coleman e60807adc5
Fixes #21121: Expand changelog message doc/add cross-references (#21138) 2026-01-13 09:58:06 -06:00
Jeremy Stretch 2bebfccf9b Closes #20492: Disable API token plaintext retrieval 2025-10-14 14:57:37 -04:00
Jeremy Stretch c63e60a62b Add a token prefix 2025-10-06 17:04:10 -04:00
Jeremy Stretch 82db8a9c02 Update documentation 2025-10-03 14:24:21 -04:00
Jeremy Stretch 1ee23ba6fa Initial work on #20210 2025-10-02 15:04:29 -04:00
Jeremy Stretch 24a0e1907a
Closes #19713: Enable recording user messages in the change log (#19908)
* Add message field to ObjectChange model

* Set max length on changelog message

* Enable changelog messages for single object operations

* Fix tests

* Add changelog message support for bulk edit & bulk delete

* Cosmetic improvements to form fields

* Fix bulk operation templates

* Add message support for bulk import/update

* Add REST API support for changelog messages (WIP)

* Fix changelog_message assignment

* Enable changelog message support for bulk deletions

* Add documentation

* Fix changelog message support for VirtualChassis

* Add ChangeLoggingMixin to necesssary model forms

* Introduce get_random_string() utility function for tests

* Incorporate changelog messages for object view tests

* Incorporate changelog messages for object bulk view tests

* Add missing mixins for changelog message support

* Tweak test to generate expected number of change records

* Finish adding tests for changelog message functionality

* Misc cleanup

* Fixes #19956: Prevent duplicate deletion records from cascading deletions

* Tweak bulk deletion test to work around cascading deletions issue

* Correct API URL
2025-07-29 09:11:33 -05:00
Markku Leiniö 0466c8ef9b
Closes #19167: Update REST API examples (#19353)
* Closes #19167: Update REST API examples

* Fix missing description

---------

Co-authored-by: Markku Leiniö <markkuleinio@users.noreply.github.com>
2025-04-29 13:31:06 -04:00
Jeremy Stretch 0f4afbca2c
Closes #17243: Include example of image upload using REST API (#19330) 2025-04-25 15:33:46 -05:00
mr1716 9c1358e6e7 #18698 Correct REST Wikipedia URL In Documentation 2025-02-21 09:34:16 -05:00
Jeremy Stretch 10a74492f6 #17143: Update docs for nested serializer use 2024-08-30 10:18:29 -04:00
muTeREdO 238fa704b9
add example showing how to order results. (#15627)
* add example showing how to order results.

This addresses issue 15622 by building off filtering example to
show how to order results on a named field.

* Apply suggestions from code review

---------

Co-authored-by: Frank Clements <fclements@scoore.net>
Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
2024-04-04 14:21:26 -04:00
Markku Leiniö d285edc0c7
Fixes #15583: Update API token provisioning example response (#15584)
* Fixes #15583: Update API token provisioning example response

* Fix 'display' field output
2024-04-03 07:58:46 -04:00
Jeremy Stretch b4acbb5e16 Closes #13439: Update API token documentation 2023-08-16 10:28:33 -04:00
Jeremy Stretch 699b4dfade Update feature introduction flags 2023-08-01 14:25:25 -04:00
kkthxbye 0ad88e2431
Changed docs to reflect the new URL for the dynamic API documentation 2023-05-16 08:19:57 +02:00
jeremystretch f49e4ee512 Merge branch 'develop' into feature 2023-04-26 15:09:51 -04:00
Janik H 12bb0ec1fe Fix typo in api token auth 2023-04-21 10:01:13 -04:00
jeremystretch 59a6b3e71b Merge branch 'develop' into feature 2023-04-12 17:38:16 -04:00
Arthur Hanson 9e305c6181
Closes #12207: Establish a permission for creating API tokens on behalf of other users (#12192)
* 11091 add permission to allow user to create api tokens for other users

* 11091 update docs

* 11091 fix for test

* 11091 fix for test

* 11091 test case for invalid token creation

* 11091 add test for permission grant

* Cleanup & fix serializer validation

---------

Co-authored-by: jeremystretch <jstretch@netboxlabs.com>
2023-04-12 10:25:06 -04:00
jeremystretch 402d5d955f Documentation cleanup 2023-03-20 16:37:47 -04:00
jeremystretch f74a2536f1 Closes #11254: Introduce the X-Request-ID HTTP header to annotate the unique ID of each request for change logging 2023-02-19 20:09:51 -05:00
jeremystretch ef3ac25406 Remove old feature version notices 2023-02-19 20:09:51 -05:00
Arthur Hanson 816fedb78d
8853 Prevent the retrieval of API tokens after creation (#10645)
* 8853 hide api token

* 8853 hide key on edit

* 8853 add key display

* 8853 cleanup html

* 8853 make token view accessible only once on POST

* Clean up display of tokens in views

* Honor ALLOW_TOKEN_RETRIEVAL in API serializer

* Add docs & tweak default setting

* Include token key when provisioning with user credentials

Co-authored-by: jeremystretch <jstretch@ns1.com>
2022-11-02 12:45:00 -04:00
jeremystretch 5da3cab4de Reorganize documentation 2022-08-04 14:11:52 -04:00