diff --git a/docs/configuration.md b/docs/configuration.md index f70b842..bc13a04 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1,5 +1,33 @@ # Configuration Parameters +## `exempt_models` + +Default: `[]` (empty list) + +A list of models provided by other plugins which should be exempt from branching support. (Only models which support change logging need be listed; all other models are ineligible for branching support.) + +!!! warning + A model may not be exempted from branching support if it has one or more relationships to models for which branching is supported. Branching **must** be supported consistently for all inter-related models; otherwise, data corruption can occur. Configure this setting only if you have a specific need to disable branching for certain models provided by plugins. + +Models must be specified by app label and model name, as such: + +```python +exempt_models = ( + 'my_plugin.foo', + 'my_plugin.bar', +) +``` + +It is also possible to exclude _all_ models from within a plugin by substituting an asterisk (`*`) for the model name: + +```python +exempt_models = ( + 'my_plugin.*', +) +``` + +--- + ## `max_working_branches` Default: None diff --git a/netbox_branching/__init__.py b/netbox_branching/__init__.py index a17aa6c..4aeb70c 100644 --- a/netbox_branching/__init__.py +++ b/netbox_branching/__init__.py @@ -1,7 +1,7 @@ from django.conf import settings from django.core.exceptions import ImproperlyConfigured -from netbox.plugins import PluginConfig +from netbox.plugins import PluginConfig, get_plugin_config from netbox.registry import registry @@ -22,6 +22,9 @@ class AppConfig(PluginConfig): # The maximum number of branches which can be provisioned simultaneously 'max_branches': None, + # Models from other plugins which should be excluded from branching support + 'exempt_models': [], + # This string is prefixed to the name of each new branch schema during provisioning 'schema_prefix': 'branch_', } @@ -42,11 +45,20 @@ def ready(self): ) # Record all object types which support branching in the NetBox registry - if 'branching' not in registry['model_features']: - registry['model_features']['branching'] = { - k: v for k, v in registry['model_features']['change_logging'].items() - if k not in constants.EXCLUDED_APPS - } + exempt_models = ( + *constants.EXEMPT_MODELS, + *get_plugin_config('netbox_branching', 'exempt_models'), + ) + branching_models = {} + for app_label, models in registry['model_features']['change_logging'].items(): + # Wildcard exclusion for all models in this app + if f'{app_label}.*' in exempt_models: + continue + branching_models[app_label] = [ + model for model in models + if f'{app_label}.{model}' not in exempt_models + ] + registry['model_features']['branching'] = branching_models config = AppConfig diff --git a/netbox_branching/constants.py b/netbox_branching/constants.py index c7743b5..d641b63 100644 --- a/netbox_branching/constants.py +++ b/netbox_branching/constants.py @@ -10,8 +10,8 @@ # URL query parameter name QUERY_PARAM = '_branch' -# Apps which are explicitly excluded from branching -EXCLUDED_APPS = ( - 'netbox_branching', - 'netbox_changes', +# Models for which branching support is explicitly disabled +EXEMPT_MODELS = ( + 'netbox_branching.*', + 'netbox_changes.*', )