Limit inherited contacts to model

This commit is contained in:
Alexander Haase 2025-02-22 00:06:44 +01:00
parent 72adda1197
commit ca6b686b88

View File

@ -373,16 +373,14 @@ class ContactsMixin(models.Model):
from tenancy.models import ContactAssignment from tenancy.models import ContactAssignment
from . import NestedGroupModel from . import NestedGroupModel
filter = Q() filter = Q(
for obj in [self]: object_type=ObjectType.objects.get_for_model(self),
filter |= Q( object_id__in=(
object_type=ObjectType.objects.get_for_model(obj), self.get_ancestors(include_self=True).values_list('pk', flat=True)
object_id__in=( if (isinstance(self, NestedGroupModel) and inherited)
obj.get_ancestors(include_self=True).values_list('pk', flat=True) else [self.pk]
if (isinstance(obj, NestedGroupModel) and inherited) ),
else [obj.pk] )
),
)
return ContactAssignment.objects.filter(filter) return ContactAssignment.objects.filter(filter)