Commit Graph

234 Commits

Author SHA1 Message Date
Jeremy Stretch 9abbebe392 Add v4.7 release notes 2026-08-14 13:53:02 -04:00
Martin Hauser f4fdd60e8d
#22592: Pre-release QA (#22920) 2026-08-14 11:09:53 -05:00
bctiemann d2024a1edc
Closes #22770: Allow plugins to register Event Rule action handlers (#22793)
* Closes #22770: Allow plugins to register Event Rule action handlers

Introduces an EventRuleAction registration API (netbox.event_rules /
netbox.extras.event_rules) so plugins can add new EventRule action types
the same way they already register search indexes and event types,
replacing the hardcoded webhook/script/notification elif-chain. Core's
own three action types are refactored onto this mechanism.

An EventRule referencing an unregistered action (e.g. its providing
plugin is uninstalled) remains stored, is skipped during processing
without affecting other rules, is visibly marked unavailable in the
UI/API, and triggers a new extras.W001 system check, resuming
automatically once the plugin is reinstalled, with no need to re-save.

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

* Fix CI failure: extras.W001 check must tolerate a not-yet-migrated database

check_event_rule_actions() queried EventRule unconditionally, which broke
`manage.py makemigrations --check` (and a fresh `manage.py migrate`) on a
database with no tables yet, since Django runs system checks before
verifying/applying migrations. Wrap the query and swallow DatabaseError,
matching the existing check_postgresql_version precedent for a database
that may not be ready. Verified against a fresh, unmigrated database that
makemigrations --check, migrate, and manage.py check all behave correctly,
and that the warning still fires once a qualifying EventRule exists.

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

* Fix EventRuleForm action_type widget: HTMXSelect was silently ignored

Meta.widgets only applies to fields the ModelForm auto-generates; action_type
is an explicit class-level field, so its HTMXSelect assignment in Meta.widgets
never took effect, and switching Action type in the browser never refreshed
the action_choice field's label/queryset. Move the widget onto the field
declaration itself.

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

* Address review feedback from Jeremy Stretch on PR #22793

- Revert action_object_type on_delete to CASCADE (was changed to SET_NULL)
- Make action_type choices dynamic via the model field's own callable
  choices=, simplifying EventRule.clean() and making any unavailable
  action_type invalid on save, whether new or unchanged
- Rename is_action_available to action_is_available
- Fold new dispatch tests into the existing RQQueueTestMixin test class to
  fix a flaky --parallel run (two such classes cross-flush each other's
  Redis queues)
- Only catch broad exceptions around plugin-provided actions in
  process_event_rules(); let a core action's own bugs propagate
- Add value_action_type() so table exports don't leak the "unavailable"
  badge's HTML markup
- Drop the frozen CSVChoiceField on action_type and make action_object
  optional at the field level, so bulk import of an object-less action
  works
- Map ValidationErrors on unexposed model fields to NON_FIELD_ERRORS in
  bulk import instead of letting them surface as a raw ValueError
- Restore EventRuleActionEnum/the enum-based GraphQL filter, built from
  the live action registry instead of the static EventRuleActionChoices
- Default EventRuleAction.object_required to False, matching
  object_model's default of None; set it explicitly on the three core
  actions
- Drop the unused request parameter on get_object_queryset()
- Fix action_object_type's serializer queryset, which incorrectly used
  the triggering object_types' feature flag
- Use .format() instead of % in get_action_type_display()
- Remove the extras.W001 system check (a DB query on every management
  command) in favor of an action_is_available field on the REST API
- Raise ValidationError instead of a bare Exception on duplicate action
  slug registration
- Shorten a couple of overly verbose inline comments
- Split EventRuleAction.validate() into an internal _validate() and a
  public no-op validate(), so a subclass's custom validation doesn't
  need to remember to call super()

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

* Trim verbose comments/docstrings added while addressing review feedback

