mirror of
https://github.com/ansible/awx.git
synced 2026-01-17 04:31:21 -03:30
work around a django-polymorphic bug that breaks certain cascades
see: #1794
This commit is contained in:
parent
0eefed80e1
commit
db1a669c68
@ -3,6 +3,7 @@
|
||||
|
||||
# Django
|
||||
from django.conf import settings # noqa
|
||||
from django.db.models.signals import pre_delete # noqa
|
||||
|
||||
# AWX
|
||||
from awx.main.models.base import * # noqa
|
||||
@ -58,6 +59,18 @@ User.add_to_class('can_access_with_errors', check_user_access_with_errors)
|
||||
User.add_to_class('accessible_objects', user_accessible_objects)
|
||||
|
||||
|
||||
def cleanup_created_modified_by(sender, **kwargs):
|
||||
# work around a bug in django-polymorphic that doesn't properly
|
||||
# handle cascades for reverse foreign keys on the polymorphic base model
|
||||
# https://github.com/django-polymorphic/django-polymorphic/issues/229
|
||||
for cls in (UnifiedJobTemplate, UnifiedJob):
|
||||
cls.objects.filter(created_by=kwargs['instance']).update(created_by=None)
|
||||
cls.objects.filter(modified_by=kwargs['instance']).update(modified_by=None)
|
||||
|
||||
|
||||
pre_delete.connect(cleanup_created_modified_by, sender=User)
|
||||
|
||||
|
||||
@property
|
||||
def user_get_organizations(user):
|
||||
return Organization.objects.filter(member_role__members=user)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user