diff --git a/core/models.py b/core/models.py index dfd220f..17998b9 100644 --- a/core/models.py +++ b/core/models.py @@ -43,13 +43,13 @@ class MailTemplate(models.Model): template = cls.objects.filter(event=event, language='en').first() return template - def send_mail(self, to, context): + def send_mail(self, to_list: list[str], context): try: send_mail( self.subject.format(**context), self.content.format(**context), settings.DEFAULT_FROM_EMAIL, - [to], + to_list, fail_silently=False, ) except Exception as e: diff --git a/ticketing/models.py b/ticketing/models.py index 5fa4d03..6049baf 100644 --- a/ticketing/models.py +++ b/ticketing/models.py @@ -148,20 +148,19 @@ def update_team_assignment(sender, instance, created, **kwargs): return None if not instance.category or not instance.category.team: - mail_template = MailTemplate.get_template('ticket_assigned') - if not mail_template: - return None - #TODO send mail to all supporters - return None - - # assign team to ticket - instance.assigned_team = instance.category.team - instance.save() + team_addresses = list(Team.objects.filter(access_non_category_tickets=True).values_list('members__email', flat=True)) + + else: + # assign team to ticket + instance.assigned_team = instance.category.team + instance.save() + team_addresses = list(instance.category.team.members.values_list('email', flat=True)) mail_template = MailTemplate.get_template('ticket_assigned') if not mail_template: return None - mail_template.send_mail(instance.category.team.members.values_list('email', flat=True), { + + mail_template.send_mail(team_addresses, { 'ticket_id': instance.id, 'ticket_title': instance.title, 'ticket_description': instance.description, 'ticket_priority': instance.get_priority(), 'ticket_category': instance.category.name if instance.category else _('General'), 'ticket_creator_username': instance.user.username}) @@ -174,7 +173,7 @@ def send_mail_notification(sender, instance, created, **kwargs): mail_template = MailTemplate.get_template('new_ticket', instance.user.language) if not mail_template: return None - mail_template.send_mail(instance.user.email, { + mail_template.send_mail([instance.user.email], { 'ticket_id': instance.id, 'ticket_creator_username': instance.user.username, 'ticket_title': instance.title, 'ticket_description': instance.description, 'ticket_category': instance.category.name if instance.category else _('General')}) @@ -191,7 +190,7 @@ def send_mail_change_notification(sender, instance: Ticket, update_fields=None, mail_template = MailTemplate.get_template('ticket_status_change', instance.user.language) if not mail_template: return None - mail_template.send_mail(instance.user.email, { + mail_template.send_mail([instance.user.email], { 'ticket_id': instance.id, 'ticket_creator_username': instance.user.username, 'ticket_status': instance.get_status(), 'ticket_status_old': old_instance.get_status(), 'ticket_title': instance.title }) @@ -219,7 +218,7 @@ def send_mail_comment_notification(sender, instance, created, **kwargs): mail_template = MailTemplate.get_template('new_comment', instance.user.language) if not mail_template: return None - mail_template.send_mail(instance.ticket.user.email, { + mail_template.send_mail([instance.ticket.user.email], { 'ticket_id': instance.ticket.id, 'ticket_title': instance.ticket.title, 'ticket_creator_username': instance.user.username, 'comment_text': instance.text})