[WIP] Related object tabs — PoC for discussion#434
[WIP] Related object tabs — PoC for discussion#434Kani999 wants to merge 6 commits intonetboxlabs:mainfrom
Conversation
|
@Kani999 We've enabled the CLA Assistant on this repo to ensure that all contributors sign the license agreement. However this was enabled after you posted your PR. Could I ask you please to push a trivial commit to this PR in order to trigger the CLA prompt? I'm hoping that will do it and won't require the PR to be wholly resubmitted (it should trigger on any |
- 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
69c46a7 to
237e766
Compare
|
@bctiemann Hi, I pushed a trivial commit but nothing seems to have happened — the CLA prompt didn't trigger. I suspect it might be because the PR is currently marked as |
- 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.
|
@Kani999 I think the CLA may not trigger unless it's a brand-new PR. Could I please ask you to close this PR and open a new one (same description etc)? Thanks, and apologies for the extra work. |
|
Closing per @bctiemann's request above to trigger the CLA Assistant on a fresh PR. Reopening with the same description — link to follow. |
|
Reopened as #482 |
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?Commits
1cac046— Add related object tab views and templatesab29d56— Wire tab registration into plugin and fix pre-existing view bugs69c46a7— Document related object tabs in READMEImages