Shortened a number of overly long inline comments and test docstrings
introduced across the previous commit's review-feedback fixes (the
EventRuleActionEnum comment, the _validate()/validate() docstrings, and
several test docstrings that restated context already given elsewhere).
Also drops the auto-generated "Generated by Django" header comment from
migration 0143, matching the rest of this app's hand-touched migrations.

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

* Address findings from automated follow-up review of #22793

- Clear stale action_object_type/action_object_id when an action declares
  object_model but is left with no object selected (object_required=False);
  previously neither branch of the if/elif fired and the old value from
  before the edit silently persisted. Fixed in both EventRuleForm and
  EventRuleImportForm (the latter matters for CSV updates of an existing
  row). Also resolve the content type from the actual selected object
  rather than the action's declared object_model, correctly handling
  subclass/proxy instances.
- Validate action slugs at registration time (format, and collision via
  enum_key() with an already-registered slug) so a bad third-party slug
  is rejected immediately instead of crashing GraphQL schema assembly at
  startup.
- Strip the dead-code label/description duplication out of
  EventRuleActionChoices.CHOICES -- nothing reads it, and it risked
  drifting from WebhookAction/ScriptAction/NotificationAction's own.
- Record whether an action is plugin-provided at registration time
  instead of introspecting its module on every dispatch; core's three
  actions now register with is_plugin_provided=False explicitly.
- Add an action_is_available filter (API + UI) so event rules with a
  now-unavailable action can still be found in bulk, now that the
  extras.W001 system check is gone.
- Update the plugin dev docs: fix the OpenTicketAction example (it was
  missing object_required=True, the exact gap the action_object fix
  above addresses), note that an unavailable rule can't be saved at all
  (not just skipped), and move an internal-only note out of the
  published class docstring.

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

* Address findings from second automated follow-up review of #22793

- Drop the ChoiceSet base from EventRuleActionChoices. With CHOICES=(),
  the previous version made ChoiceField(choices=EventRuleActionChoices)
  -- the idiomatic pattern used for every other ChoiceSet in this
  codebase, and reachable via `from extras.choices import *` -- silently
  reject every value instead of failing at first use.
- Reject slugs containing hyphens or a leading underscore at
  registration time: a hyphenated slug (plausible, since plugin
  distribution names are conventionally hyphenated) or a slug starting
  with an underscore both currently pass validation but produce a
  GraphQL-invalid or GraphQL-reserved enum member name once sanitized,
  crashing schema assembly at startup. Document the constraint in the
  plugin docs and the published slug docstring.
- Raise ImproperlyConfigured instead of ValidationError for all three
  registration-failure cases in register_event_rule_action() -- these
  are packaging/configuration mistakes surfaced from AppConfig.ready(),
  not user input, matching the convention ChoiceSetMeta already uses for
  the same class of error.
- Remove is_plugin_provided's class-level default; nothing reads it
  before an action is registered in any real code path, and the default
  masked a class-vs-instance inconsistency. Move its documentation out
  of the published Attributes docstring into a plain comment.
- Simplify EventRuleImportForm.clean()'s action_object_type/id
  assignment to match EventRuleForm.clean()'s approach (set both fields
  once, unconditionally, from the resolved object) rather than assigning
  via the GFK setter and then conditionally overwriting the content
  type.
- Split a dense doc sentence in eventrule.md onto its own line.

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

* Address findings from third automated follow-up review of #22793

- Restore is_plugin_provided's class-level default of True. Its only
  read is inside process_event_rules()'s exception handler; without a
  default, an action reaching dispatch without going through
  register_event_rule_action() (e.g. inserted into the registry dict
  directly) raised AttributeError while already handling the real
  exception, masking it entirely instead of degrading gracefully.
- Move the slug/label presence checks out of __init_subclass__ (which
  fired at class-definition time, raising TypeError) and into
  register_event_rule_action() as ImproperlyConfigured, unifying them
  with the other three registration-time checks. This also resolves a
  still-open item from the very first automated review: an intermediate
  base class shared by several concrete plugin actions couldn't
  previously be defined without a placeholder slug/label of its own.
