Commit Graph

56 Commits

Author SHA1 Message Date
Arthur Hanson c9a62254d7
Fixes #22750: Validate Custom Script input and resolve object IDs in the REST API (#23119)
Validate REST script input before enqueueing jobs. Resolve ObjectVar
IDs to model instances and MultiObjectVar IDs to querysets, returning
HTTP 400 with errors nested under data when validation fails.

Share form preparation between the API and UI, including multi-value
defaults, while keeping validation out of the job runner to preserve
other execution paths. Exclude only known execution fields from script
data and prevent _notifications from leaking into CLI script input.

Document the REST compatibility changes, including required-field
validation and discarded undeclared keys. Add regression coverage for
object resolution, defaults, validation errors, and execution options.

Co-authored-by: Martin Burggraf <martin.burggraf@netclusive.com>
2026-09-07 13:11:14 +02:00
Jeremy Stretch 9e69498e07
Closes #22935: Deprecate Custom Scripts (#22936) 2026-08-14 20:35:44 +02:00
Martin Hauser 75ceb55754
fix(extras): Honor Script defaults when triggered by Event Rules
Scripts triggered by Event Rules now respect notifications_default and
job_timeout from script Meta class. Updates documentation to clarify
this behavior and adds regression test coverage.

Fixes #22852
2026-08-05 18:01:38 +02:00
Jason Satein c36e72876f
Closes #22567: Warn that a custom script file name must not shadow an installed Python module (#22804) 2026-08-04 08:36:11 -07:00
Martin Hauser a0debf0e3b
feat(extras): Allow updating uploaded Script Modules via API
Add PUT/PATCH support to ScriptModuleViewSet for replacing Script Module
content in place. Modules can be addressed by numeric ID or file name,
and the uploaded file name must match the existing file path.
The module's scripts are re-synchronized from the new content after
successful update.

Fixes #22544
2026-07-10 13:18:36 +02:00
mburggraf f9ce0a6741
Closes #22464: Update Documentation to use v2 Tokens in examples (#22477) 2026-06-17 13:44:29 -07:00
mburggraf 57e7884d83
Closes #21261: add quick_add parameter to ObjectVar (#22271) 2026-05-22 13:38:58 -05:00
Martin Hauser 62b3d8f615 docs(customization): Add model validation guidance for Custom Scripts
Adds warning and examples for validating NetBox objects before saving
in Custom Scripts. Direct ORM writes bypass UI/API validation and can
introduce invalid data. Recommends calling `full_clean()` explicitly.

