From 5bf83e8b64969e9fe546962690eaf6076775bf45 Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Mon, 11 Apr 2016 16:02:42 -0400 Subject: [PATCH 1/2] cascade delete labels --- awx/main/access.py | 4 ++-- awx/main/models/label.py | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/awx/main/access.py b/awx/main/access.py index 8cf71f9f88..183643532f 100644 --- a/awx/main/access.py +++ b/awx/main/access.py @@ -1204,7 +1204,7 @@ class LabelAccess(BaseAccess): def can_read(self, obj): if self.user.is_superuser: return True - return obj.organization and obj.organization.accessible_by(self.user, {'read': True}) + return obj.organization.accessible_by(self.user, {'read': True}) def can_add(self, data): if self.user.is_superuser: @@ -1224,7 +1224,7 @@ class LabelAccess(BaseAccess): if self.can_add(data) is False: return False - return obj.organization and obj.organization.accessible_by(self.user, ALL_PERMISSIONS) + return obj.organization.accessible_by(self.user, ALL_PERMISSIONS) def can_delete(self, obj): return self.can_change(obj, None) diff --git a/awx/main/models/label.py b/awx/main/models/label.py index d21de8622e..8458e4cb23 100644 --- a/awx/main/models/label.py +++ b/awx/main/models/label.py @@ -24,11 +24,8 @@ class Label(CommonModelNameNotUnique): organization = models.ForeignKey( 'Organization', related_name='labels', - blank=True, - null=True, - default=None, help_text=_('Organization this label belongs to.'), - on_delete=models.SET_NULL, + on_delete=models.CASCADE, ) def get_absolute_url(self): From 0d0115ef5e088ed54a176e24cc94713b706f3d55 Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Tue, 12 Apr 2016 10:23:43 -0400 Subject: [PATCH 2/2] include migration --- .../migrations/0015_v300_label_changes.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 awx/main/migrations/0015_v300_label_changes.py diff --git a/awx/main/migrations/0015_v300_label_changes.py b/awx/main/migrations/0015_v300_label_changes.py new file mode 100644 index 0000000000..022ae1d73a --- /dev/null +++ b/awx/main/migrations/0015_v300_label_changes.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('main', '0014_v300_invsource_cred'), + ] + + operations = [ + migrations.AlterField( + model_name='label', + name='organization', + field=models.ForeignKey(related_name='labels', to='main.Organization', help_text='Organization this label belongs to.'), + ), + ]