- Restore the GFK assignment (self.instance.action_object = obj) in
  EventRuleImportForm.clean() alongside the explicit content-type
  assignment, so EventRule.clean()'s later access to action_object hits
  the descriptor cache instead of an extra SELECT per imported row.
- Clarify the slug docstring/docs wording (leading underscore
  specifically, not underscores in general; tell authors to use an
  underscore instead of a hyphen) and document that intermediate base
  classes are now supported. Add a test for an uppercase slug.

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

* Document the frozen-at-import tradeoff on EventRuleSerializer.action_type

The EventRuleActionAPITestCase docstring in test_api.py pointed here for
an explanation of why the choices are materialized once at module-import
time rather than dynamically, but the field itself had no such comment.

* Address findings from fourth automated follow-up review of #22793

- Restore the "must start with a letter" slug constraint dropped from
  the docs page and class docstring by the previous round's rewording;
  reword to "must begin with a lowercase letter", which covers the
  leading-digit case SLUG_RE actually rejects and matches the
  ImproperlyConfigured message an author will hit.
- Scope the GFK-cache-priming comment in EventRuleImportForm.clean() to
  the non-proxy case it actually holds for, rather than claiming it
  unconditionally.
- Trim comments and docstrings that had regrown into reviewer-facing
  rationale (why a prior finding was reverted, why a check isn't in
  __init_subclass__ anymore rather than API documentation, in
  event_rules.py and test_event_rules.py.
EOF
)

* Misc cleanup

* Misc cleanup

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
2026-07-31 16:28:01 -04:00
Jeremy Stretch a24fbb06ce Closes #22721: Enable plugins to extend core GraphQL API
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-22 13:16:43 -04:00
Martin Hauser 8ff8dab8a2
docs: Add Python package installation guide (experimental)
Introduce experimental Python package installation workflow as an
alternative to release archive and Git methods. Document package layout,
setup command, upgrade procedure, and migration path for existing
deployments.

Fixes #22604
2026-07-22 18:18:16 +02:00
Jeremy Stretch ab07002df8 Cleanup from merging main 2026-07-21 09:28:17 -04:00
Jeremy Stretch 80c81230a4 Closes #22615: Remove legacy request_id and username parameters from webhook context 2026-07-07 11:13:09 -04:00
Jeremy Stretch a7be755e01 Closes #21712: Support description annotations for static choice form fields 2026-07-02 13:46:43 -04:00
Jeremy Stretch 48ce5e7e2c
Closes #22446: Add breadcrumbs support for Layouts (#22546) 2026-07-02 10:46:01 -05:00
Martin Hauser b6bdfbd2a5
Closes #19821: Consolidate GFK form handling with GenericObjectChoiceField (#22537)
* refactor(forms): Add GenericObjectChoiceField

Replace separate scope_type/scope and parent_object_type/parent field
pairs with unified GenericObjectChoiceField. Introduce
GenericObjectFormMixin to handle GFK descriptor initialization and
assignment.

This removes redundant HTMX/queryset setup logic from ScopedForm,
VLANGroupForm, and ServiceForm by delegating GFK presentation to a
single reusable field and mixin pair. Field query param references now
use `$scope_object_id` instead of `$scope` to match the subwidget name.

Fixes #19821

* fix(forms): Skip validation on HTMX bulk-edit dependent field refresh

Render bulk-edit form unbound when an HTMX request changes a dependent
field (e.g. content type) without clicking Apply. This prevents
validation errors from surfacing before the user submits.

Cache ContentType lookups in GenericObjectChoiceField and sync widget
references before setting queryset to ensure choices land on the
rendered subwidget.

* fix(ipam): Update scope query params for GenericObjectChoiceField

Change available-prefix Add links to use `scope_content_type` and
`scope_object_id` query parameters instead of `scope_type` and `scope`.
This aligns with the GenericObjectChoiceField subwidget naming
introduced in the earlier refactor.

* refactor(models): Simplify GFK handling in clone_fields

