1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 16:51:11 +03:00

Merge pull request #1807 from ryanpetrello/polymorphic_created_by_delete

restore a django-polymorphic workaround to avoid a weird cascade bug
This commit is contained in:
Ryan Petrello 2018-05-16 11:03:41 -04:00 committed by GitHub
commit f49d52ad8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)