From 51a63bc7a591288ac71c11b49fcea37fba6fc0c9 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 29 Jul 2025 11:34:00 -0400 Subject: [PATCH] model_is_public() should return False for non-core & non-plugin models --- netbox/netbox/constants.py | 15 +++++++++++++++ netbox/netbox/models/features.py | 10 ++++++++++ netbox/netbox/tests/test_model_features.py | 10 ++++++++++ 3 files changed, 35 insertions(+) diff --git a/netbox/netbox/constants.py b/netbox/netbox/constants.py index ad96a643d..75e0f4da6 100644 --- a/netbox/netbox/constants.py +++ b/netbox/netbox/constants.py @@ -1,3 +1,18 @@ +CORE_APPS = ( + 'account', + 'circuits', + 'core', + 'dcim', + 'extras', + 'ipam', + 'tenancy', + 'users', + 'utilities', + 'virtualization', + 'vpn', + 'wireless', +) + # RQ queue names RQ_QUEUE_DEFAULT = 'default' RQ_QUEUE_HIGH = 'high' diff --git a/netbox/netbox/models/features.py b/netbox/netbox/models/features.py index 11f2a43bc..b71eecaaa 100644 --- a/netbox/netbox/models/features.py +++ b/netbox/netbox/models/features.py @@ -17,7 +17,9 @@ from extras.choices import * from extras.constants import CUSTOMFIELD_EMPTY_VALUES from extras.utils import is_taggable from netbox.config import get_config +from netbox.constants import CORE_APPS from netbox.models.deletion import DeleteMixin +from netbox.plugins import PluginConfig from netbox.registry import registry from netbox.signals import post_clean from utilities.json import CustomFieldJSONEncoder @@ -651,6 +653,14 @@ registry['model_features'].update({ def model_is_public(model): + """ + Return True if the model is considered "public use;" otherwise return False. + + All non-core and non-plugin models are excluded. + """ + opts = model._meta + if opts.app_label not in CORE_APPS and not isinstance(opts.app_config, PluginConfig): + return False return not getattr(model, '_netbox_private', False) diff --git a/netbox/netbox/tests/test_model_features.py b/netbox/netbox/tests/test_model_features.py index 13934bff6..190c177ea 100644 --- a/netbox/netbox/tests/test_model_features.py +++ b/netbox/netbox/tests/test_model_features.py @@ -3,6 +3,8 @@ from django.test import TestCase from core.models import AutoSyncRecord, DataSource from extras.models import CustomLink from netbox.models.features import get_model_features, has_feature, model_is_public +from netbox.tests.dummy_plugin.models import DummyModel +from taggit.models import Tag class ModelFeaturesTestCase(TestCase): @@ -19,6 +21,14 @@ class ModelFeaturesTestCase(TestCase): self.assertTrue(getattr(AutoSyncRecord, '_netbox_private')) self.assertFalse(model_is_public(AutoSyncRecord)) + # Plugin model + self.assertFalse(hasattr(DummyModel, '_netbox_private')) + self.assertTrue(model_is_public(DummyModel)) + + # Non-core model + self.assertFalse(hasattr(Tag, '_netbox_private')) + self.assertFalse(model_is_public(Tag)) + def test_has_feature(self): """ Test the functionality of the has_feature() utility function.