[PR #20634] [MERGED] Closes #20304: Object owners #15994

Closed
opened 2025-12-30 00:25:13 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/20634
Author: @jeremystretch
Created: 10/20/2025
Status: Merged
Merged: 10/24/2025
Merged by: @arthanson

Base: featureHead: 20304-object-owners


📝 Commits (10+)

  • 8fd88b3 Introduce the Owner model
  • 27ddccb Add owner fields to applicable models
  • a2f8ddc Introduce PrimaryModelSerializer & OrganizationalModelSerializer; add owner field to serializers
  • 789139b Add 'owner' field to bulk operation forms
  • 800cf5c Add owner filters
  • a4d52b4 NestedGroupModel should inherit from NetBoxModel
  • 7d0f68c Update GraphQL types to support owner assignment
  • 6f1a845 Add missing filters
  • 6746913 ComponentType should inherit from PrimaryObjectType
  • 3a212cc Misc fixes

📊 Changes

196 files changed (+16203 additions, -3087 deletions)

View changed files

📝 contrib/openapi.json (+11697 -774)
docs/features/resource-ownership.md (+10 -0)
📝 docs/features/tenancy.md (+23 -7)
docs/models/users/owner.md (+23 -0)
docs/models/users/ownergroup.md (+9 -0)
📝 mkdocs.yml (+4 -0)
📝 netbox/circuits/api/serializers_/circuits.py (+16 -14)
📝 netbox/circuits/api/serializers_/providers.py (+9 -9)
📝 netbox/circuits/filtersets.py (+6 -6)
📝 netbox/circuits/forms/bulk_edit.py (+10 -55)
📝 netbox/circuits/forms/bulk_import.py (+18 -19)
📝 netbox/circuits/forms/filtersets.py (+17 -17)
📝 netbox/circuits/forms/model_forms.py (+18 -29)
📝 netbox/circuits/graphql/types.py (+6 -11)
netbox/circuits/migrations/0053_owner.py (+68 -0)
📝 netbox/circuits/tables/circuits.py (+8 -13)
📝 netbox/circuits/tables/providers.py (+9 -18)
📝 netbox/circuits/tables/virtual_circuits.py (+5 -8)
📝 netbox/core/api/serializers_/data.py (+4 -4)
📝 netbox/core/filtersets.py (+2 -2)

...and 80 more files

📄 Description

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/20634 **Author:** [@jeremystretch](https://github.com/jeremystretch) **Created:** 10/20/2025 **Status:** ✅ Merged **Merged:** 10/24/2025 **Merged by:** [@arthanson](https://github.com/arthanson) **Base:** `feature` ← **Head:** `20304-object-owners` --- ### 📝 Commits (10+) - [`8fd88b3`](https://github.com/netbox-community/netbox/commit/8fd88b357e8ccb9ba3419f83e4a273868a2db64a) Introduce the Owner model - [`27ddccb`](https://github.com/netbox-community/netbox/commit/27ddccbdf86c389720524c481692743fc0d6cd7b) Add owner fields to applicable models - [`a2f8ddc`](https://github.com/netbox-community/netbox/commit/a2f8ddc80e5f60734ab85284a28923554c0944fc) Introduce PrimaryModelSerializer & OrganizationalModelSerializer; add owner field to serializers - [`789139b`](https://github.com/netbox-community/netbox/commit/789139b88a229041bdaff6894d92a0b7256c0544) Add 'owner' field to bulk operation forms - [`800cf5c`](https://github.com/netbox-community/netbox/commit/800cf5cf3d1678d33085446165e194f9b27ad76e) Add owner filters - [`a4d52b4`](https://github.com/netbox-community/netbox/commit/a4d52b46ed99fab30e49b5220ba2366eaa2356ff) NestedGroupModel should inherit from NetBoxModel - [`7d0f68c`](https://github.com/netbox-community/netbox/commit/7d0f68c97f8f1095bff82f5ff7726b5dacc94902) Update GraphQL types to support owner assignment - [`6f1a845`](https://github.com/netbox-community/netbox/commit/6f1a84542cc2a78814d6b5cd81b5a5ddcfd4dc9b) Add missing filters - [`6746913`](https://github.com/netbox-community/netbox/commit/67469134a2b4cb1e0fb99cac9a302fd2c2665e11) ComponentType should inherit from PrimaryObjectType - [`3a212cc`](https://github.com/netbox-community/netbox/commit/3a212cc19261a62494d875be0e4c7b1c2eced5d9) Misc fixes ### 📊 Changes **196 files changed** (+16203 additions, -3087 deletions) <details> <summary>View changed files</summary> 📝 `contrib/openapi.json` (+11697 -774) ➕ `docs/features/resource-ownership.md` (+10 -0) 📝 `docs/features/tenancy.md` (+23 -7) ➕ `docs/models/users/owner.md` (+23 -0) ➕ `docs/models/users/ownergroup.md` (+9 -0) 📝 `mkdocs.yml` (+4 -0) 📝 `netbox/circuits/api/serializers_/circuits.py` (+16 -14) 📝 `netbox/circuits/api/serializers_/providers.py` (+9 -9) 📝 `netbox/circuits/filtersets.py` (+6 -6) 📝 `netbox/circuits/forms/bulk_edit.py` (+10 -55) 📝 `netbox/circuits/forms/bulk_import.py` (+18 -19) 📝 `netbox/circuits/forms/filtersets.py` (+17 -17) 📝 `netbox/circuits/forms/model_forms.py` (+18 -29) 📝 `netbox/circuits/graphql/types.py` (+6 -11) ➕ `netbox/circuits/migrations/0053_owner.py` (+68 -0) 📝 `netbox/circuits/tables/circuits.py` (+8 -13) 📝 `netbox/circuits/tables/providers.py` (+9 -18) 📝 `netbox/circuits/tables/virtual_circuits.py` (+5 -8) 📝 `netbox/core/api/serializers_/data.py` (+4 -4) 📝 `netbox/core/filtersets.py` (+2 -2) _...and 80 more files_ </details> ### 📄 Description ### 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 00:25:13 +01:00
adam closed this issue 2025-12-30 00:25:13 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15994