Replace `scope_type`/`scope_id` pairs with bare `scope` GFK names in
clone_fields across models. Update CloningMixin to emit GFK subwidget
parameters (`scope_content_type`, `scope_object_id`) directly when a
GenericForeignKey appears in clone_fields.

* Update pre-populated links

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
2026-06-29 16:44:33 -04:00
Jeremy Stretch bf954f08d6 Merge branch 'main' into feature 2026-06-16 14:55:03 -04:00
Brian Tiemann ac513345b5 Closes #22436: Rename jinja2_filters/get_jinja2_context/register_jinja2_filters to drop the '2' suffix
Follow-up to #22363: align the plugin hook names with the already-renamed
JINJA_FILTERS setting (#22288) and with the rest of the codebase's 'Jinja'
spelling convention.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-12 09:20:42 -04:00
Jeremy Stretch 9f905cf842 Closes #22288: Rename JINJA2_FILTERS to JINJA_FILTERS 2026-06-09 14:49:31 -04:00
bctiemann 5b6d7887f2
Closes #22351: Add jinja2_filters plugin hook and get_jinja2_context() for config template extensibility (#22363) 2026-06-05 13:29:32 -07:00
Jeremy Stretch 839259ccec
Closes #22361: Introduce ArrayAttr UI panel attribute (#22362) 2026-06-02 18:17:02 +02:00
Arthur ff26cbd521 cleanup 2026-05-22 14:12:17 -04:00
Arthur b09e8a1808 cleanup 2026-05-22 14:12:17 -04:00
Martin Hauser d2545c4bda
docs(plugin): Update plugin installation examples (#22185) 2026-05-14 13:36:00 -07:00
Jeremy Stretch e50aff8736
Documentation cleanup (#22127) 2026-05-06 16:58:08 -05:00
Jason Novinger 28a11f6aad
Fixes #21357: Add support for registering custom model actions (#21560)
* Add ModelAction and register_model_actions() API for custom permission actions

* Add ObjectTypeSplitMultiSelectWidget and RegisteredActionsWidget

* Integrate registered actions into ObjectPermissionForm

* Add JavaScript for registered actions show/hide

* Register custom actions for DataSource, Device, and VirtualMachine

* Add tests for ModelAction and register_model_actions

* Refine registered actions widget UI

- Use verbose labels (App | Model) for action group headers
- Simplify template layout with h5 headers instead of cards
- Consolidate Standard/Custom/Additional Actions into single Actions fieldset

* Hide custom actions field when no applicable models selected

The entire field row is now hidden when no selected object types
have registered custom actions, avoiding an empty "Custom actions"
label.

* Add documentation for custom model actions

- Add plugin development guide for registering custom actions
- Update admin permissions docs to mention custom actions UI
- Add docstrings to ModelAction and register_model_actions

* Add RESERVED_ACTIONS constant and fix dedup in registered actions

- Define RESERVED_ACTIONS in users/constants.py for the four built-in
  permission actions (view, add, change, delete)
- Replace hardcoded action lists in ObjectPermissionForm with the constant
- Fix duplicate action names in clean() when the same action is registered
  across multiple models (e.g. render_config for Device and VirtualMachine)
- Fix template substring matching bug in objectpermission.html detail view
  by passing RESERVED_ACTIONS through view context for proper list membership

* Fix shared action pre-selection and additional actions leakage on edit

* Prevent duplicate action registration in register_model_actions()

* Remove stale comment in RegisteredActionsWidget

* Rebuild frontend assets after rebase onto feature

* Refactor SplitMultiSelectWidget to use class attributes for widget classes

* Reject reserved action names in register_model_actions()

* Show all registered actions with enable/disable instead of show/hide

* Validate action name is not empty and clarify RESERVED_ACTIONS origin

* Adapt custom actions panel for declarative layout system

Convert the ObjectPermission detail view to use the new panel-based
layout from #21568. Add ObjectPermissionCustomActionsPanel that
cross-references assigned object types with the model_actions registry
to display which models each custom action applies to.

Also fix dark-mode visibility of disabled action checkboxes in the
permission form by overriding Bootstrap's disabled opacity.

* Flatten registered actions UI and declare via Meta.permissions

Implement two changes requested in review of #21560:

1. Use Meta.permissions for action declaration
   - Add Meta.permissions to DataSource, Device, and VirtualMachine
   - register_models() auto-registers actions from Meta.permissions
   - Remove explicit register_model_actions() calls from apps.py
   - Add get_action_model_map() utility to utilities/permissions.py

2. Flatten the ObjectPermission form UI
   - Show a single deduplicated list of action checkboxes (one per
     unique action name) instead of grouped-by-model checkboxes
   - RegisteredActionsWidget uses create_option() to inject model_keys
     and help_text; JS enables/disables based on selected object types
   - render_field.html bypasses outer wrapper for registeredactionswidget
     so widget emits rows with identical DOM structure to CRUD checkboxes
   - Unchecking a model now also unchecks unsupported action checkboxes

Fixes #21357

* Address review feedback on registered actions

- Sort model_keys in data-models attribute for deterministic output
- Rename registered_actions field label to 'Registered actions'
- Target object_types selected list via data-object-types-selected
  attribute instead of hardcoded DOM ID
- Reduce setTimeout delay to 0ms since moveOption() is synchronous

* Consolidate ObjectPermission detail view actions panel

Merge ObjectPermissionActionsPanel and ObjectPermissionCustomActionsPanel
into a single Actions panel that shows CRUD booleans and all registered
actions in one table, matching the form's consolidated layout.

Also fix data-object-types-selected attribute value (True -> 'true') and
update plugin docs to show Meta.permissions as the primary registration
approach.

* Address additional bot review feedback

- clean() collects all validation errors before raising instead of stopping at the first
- Fix stale admin docs (still referenced "Custom actions" and "grouped by model")

* Update netbox/netbox/registry.py

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>

* Fix model_actions registry to use set operations

The registry was changed to defaultdict(set) but the registration
code still used list methods. Update .append() to .add() and fix
tests to use set-compatible access patterns.

* Rename permission migrations for clarity

* Move ModelAction validation into __post_init__

* Drop model name from permission descriptions

* Simplify ObjectPermission form and remove custom widgets

Replace the dynamic UI with standard BooleanField checkboxes for each
registered action. No custom widgets, no JavaScript, no template
changes.

- Remove RegisteredActionsWidget, ObjectTypeSplitMultiSelectWidget,
  and registeredActions.ts
- Use dynamic BooleanFields for registered actions (renders identically
  to CRUD checkboxes)
- Move action-resolution logic from panel to ObjectPermission model
- Remove object-type cross-validation from form clean()
- Remove unused get_action_model_map utility

* Remove register_model_actions from public API

Meta.permissions is the documented approach for plugins. The
register_model_actions function is now an internal implementation
detail.

* Sort registered actions and improve test coverage

Sort action names alphabetically for stable display order. Add tests
for cloning, empty registry, and models_csv output.

* Add help_text to registered action checkboxes

* Return model_keys as list from get_registered_actions()

Move string joining to the template so callers get native
list data instead of a pre-formatted CSV string.

* Improve detail view: human-friendly descriptions and additional actions

Return dicts from get_registered_actions() with help_text and verbose
model names. Add get_additional_actions() for manually-entered actions
that aren't CRUD or registered. Show both in the Actions panel.

* Renumber permission migrations after feature merge

Resolve migration conflicts with default_ordering_indexes migrations.
Renumber to 0023 (core), 0232 (dcim), 0056 (virtualization) and
update dependencies.

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
2026-04-13 08:37:09 -04:00
Jeremy Stretch 06c90cb86a
Closes #21847: Correct webhook documentation for deprecated keys (#21848) 2026-04-07 15:58:45 +02:00
Jeremy Stretch bcc410d99f
Closes #20924: Ready UI components for use by plugins (#21827)
* Misc cleanup

* Include permissions in TemplatedAttr context

* Introduce CircuitTerminationPanel to replace generic panel

* Replace all instantiations of Panel with TemplatePanel

* Misc cleanup for layouts

* Enable specifying column grid width

* Panel.render() should pass the request to render_to_string()

* CopyContent does not need to override render()

* Avoid setting mutable panel actions

* Catch exceptions raised when rendering embedded plugin content

* Handle panel title when object is not available

* Introduce should_render() method on Panel class

* Misc cleanup

* Pass the value returned by get_context() to should_render()

* Yet more cleanup

* Fix typos

* Clean up object attrs

* Replace candidate template panels with ObjectAttributesPanel subclasses

* Add tests for object attrs

* Remove beta warning

* PluginContentPanel should not call should_render()

* Clean up AddObject

* speed.html should reference value for port_speed

* Address PR feedback
2026-04-06 15:35:18 -04:00
Jeremy Stretch b62c5e1ac4 Merge branch 'main' into feature 2026-04-01 13:22:52 -04:00
Martin Hauser 0455e14c29 docs(plugins): Use @register_search in plugin search docs
Align the plugin search example with the recommended registration
pattern used in the general search documentation and NetBox core.

Replace the legacy `indexes = [...]` example with decorator-based
registration to make the preferred approach clearer for plugin authors.
2026-03-31 16:55:27 -04:00
bctiemann 3320e07b70
Closes #21284: Add deprecation note to webhooks documentation (#21491)
* Add searchable deprecation comments on request_id and username fields in EventContext

* Add deprecation note in webhooks documentation

* Expand deprecation note/warning

* Add version number to deprecation warning

* Add deprecation warning to two other places
2026-02-20 19:52:42 +01:00
Jeremy Stretch 6f2ba5c75c Merge branch 'main' into feature 2026-01-06 13:05:07 -05:00
Jeremy Stretch f510e40428
Closes #21047: Add compatibility matrix to plugin setup instructions (#21048) 2025-12-29 11:39:51 -06:00
Jeremy Stretch f56015e03d
Closes #13182: Support PrimaryModel and OrganizationalModel in plugins (#20919) 2025-12-09 13:17:21 -08:00
Jeremy Stretch cc935dbfab
Closes #20926: Rename and clean up GraphQL filters (#20935) 2025-12-08 13:40:43 -06:00
Jason Novinger 7eefb07554
Closes #7604: Add filter modifier dropdowns for advanced lookup operators (#20747)
* Fixes #7604: Add filter modifier dropdowns for advanced lookup operators

Implements dynamic filter modifier UI that allows users to select lookup operators
(exact, contains, starts with, regex, negation, empty/not empty) directly in filter
forms without manual URL parameter editing.

Supports filters for all scalar types and strings, as well as some
related object filters. Explicitly does not support filters on fields
that use APIWidget. That has been broken out in to follow up work.

**Backend:**
- FilterModifierWidget: Wraps form widgets with lookup modifier dropdown
- FilterModifierMixin: Auto-enhances filterset fields with appropriate lookups
- Extended lookup support: Adds negation (n), regex, iregex, empty_true/false lookups
- Field-type-aware: CharField gets text lookups, IntegerField gets comparison operators, etc.

**Frontend:**
- TypeScript handler syncs modifier dropdown with URL parameters
- Dynamically updates form field names (serial → serial__ic) on modifier change
- Flexible-width modifier dropdowns with semantic CSS classes

* Remove extraneous TS comments

* Fix import order

* Fix CircuitFilterForm inheritance

* Enable filter form modifiers on DCIM models

* Enable filter form modifiers on Tenancy models

* Enable filter form modifiers on Wireless models

* Enable filter form modifiers on IPAM models

* Enable filter form modifiers on VPN models

* Enable filter form modifiers on Virtualization models

* Enable filter form modifiers on Circuit models

* Enable filter form modifiers on Users models

* Enable filter form modifiers on Core models

* Enable filter form modifiers on Extras models

* Add ChoiceField support to FilterModifierMixin

Enable filter modifiers for single-choice ChoiceFields in addition to the
existing MultipleChoiceField support. ChoiceFields can now display modifier
dropdowns with "Is", "Is Not", "Is Empty", and "Is Not Empty" options when
the corresponding FilterSet defines those lookups.

The mixin correctly verifies lookup availability against the FilterSet, so
modifiers only appear when multiple lookup options are actually supported.
Currently most FilterSets only define 'exact' for single-choice fields, but
this change enables future FilterSet enhancements to expose additional
lookups for ChoiceFields.

* Address PR feedback: Replace global filterset mappings with registry

* Address PR feedback: Move FilterModifierMixin into base filter form classes

Incorporates FilterModifierMixin into NetBoxModelFilterSetForm and FilterForm,
making filter modifiers automatic for all filter forms throughout the application.

* Fix filter modifier form submission bug with 'action' field collision

Forms with a field named "action" (e.g., ObjectChangeFilterForm) were causing
the form.action property to be shadowed by the field element, resulting in
[object HTMLSelectElement] appearing in the URL path.

Use form.getAttribute('action') instead of form.action to reliably retrieve
the form's action URL without collision from form fields.

Fixes form submission on /core/changelog/ and any other forms with an 'action'
field using filter modifiers.

* Address PR feedback: Move FORM_FIELD_LOOKUPS to module-level constant

Extracts the field type to lookup mappings from FilterModifierMixin class
attribute to a module-level constant for better reusability.

* Address PR feedback: Refactor and consolidate field filtering logic

Consolidated field enhancement logic in FilterModifierMixin by:
- Creating QueryField marker type (CharField subclass) for search fields
- Updating FilterForm and NetBoxModelFilterSetForm to use QueryField for 'q'
- Moving all skip logic into _get_lookup_choices() to return empty list for
  fields that shouldn't be enhanced
- Removing separate _should_skip_field() method
- Removing unused field_name parameter from _get_lookup_choices()
- Replacing hardcoded field name check ('q') with type-based detection

* Address PR feedback: Refactor applied_filters to use FORM_FIELD_LOOKUPS

* Address PR feedback: Rename FilterModifierWidget parameter to widget

* Fix registry pattern to use model identifiers as keys

Changed filterset registration to use model identifiers ('{app_label}.{model_name}')
as registry keys instead of form classes, matching NetBox's pattern for search indexes.

* Address PR feedback: refactor brittle test for APISelect useage

Now checks if widget is actually APISelect, rather than trying to infer
from the class name.

* Refactor register_filterset to be more generic and simple

* Remove unneeded imports left from earlier registry work

* Update app registry for new `filtersets` store

* Remove unused star import, leftover from earlier work

* Enables filter modifiers on APISelect based fields

* Support filter modifiers for ChoiceField

* Include MODIFIER_EMPTY_FALSE/_TRUE in __all__

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>

* Fix filterset registration for doubly-registered models

* Removed explicit checks against QueryField and [Null]BooleanField

I did add them to FORM_FIELD_LOOKUPS, though, to underscore that they
were considered and are intentially empty for future devs.

* Switch to sentence case for filter pill text

* Fix applied_filters template tag to use field-type-specific lookup labelsresolves

E.g. resolves gt="after" for dates vs "greater than" for numbers

* Verifies that filter pills for exact matches (no lookup
Add test for exact lookup filter pill rendering

* Add guard for FilterModifierWidget with no lookups

* Remove comparison symbols from numeric filter labels

* Match complete tags in widget rendering test assertions

* Check all expected lookups in field enhancement tests

* Move register_filterset to netbox.plugins.registration

* Require registered filterset for filter modifier enhancements

Updates FilterModifierMixin to only enhance form fields when the
associated model has a registered filterset. This provides plugin
safety by ensuring unregistered plugin filtersets fall back to
simple filters without lookup modifiers.

Test changes:
- Create TestModel and TestFilterSet using BaseFilterSet for
automatic lookup generation
- Import dcim.filtersets to ensure Device filterset registration
- Adjust tag field expectations to match actual Device filterset
(has exact/n but not empty lookups)

* Attempt to resolve static conflicts

* Move register_filterset() back to utilities.filtersets

* Add register_filterset() to plugins documentation for filtersets

* Reorder import statements

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
2025-12-05 15:13:37 -05:00
Jeremy Stretch 917280d1d3 Add plugin dev docs for UI components 2025-11-07 15:39:40 -05:00
Jeremy Stretch 068d493cc6 Merge branch 'main' into feature 2025-10-29 13:47:01 -04:00
Jo 80f03daad6
Improved docs on background jobs on instances (#20489) 2025-10-29 10:15:49 -07:00
Jo 56d9146323
Fixes #20499: Documented ObjectListView quick search feature for plugins (#20500) 2025-10-26 20:59:59 -05:00
Jeremy Stretch 37a9d03348 Merge branch 'main' into feature 2025-10-14 13:54:47 -04:00
Johannes Erwerle b70f1211ab Fixed wrong link in plugin filtersets documentation 2025-10-06 10:03:47 -04:00
Jeremy Stretch 57a7afd548 Merge branch 'main' into feature 2025-09-16 12:00:48 -04:00
Jo 37644eed3f
Extended plugin development documentation regarding bulk edit/delete buttons in tables 2025-09-12 08:22:16 +02:00
Jeremy Stretch c0e4d1c1e3
Closes #16137: Remove `is_staff` boolean from User model (#20306)
* Closes #16137: Remove is_staff boolean from User model

* Remove default is_staff value from UserManager.create_user()

* Restore staff_only on MenuItem

* Introduce IsSuperuser API permission to replace IsAdminUser

* Update and improve RQ task API view tests

* Remove is_staff attribute assignment from RemoteUserBackend
2025-09-10 16:51:59 -04:00
Jeremy Stretch ec9da88134 Closes #19095: Introduce support for Python 3.13 & 3.14 2025-09-08 15:36:12 -04:00
mr1716 1eeede0931
Update Grammar 2025-09-07 08:35:59 -04:00
bctiemann 8f8ca805c4
Merge pull request #20209 from netbox-community/20092-mkdocs-cleanup
Closes #20092: Clean up `mkdocs` warnings
2025-08-29 17:23:50 -04:00
Jeremy Stretch 6e6c02f98c Fix invalid link 2025-08-29 13:59:55 -04:00
Jeremy Stretch 29ea88eb94 Closes #20115: Support the use of ArrayColumn for plugin tables 2025-08-29 13:42:55 -04:00
Jeremy Stretch a59da37ac3
Closes #20129: Enable dynamic model feature registration (#20130)
* Closes #20129: Enable dynamic model feature registration

* Correct import path for register_model_feature()
2025-08-19 17:20:32 -05:00
Jeremy Stretch 37d6c160b9
Closes #20003: Introduce mechanism to register callbacks for webhook context (#20025)
* Closes #20003: Introduce mechanism to register callbacks for webhook context

* Swap ContentType with ObjectType

* Add plugin dev documentation for webhook callbacks

* Fix tests

* Add note about namespacing webhook data
2025-08-07 16:28:53 -04:00
Jeremy Stretch 4ce47e778b
Closes #18006: Dispatch event when toggling color mode & document for plugin use (#20031) 2025-08-06 10:47:06 -05:00
Jeremy Stretch 2b7600e659 Remove old "introduced in" notices 2025-08-01 15:57:26 -04:00
Jeremy Stretch 5f8a4f6c43 Merge branch 'main' into feature 2025-07-16 09:52:58 -04:00
Jeremy Stretch 21a840c32e
Closes #19816: Implement a logging mechanism for background jobs (#19838)
* Initial work on #19816

* Use TZ-aware timestamps

* Deserialize JobLogEntry timestamp

* Repurpose RQJobStatusColumn to display job entry level badges

* Misc cleanup

* Test logging

* Refactor HTML templates

* Update documentation
2025-07-14 08:52:50 -05:00