+ subject = _('New Ticket: {} ({})'.format(ticket.title, ticket.get_type_display()))
+ ticket_detail_url = urljoin(
+ settings.SITE_URL, const.TICKET_DETAIL_URL.format(id=str(ticket.id))
+ )
+ message = _(
+ """
- """).format(body=ticket.body, user=user, url=detail_url)
+ """.format(
+ body=ticket.body.replace('\n', '
'),
+ ticket_detail_url=ticket_detail_url
+ )
+ )
+ if settings.DEBUG:
+ logger.debug(message)
+ recipient_list = [assignee.email for assignee in assignees]
send_mail_async.delay(subject, message, recipient_list, html_message=message)
-def send_ticket_action_mail_to_user(ticket):
- if not ticket.user:
- logger.error("Ticket not has user: {}".format(ticket.id))
+def send_ticket_processed_mail_to_applicant(ticket):
+ if not ticket.applicant:
+ logger.error("Not found applicant: {}({})".format(ticket.title, ticket.id))
return
- user = ticket.user
- recipient_list = [user.email]
- subject = '{}: {}'.format(_("Ticket has been reply"), ticket.title)
- message = _("""
+ subject = _('Ticket has processed: {} ({})').format(ticket.title, ticket.get_type_display())
+ message = _(
+ """
-
Your ticket has been replay
+
Your ticket has been processed
- Title: {ticket.title}
+ Ticket:
- Assignee: {ticket.assignee_display}
-
- Status: {ticket.status_display}
+ {body}
- """).format(ticket=ticket)
+ """.format(
+ body=ticket.body.replace('\n', '
'),
+ )
+ )
+ if settings.DEBUG:
+ logger.debug(message)
+ recipient_list = [ticket.applicant.email]
send_mail_async.delay(subject, message, recipient_list, html_message=message)
diff --git a/apps/users/models/user.py b/apps/users/models/user.py
index 2dcbd452d..20701acac 100644
--- a/apps/users/models/user.py
+++ b/apps/users/models/user.py
@@ -329,6 +329,28 @@ class RoleMixin:
return
OrganizationMember.objects.remove_users(current_org, [self])
+ @classmethod
+ def get_super_admins(cls):
+ return cls.objects.filter(role=cls.ROLE.ADMIN)
+
+ @classmethod
+ def get_org_admins(cls, org=None):
+ from orgs.models import Organization
+ if not isinstance(org, Organization):
+ org = current_org
+ org_admins = org.admins
+ return org_admins
+
+ @classmethod
+ def get_super_and_org_admins(cls, org=None):
+ super_admins = cls.get_super_admins()
+ super_admins_id = list(super_admins.values_list('id', flat=True))
+ org_admins = cls.get_org_admins(org)
+ org_admins_id = list(org_admins.values_list('id', flat=True))
+ admins_id = set(org_admins_id + super_admins_id)
+ admins = User.objects.filter(id__in=admins_id)
+ return admins
+
class TokenMixin:
CACHE_KEY_USER_RESET_PASSWORD_PREFIX = "_KEY_USER_RESET_PASSWORD_{}"