[WIP] Related object tabs — PoC for discussion#482
Open
Kani999 wants to merge 6 commits intonetboxlabs:mainfrom
Open
[WIP] Related object tabs — PoC for discussion#482Kani999 wants to merge 6 commits intonetboxlabs:mainfrom
Kani999 wants to merge 6 commits intonetboxlabs:mainfrom
Conversation
added 6 commits
April 21, 2026 08:40
- Add tab_views.py with combined and typed tab view factories - Combined tab shows all linked custom objects with actions, tags, column config, quick search - Typed tabs show per-COT filtered view with bulk actions and per-field filters - Auto-discover referenced models from app registry (never call get_model during registration) - Support CO-to-CO tabs (custom objects referencing other custom objects) - Badge callables use OR + distinct to avoid double-counting - Add combined_tab.html and typed_tab.html templates
- Add typed_tab_slugs to default_settings in PluginConfig - Call register_all_tabs() in ready() before super().ready() - Call inject_co_urls() and deduplicate_registry() after super().ready() - Add model_view_tabs to customobject.html for CO-to-CO tab support - Fix JournalEntryTable and ObjectChangeTable: remove unsupported user kwarg - Fix journal/changelog views to pass self.tab instead of string literals
- Add Related Object Tabs section explaining combined and typed tabs - Document typed_tab_slugs PLUGINS_CONFIG setting with example - Note that restart is required after config changes
- Replace _build_filterset_form with shared dynamic_forms.build_filterset_form_class (per prior PR netboxlabs#445 feedback / commit 26a39a5 invariant) - Extract _build_link_q helper; removes copy-pasted Q loop from _count_for_type._badge and TypedTabView.get - Drop CustomObjectType.objects.get(pk=cot_pk) refetch from typed-tab badge; use captured cot directly - Narrow bare except Exception to (OperationalError, ProgrammingError) in _count_linked and _get_linked_objects - prefetch_related('tags') in _get_linked_objects — kills per-row tag N+1 - Switch .restrict() try/except AttributeError to hasattr() guard; matches NetBox core pattern in netbox/views/generic/feature_views.py - Fix stale module docstring: typed-tab opt-in is typed_tab_slugs in PLUGINS_CONFIG, not show_tab=True
Apply .restrict(user, 'view') to linked-CO querysets so users without view permission on a referenced Custom Object model don't see its rows rendered in the related-object tab bodies. - _get_linked_objects now takes a user and restricts each per-model qs before filtering; the combined-tab view passes request.user. - TypedTabView.get restricts dynamic_model.objects before the link-Q filter so the typed-tab body is also gated. The combined-tab badge count can still include rows the user can't see; the body render itself is now restricted.
Pass a permission string into ViewTab so NetBox's core tab template tag skips the typed tab entirely for users without <app>.view_<model> permission on the underlying Custom Object model. Previously the badge count could include restricted rows while the body correctly hid them, producing a badge-vs-empty-body mismatch. The permission string is derived from the CO model resolved via model_ct_map at registration time (cot.object_type_id -> model), so no cot.get_model() call is introduced during tab registration. The combined tab is left unguarded intentionally — it aggregates across all CO types and is filtered per-row by the restrict() fix already in place.
3 tasks
|
Jan Krupa seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Integrates the standalone netbox-custom-objects-tab plugin into core netbox-custom-objects (ref: CESNET/netbox-custom-objects-tab#8).
Closes #26
What's implemented
typed_tab_slugsinPLUGINS_CONFIG.__init__.py), templates, and README documentation.Open questions for discussion
typed_tab_slugslist inPLUGINS_CONFIG. Is this the right UX, or should this be a per-COT toggle in the admin UI?OR + distinctqueries to avoid double-counting — are there performance concerns at scale?Images