Fixes #22249
2026-05-20 12:52:36 -04:00
Jeremy Stretch b68b0c6d78
Closes #21751: Enable toggling user notifications when executing custom scripts (#21923) 2026-04-20 09:32:41 -07:00
Arthur Hanson f2d8ae29c2
21701 Allow scripts to be uploaded via post to API (#21756)
* #21701 allow upload script via API

* #21701 allow upload script via API

* add extra test

* change to use Script api endpoint

* ruff fix

* review feedback:

* review feedback:

* review feedback:

* Fix permission check, perform_create delegation, and test mock setup

- destroy() now checks extras.delete_script (queryset is Script.objects.all())
- create() delegates to self.perform_create() instead of calling serializer.save() directly
- Add comment explaining why update/partial_update intentionally return 405
- Fix test_upload_script_module: set mock_storage.save.return_value so file_path
  receives a real string after the _save_upload return-value fix; add DB existence check

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Return 400 instead of 500 on duplicate script module upload

Catch IntegrityError from the unique (file_root, file_path) constraint
and re-raise as a ValidationError so the API returns a 400 with a clear
message rather than a 500.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Validate upload_file + data_source conflict for multipart requests

DRF 3.16 Serializer.get_value() uses parse_html_dict() or empty for all
HTML/multipart input. A flat key like data_source=2 produces an empty
dict ({}), which is falsy, so it falls back to empty and the nested
field is silently skipped. data.get('data_source') is therefore always
None in multipart requests, bypassing the conflict check.

Fix: also check self.initial_data for data_source and data_file in all
three guards in validate(), so the raw submitted value is detected even
when DRF's HTML parser drops the deserialized object.

Add test_upload_with_data_source_fails to cover the multipart conflict
path explicitly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Require data_file when data_source is specified

data_source alone is not a valid creation payload — a data_file must
also be provided to identify which file within the source to sync.
Add the corresponding validation error and a test to cover the case.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Align ManagedFileForm validation with API serializer rules

Add the missing checks to ManagedFileForm.clean():
- upload_file + data_source is rejected (matches API)
- data_source without data_file is rejected with a specific message
- Update the 'nothing provided' error to mention data source + data file

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Revert "Align ManagedFileForm validation with API serializer rules"

This reverts commit f0ac7c3bd2.

* Align API validation messages with UI; restore complete checks

- Match UI error messages for upload+data_file conflict and no-source case
- Keep API-only guards for upload+data_source and data_source-without-data_file
- Restore test_upload_with_data_source_fails

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Run source/file conflict checks before super().validate() / full_clean()

super().validate() calls full_clean() on the model instance, which raises
a unique-constraint error for (file_root, file_path) when file_path is
empty (e.g. data_source-only requests). Move the conflict guards above the
super() call so they produce clear, actionable error messages before
full_clean() has a chance to surface confusing database-level errors.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* destroy() deletes ScriptModule, not Script

DELETE /api/extras/scripts/<pk>/ now deletes the entire ScriptModule
(matching the UI's delete view), including modules with no Script
children (e.g. sync hasn't run yet). Permission check updated to
delete_scriptmodule. The queryset restriction for destroy is removed
since the module is deleted via script.module, not super().destroy().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* review feedback:

* cleanup

* cleanup

* cleanup

* cleanup

* change to ScriptModule

* change to ScriptModule

* change to ScriptModule

* update docs

* cleanup

* restore file

* cleanup

* cleanup

* cleanup

* cleanup

* cleanup

* keep only upload functionality

* cleanup

* cleanup

* cleanup

* change to scripts/upload api

* cleanup

* cleanup

* cleanup

* cleanup

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-02 08:42:14 -04:00
Jamie (Bear) Murphy 9b0c6110bb
Clarify optional changelog message in custom-scripts
Added comment to clarify optional changelog message.
2026-03-06 17:13:52 +00:00
Jamie (Bear) Murphy 1be917fb90
Add changelog message documentation in custom scripts
Add changelog message documentation in custom scripts
2026-03-03 13:10:04 +00:00
bctiemann b22e490847
Fixes: #20490 - Add filtering of Script objects based on object permissions with custom constraints (#21212) 2026-02-18 15:37:40 -05:00
Jeremy Stretch afba5b2791 Merge branch 'main' into feature 2025-11-25 15:25:53 -05:00
Grische 975e0ff398
Fix examples for type of class Meta() (#20799) 2025-11-17 09:14:46 -08:00
Jeremy Stretch 068d493cc6 Merge branch 'main' into feature 2025-10-29 13:47:01 -04:00
Martin Hauser e251ea10b5
Closes #20605: Document variable prefilling via URL parameters (#20619) 2025-10-19 15:42:09 -05:00
Jeremy Stretch 21ba27fb39 Closes #20096: Remove legacy load_yaml() & load_json() methods from BaseScript 2025-09-11 11:30:15 -04:00
Kyer 89a94486e1
Closes #19945: Create DecimalVar class for custom script input (#19963) 2025-07-29 09:49:33 -04:00
Jeremy Stretch fc0acb020f Merge main into feature 2025-04-10 17:17:21 -04:00
Arthur Hanson 1b4e00aeda
18896 Replace STORAGE_BACKEND with STORAGES and support Script running from S3 (#18680) 2025-03-17 07:36:34 -07:00
Arthur Hanson 35307d213f 17468 add warning to documentation about overriding custom script properties 2024-10-16 12:57:26 -04:00
Arthur Hanson ed1b8bc88d 16349 add warning to custom script docs 2024-09-05 12:52:16 -04:00
Jeremy Stretch 8b62e40874 Closes #16307: Enable calling log_* methods on Script without a log message 2024-06-24 10:45:33 -04:00
Arthur Hanson 85fd232614
16149 add (optional) obj hyperlink to script list table (#16271)
* 16149 add (optional) obj hyperlink to script list table

* 16149 add (optional) obj hyperlink to script list table

* 16149 review feedback

* 16149 review changes
2024-06-21 10:04:52 -04:00
Arthur Hanson 8f87c72eaa
16050 Show script python_class name and description (#16185)
* 16050 Show script python_class name and description

* 16050 change to use Meta.description

* 16050 change to use Meta.description

* 16050 remove module name customization from docs
2024-06-06 09:05:59 -04:00
Jeremy Stretch 312291b010 Merge branch 'develop' into feature 2024-05-01 16:09:14 -04:00
JCWasmx86 3cbade536e
Fixes #15812: Add Date(Time)Var for scripts to allow much easier date… (#15821)
* Fixes #15812: Add Date(Time)Var for scripts to allow much easier date input

* Extend tests for invalid data

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
2024-04-29 12:46:39 -04:00
Jeremy Stretch 709eac6b98 Closes #15292: Remove obsolete device_role attribute from Device model 2024-03-01 11:31:47 -05:00
Jeremy Stretch 3ddacf4b88 Merge branch 'develop' into feature 2024-02-21 16:24:23 -05:00
Jeremy Stretch 20824ceb25
Closes #13283: Add context to dropdown options (#15104)
* Initial work on #13283

* Enable passing TomSelect HTML template attibutes on DynamicModelChoiceField

* Merge disabled_indicator into option_attrs

* Add support for annotating a numeric count on dropdown options

* Annotate parent object on relevant fields

* Improve rendering of color options

* Improve rendering of color options

* Rename option_attrs to context

* Expose option context on ObjectVar for custom scripts

* Document dropdown context variables
2024-02-13 16:31:17 -05:00
Arthur Hanson 11697d19a6
12510 Merge Scripts and Reports (#14976)
* 12510 move reports to use BaseScript

* 12510 merge report into script view

* 12510 add migration for job report to script

* 12510 update templates

* 12510 remove reports

* 12510 cleanup

* 12510 legacy jobs

* 12510 legacy jobs

* 12510 fixes

* 12510 review changes

* 12510 review changes

* 12510 update docs

* 12510 review changes

* 12510 review changes

* 12510 review changes

* 12510 review changes

* 12510 main log results to empty string

* 12510 move migration

* Introduce an internal log level for debug to simplify Script logging

* Misc cleanup

* Remove obsolete is_valid() method

* Reformat script job data (log, output, tests)

* Remove ScriptLogMessageSerializer

* Fix formatting of script logs

* Record a timestamp with script logs

* Rename _current_method to _current_test

* Clean up template

* Remove obsolete runreport management command

* Misc cleanup & refactoring

* Clean up template

* Clean up migration

* Clean up docs

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
2024-02-07 12:02:09 -05:00
Anders Harrisson 4afebd3565 Fix custom script documentation example script
The example script still uses the old "role" field when creating
a Device object.

Fixes #15052
2024-02-06 12:42:17 +01:00
Markku Leiniö 3d941411d4
Fixes #14722: Change references to admin UI to Admin menu (#14743)
* Change references to admin UI to Admin menu

* Change also for reports and custom scripts

* Minor tweaks to help text flow better

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
2024-01-10 16:04:46 -05:00
Arthur Hanson bbb133019d
13815 document view permissions for scripts (#13943)
* 13815 document view permissions for scripts

* Replicate permissions note for reports

* Remove duplicated text

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
2023-10-05 15:15:50 -04:00
Abhimanyu Saharan 0bb86f1e7d
Replaces device_role with role on device model (#13342)
* replaces device_role with role on device model #6391

* fixes lint issue #6391

* revert the database user

* revert test_runner comment

* changes as per review

* Update references to device_role column in UserConfigs

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
2023-08-02 09:55:52 -04:00
Abhimanyu Saharan 1af3ba9496
Adds full_clean in examples (#12527)
* adds full_clean in examples #11689

* removes extra info
2023-05-09 08:31:50 -04:00
jeremystretch d5d2431cbd Docs cleanup for v3.5 2023-04-18 16:58:53 -04:00
jeremystretch 197c6a1cbf Add scheduling_enabled parameter for scripts 2023-04-18 08:45:31 -04:00
jeremystretch 3b9fda0169 Merge branch 'develop' into feature 2023-03-20 08:54:22 -04:00
Ryan Merolle 4286d74d44
Add fieldsets functionality to scripts to allow for form field groupings (#11880)
* update script template

* update docs

* introduce default_fieldset

* correct custom script docs

* default to use fieldsets in scripts

* update scripts docs for new behavior

* Misc cleanup

---------

Co-authored-by: jeremystretch <jstretch@netboxlabs.com>
2023-03-14 15:50:49 -04:00
jeremystretch ef3ac25406 Remove old feature version notices 2023-02-19 20:09:51 -05:00
Maximilian Wilhelm 699edd049c
Closes #11152: Add support to abort custom script gracefully (#11621)
Signed-off-by: Maximilian Wilhelm <max@sdn.clinic>
2023-02-02 15:22:55 -05:00
kkthxbye-code 4f95c5a72c Allow scheduling jobs via. the API 2022-10-20 21:36:43 +02:00
kkthxbye-code 52faeb6f60 Added documentation describing job scheduling 2022-10-16 18:15:45 +02:00
Daniel Sheppard 86d366be4d
Fixes #9651 - Document Pre-Change process for scripts 2022-09-20 09:46:23 -05:00
jeremystretch 1d8b8aad3b Changelog & documentation for #5479 2022-04-08 14:10:21 -04:00
kkthxbye-code 36d6ae33d1 Allow setting individual timeouts on scripts and reports 2022-04-04 18:00:38 +02:00
jeremystretch 69eb6b11d0 Closes #8368: Enable controlling the order of custom script form fields with field_order 2022-01-18 16:01:40 -05:00
Jeremy Stretch 2e20d7f02b
Merge pull request #7677 from netbox-community/6529-command-line-run-scripts
#6529 - Add CLI to run scripts
2021-11-03 08:10:36 -04:00