mirror of
https://github.com/netbox-community/netbox.git
synced 2025-09-06 14:23:36 -06:00
model_is_public() should return False for non-core & non-plugin models
This commit is contained in:
parent
57dff90aae
commit
51a63bc7a5
@ -1,3 +1,18 @@
|
|||||||
|
CORE_APPS = (
|
||||||
|
'account',
|
||||||
|
'circuits',
|
||||||
|
'core',
|
||||||
|
'dcim',
|
||||||
|
'extras',
|
||||||
|
'ipam',
|
||||||
|
'tenancy',
|
||||||
|
'users',
|
||||||
|
'utilities',
|
||||||
|
'virtualization',
|
||||||
|
'vpn',
|
||||||
|
'wireless',
|
||||||
|
)
|
||||||
|
|
||||||
# RQ queue names
|
# RQ queue names
|
||||||
RQ_QUEUE_DEFAULT = 'default'
|
RQ_QUEUE_DEFAULT = 'default'
|
||||||
RQ_QUEUE_HIGH = 'high'
|
RQ_QUEUE_HIGH = 'high'
|
||||||
|
@ -17,7 +17,9 @@ from extras.choices import *
|
|||||||
from extras.constants import CUSTOMFIELD_EMPTY_VALUES
|
from extras.constants import CUSTOMFIELD_EMPTY_VALUES
|
||||||
from extras.utils import is_taggable
|
from extras.utils import is_taggable
|
||||||
from netbox.config import get_config
|
from netbox.config import get_config
|
||||||
|
from netbox.constants import CORE_APPS
|
||||||
from netbox.models.deletion import DeleteMixin
|
from netbox.models.deletion import DeleteMixin
|
||||||
|
from netbox.plugins import PluginConfig
|
||||||
from netbox.registry import registry
|
from netbox.registry import registry
|
||||||
from netbox.signals import post_clean
|
from netbox.signals import post_clean
|
||||||
from utilities.json import CustomFieldJSONEncoder
|
from utilities.json import CustomFieldJSONEncoder
|
||||||
@ -651,6 +653,14 @@ registry['model_features'].update({
|
|||||||
|
|
||||||
|
|
||||||
def model_is_public(model):
|
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)
|
return not getattr(model, '_netbox_private', False)
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,6 +3,8 @@ from django.test import TestCase
|
|||||||
from core.models import AutoSyncRecord, DataSource
|
from core.models import AutoSyncRecord, DataSource
|
||||||
from extras.models import CustomLink
|
from extras.models import CustomLink
|
||||||
from netbox.models.features import get_model_features, has_feature, model_is_public
|
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):
|
class ModelFeaturesTestCase(TestCase):
|
||||||
@ -19,6 +21,14 @@ class ModelFeaturesTestCase(TestCase):
|
|||||||
self.assertTrue(getattr(AutoSyncRecord, '_netbox_private'))
|
self.assertTrue(getattr(AutoSyncRecord, '_netbox_private'))
|
||||||
self.assertFalse(model_is_public(AutoSyncRecord))
|
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):
|
def test_has_feature(self):
|
||||||
"""
|
"""
|
||||||
Test the functionality of the has_feature() utility function.
|
Test the functionality of the has_feature() utility function.
|
||||||
|
Loading…
Reference in New Issue
Block a user