Skip to content

Conversation

@jeremystretch
Copy link
Member

@jeremystretch jeremystretch commented Oct 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.

@jeremystretch jeremystretch marked this pull request as ready for review October 23, 2025 13:59
@jeremystretch jeremystretch requested review from a team and arthanson and removed request for a team October 23, 2025 13:59
@arthanson
Copy link
Collaborator

arthanson commented Oct 23, 2025

Couple small things:

  • Owner Groups Detail page should probably have an "Add Owner" button like Tenant Group Detail page.
  • In the Add new owner "Group" field under Owner could be renamed to "Owner Group" to avoid confusion with Groups, or Groups could change to "User Groups" that is how it is on CSV import.
  • The Owners / Groups are not in the search index - just making sure that is by design.
  • What are the owner groups used for (later for permissions?) right now they don't do anything. Would you want to assign ownership of an item to a group or just an individual? Not sure what owner groups are used for.

@jeremystretch
Copy link
Member Author

jeremystretch commented Oct 23, 2025

Owner Groups Detail page should probably have an "Add Owner" button like Tenant Group Detail page.

Done.

In the Add new owner "Group" field under Owner could be renamed to "Owner Group" to avoid confusion with Groups, or Groups could change to "User Groups" that is how it is on CSV import.

Made these DynamicModelMultipleChoiceFields and tweaked the label for user groups.

The Owners / Groups are not in the search index - just making sure that is by design.

For now, yes. (We don't currently include any of the admin models in the global search.)

What are the owner groups used for (later for permissions?) right now they don't do anything.

Owner groups exist simply to help organize owners. They aren't strictly needed but would be very helpful in a scenario where you have hundreds of owners to manage.

Copy link
Collaborator

@arthanson arthanson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Virtual Chassis Add / Edit is still missing the owner dropdown. Otherwise, everything else looks good.

@jeremystretch
Copy link
Member Author

Turns out we use a separate form for creating a virtual chassis, for some reason.

@arthanson arthanson merged commit be74436 into feature Oct 24, 2025
8 checks passed
@jeremystretch jeremystretch deleted the 20304-object-owners branch October 24, 2025 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants