Closes #20304: Object owners #1020

Closed
opened 2026-04-05 19:53:58 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @jeremystretch on 10/20/2025

Closes: #20304

Model Changes

  • Introduce the users.OwnerGroup model (for organizing owners)
  • Introduce the users.Owner model, with M2M fields to Group and User
  • Introduce OwnerMixin to attach a ForeignKey field to users.Owner
    • Add it to the PrimaryModel, OrganizationalModel, and NestedGroupModel base classes
    • Add it to various models within the extras app which don't inherit from one of the three bases above

FilterSet Changes

  • Introduce PrimaryModelFilterSet for subclasses of PrimaryModel (for consistency with base model classes)
  • Introduce OwnerFilterMixin and add it to the three base FilterSet classes
  • Update model FilterSet classes to inherit from one of the three base FilterSet classes where appropriate

Form Changes

  • Split base form classes into separate modules under netbox.forms
  • Introduce three base model-specific form classes for each of the four form flavors (model, bulk import, bulk edit, and filterset)
    • This is necessary to avoid adding the owner field to the base classes, which derive from NetBoxModel (and it ensures consistency for future work)

Table Changes

  • Introduce PrimaryModelTable, OrganizationalModelTable, and NestedGroupModelTable base classes
    • Include an owner column on each
  • Update all model tables to inherit from their respective models' appropriate base table

REST API Serializer Changes

  • Reorganize base REST API serializer classes (no breaking changes)
    • Move NetBoxModelSerializer to netbox.api.serializers_.features
    • Move NestedGroupModelSerializer to netbox.api.serializers_.models
    • Move BulkOperationSerializer to netbox.api.serializers_.bulk
  • Introduce PrimaryModelSerializer and OrganizationalModelSerializer in netbox.api.serializers_.models for consistency with the base model classes
  • Change subclasses of NetBoxModelSerializer to inherit from PrimaryModelSerializer, OrganizationalModelSerializer, or NestedGroupModelSerializer where appropriate and add the owner field

GraphQL API Type Changes

  • Introduce users.graphql.mixins.OwnerMixin to add the owner field
  • Introduce PrimaryObjectType and NestedGroupObjectType for consistency with base model classes
  • Add OwnerMixin to PrimaryObjectType, OrganizationalObjectType, and NestedGroupObjectType
  • Update GraphQL object types to use one of the three base classes above where appropriate
    • Add OwnerMixin to GraphQL types which don't inherit from one of the three base classes but support owner assignment

Tests

  • Add tests to ensure each major resource is subclassed from the appropriate base class according to its model
  • Introduce the AdminModelViewTestCase base class
  • Add views, API, and filterset tests for the Owner and OwnerGroup models

Reviewer Notes

Boilerplate changes to apps other than users comprise a large portion (if not the majority) of this PR. Spot checking is sufficient for the following files:

  • */api/serializers_/*.py - Changed base serializer classes
  • */forms/bulk_edit.py - Changed base form classes; removed redundant form fields
  • */forms/bulk_import.py - Changed base form classes; removed redundant form fields
  • */forms/filtersets.py - Changed base form classes; updated fieldsets
  • */forms/model_forms.py - Changed base form classes; removed redundant form fields
  • */graphql/types.py - Changed base type classes
  • */tables/*.py - Changed base table & Meta classes; removed redundant table columns
  • */filtersets.py - Changed base FilterSet classes

The bulk of the important changes appear under the netbox, users, and utilities apps.

*Originally created by @jeremystretch on 10/20/2025* ### Closes: #20304 #### Model Changes - Introduce the `users.OwnerGroup` model (for organizing owners) - Introduce the `users.Owner` model, with M2M fields to Group and User - Introduce `OwnerMixin` to attach a ForeignKey field to `users.Owner` - Add it to the PrimaryModel, OrganizationalModel, and NestedGroupModel base classes - Add it to various models within the `extras` app which don't inherit from one of the three bases above #### FilterSet Changes - Introduce PrimaryModelFilterSet for subclasses of PrimaryModel (for consistency with base model classes) - Introduce `OwnerFilterMixin` and add it to the three base FilterSet classes - Update model FilterSet classes to inherit from one of the three base FilterSet classes where appropriate #### Form Changes - Split base form classes into separate modules under `netbox.forms` - Introduce three base model-specific form classes for each of the four form flavors (model, bulk import, bulk edit, and filterset) - This is necessary to avoid adding the `owner` field to the base classes, which derive from NetBoxModel (and it ensures consistency for future work) #### Table Changes - Introduce PrimaryModelTable, OrganizationalModelTable, and NestedGroupModelTable base classes - Include an `owner` column on each - Update all model tables to inherit from their respective models' appropriate base table #### REST API Serializer Changes - Reorganize base REST API serializer classes (no breaking changes) - Move NetBoxModelSerializer to `netbox.api.serializers_.features` - Move NestedGroupModelSerializer to `netbox.api.serializers_.models` - Move BulkOperationSerializer to `netbox.api.serializers_.bulk` - Introduce PrimaryModelSerializer and OrganizationalModelSerializer in `netbox.api.serializers_.models` for consistency with the base model classes - Change subclasses of NetBoxModelSerializer to inherit from PrimaryModelSerializer, OrganizationalModelSerializer, or NestedGroupModelSerializer where appropriate and add the `owner` field #### GraphQL API Type Changes - Introduce `users.graphql.mixins.OwnerMixin` to add the `owner` field - Introduce PrimaryObjectType and NestedGroupObjectType for consistency with base model classes - Add OwnerMixin to PrimaryObjectType, OrganizationalObjectType, and NestedGroupObjectType - Update GraphQL object types to use one of the three base classes above where appropriate - Add OwnerMixin to GraphQL types which don't inherit from one of the three base classes but support owner assignment #### Tests - Add tests to ensure each major resource is subclassed from the appropriate base class according to its model - Introduce the `AdminModelViewTestCase` base class - Add views, API, and filterset tests for the Owner and OwnerGroup models ### Reviewer Notes Boilerplate changes to apps other than `users` comprise a large portion (if not the majority) of this PR. Spot checking is sufficient for the following files: - `*/api/serializers_/*.py` - Changed base serializer classes - `*/forms/bulk_edit.py` - Changed base form classes; removed redundant form fields - `*/forms/bulk_import.py` - Changed base form classes; removed redundant form fields - `*/forms/filtersets.py` - Changed base form classes; updated fieldsets - `*/forms/model_forms.py` - Changed base form classes; removed redundant form fields - `*/graphql/types.py` - Changed base type classes - `*/tables/*.py` - Changed base table & Meta classes; removed redundant table columns - `*/filtersets.py` - Changed base FilterSet classes The bulk of the important changes appear under the `netbox`, `users`, and `utilities` apps.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#1020