fix: honor tenant validation during plugin imports

This commit is contained in:
2026-08-05 13:28:01 +02:00
parent f558832cd2
commit 7a018807d8
11 changed files with 139 additions and 8 deletions
+17
View File
@@ -0,0 +1,17 @@
from __future__ import annotations
def netbox_utilities_tenant_required() -> bool:
"""Return the effective tenant policy without requiring the optional plugin."""
try:
from netbox_utilities.runtime import tenant_required
except ImportError:
return False
return bool(tenant_required())
def relation_required_before_save(field, *, tenant_required: bool) -> bool:
if not tenant_required or field.name != "tenant":
return False
related_model = getattr(field.remote_field, "model", None)
return getattr(getattr(related_model, "_meta", None), "label_lower", None) == "tenancy.tenant"