Enforce org dependency of notification template.

This commit is contained in:
Aaron Tan 2017-04-27 14:06:39 -04:00
parent 25fae0eafd
commit d0d201863b
2 changed files with 19 additions and 2 deletions

View File

@ -98,4 +98,20 @@ class Migration(migrations.Migration):
name='launch_type',
field=models.CharField(default=b'manual', max_length=20, editable=False, choices=[(b'manual', 'Manual'), (b'relaunch', 'Relaunch'), (b'callback', 'Callback'), (b'scheduled', 'Scheduled'), (b'dependency', 'Dependency'), (b'workflow', 'Workflow'), (b'sync', 'Sync'), (b'scm', 'SCM Update')]),
),
# Named URL
migrations.AlterField(
model_name='notificationtemplate',
name='name',
field=models.CharField(max_length=512),
),
migrations.AlterField(
model_name='notificationtemplate',
name='organization',
field=models.ForeignKey(related_name='notification_templates', to='main.Organization', null=True),
),
migrations.AlterUniqueTogether(
name='notificationtemplate',
unique_together=set([('organization', 'name')]),
),
]

View File

@ -27,7 +27,7 @@ logger = logging.getLogger('awx.main.models.notifications')
__all__ = ['NotificationTemplate', 'Notification']
class NotificationTemplate(CommonModel):
class NotificationTemplate(CommonModelNameNotUnique):
NOTIFICATION_TYPES = [('email', _('Email'), CustomEmailBackend),
('slack', _('Slack'), SlackBackend),
@ -41,12 +41,13 @@ class NotificationTemplate(CommonModel):
class Meta:
app_label = 'main'
unique_together = ('organization', 'name')
organization = models.ForeignKey(
'Organization',
blank=False,
null=True,
on_delete=models.SET_NULL,
on_delete=models.CASCADE,
related_name='notification_templates',
)