mirror of
https://gitea.mueller.network/extern/django-helpdesk.git
synced 2024-11-25 01:13:31 +01:00
Merge pull request #1145 from timthelion/webhooks-1
API: Actually send out emails when creating followups via the API
This commit is contained in:
commit
9db89e6714
@ -1,5 +1,8 @@
|
|||||||
Integrating django-helpdesk into your application
|
Integrating django-helpdesk into your application
|
||||||
-------------------------------------------------
|
=================================================
|
||||||
|
|
||||||
|
Ticket submission with embeded iframe
|
||||||
|
-------------------------------------
|
||||||
|
|
||||||
Django-helpdesk associates an email address with each submitted ticket. If you integrate django-helpdesk directly into your django application, logged in users will automatically have their email address set when they visit the `/tickets/submit/` form. If you wish to pre-fill fields in this form, you can do so simply by setting the following query parameters:
|
Django-helpdesk associates an email address with each submitted ticket. If you integrate django-helpdesk directly into your django application, logged in users will automatically have their email address set when they visit the `/tickets/submit/` form. If you wish to pre-fill fields in this form, you can do so simply by setting the following query parameters:
|
||||||
|
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
from .forms import TicketForm
|
|
||||||
from .lib import format_time_spent, process_attachments
|
|
||||||
from .models import CustomField, FollowUp, FollowUpAttachment, Ticket
|
|
||||||
from .user import HelpdeskUser
|
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.contrib.humanize.templatetags import humanize
|
from django.contrib.humanize.templatetags import humanize
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_framework.exceptions import ValidationError
|
from rest_framework.exceptions import ValidationError
|
||||||
|
|
||||||
|
from .forms import TicketForm
|
||||||
|
from .lib import format_time_spent
|
||||||
|
from .models import CustomField, FollowUp, FollowUpAttachment, Ticket
|
||||||
|
from .user import HelpdeskUser
|
||||||
|
from .update_ticket import update_ticket
|
||||||
|
|
||||||
|
|
||||||
class DatatablesTicketSerializer(serializers.ModelSerializer):
|
class DatatablesTicketSerializer(serializers.ModelSerializer):
|
||||||
"""
|
"""
|
||||||
@ -124,20 +126,30 @@ class FollowUpSerializer(serializers.ModelSerializer):
|
|||||||
write_only=True,
|
write_only=True,
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
|
date = serializers.DateTimeField(read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = FollowUp
|
model = FollowUp
|
||||||
fields = (
|
fields = (
|
||||||
'id', 'ticket', 'date', 'title', 'comment', 'public', 'user', 'new_status', 'message_id',
|
'id', 'ticket', 'user', 'title', 'comment', 'public', 'new_status',
|
||||||
'time_spent', 'followupattachment_set', 'attachments'
|
'time_spent', 'attachments', 'followupattachment_set', 'date', 'message_id',
|
||||||
)
|
)
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
attachments = validated_data.pop('attachments', None)
|
if validated_data["user"]:
|
||||||
followup = super().create(validated_data)
|
user = validated_data["user"]
|
||||||
if attachments:
|
else:
|
||||||
process_attachments(followup, attachments)
|
user = self.context['request'].user
|
||||||
return followup
|
return update_ticket(
|
||||||
|
user=user,
|
||||||
|
ticket=validated_data["ticket"],
|
||||||
|
title=validated_data.get("title", None),
|
||||||
|
comment=validated_data.get("comment", ""),
|
||||||
|
files=validated_data.get("attachments", None),
|
||||||
|
public=validated_data.get("public", False),
|
||||||
|
new_status=validated_data.get("new_status", None),
|
||||||
|
time_spent=validated_data.get("time_spent", None),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TicketSerializer(serializers.ModelSerializer):
|
class TicketSerializer(serializers.ModelSerializer):
|
||||||
|
@ -274,15 +274,15 @@ class TicketTest(APITestCase):
|
|||||||
'followup_set': [OrderedDict([
|
'followup_set': [OrderedDict([
|
||||||
('id', 1),
|
('id', 1),
|
||||||
('ticket', 1),
|
('ticket', 1),
|
||||||
('date', '2022-06-30T23:09:44'),
|
('user', 1),
|
||||||
('title', 'Ticket Opened'),
|
('title', 'Ticket Opened'),
|
||||||
('comment', 'Test description\nMulti lines'),
|
('comment', 'Test description\nMulti lines'),
|
||||||
('public', True),
|
('public', True),
|
||||||
('user', 1),
|
|
||||||
('new_status', None),
|
('new_status', None),
|
||||||
('message_id', None),
|
|
||||||
('time_spent', None),
|
('time_spent', None),
|
||||||
('followupattachment_set', [])
|
('followupattachment_set', []),
|
||||||
|
('date', '2022-06-30T23:09:44'),
|
||||||
|
('message_id', None),
|
||||||
])],
|
])],
|
||||||
'custom_varchar': 'test',
|
'custom_varchar': 'test',
|
||||||
'custom_text': 'multi\nline',
|
'custom_text': 'multi\nline',
|
||||||
|
@ -198,11 +198,13 @@ def update_ticket(
|
|||||||
files=None,
|
files=None,
|
||||||
public=False,
|
public=False,
|
||||||
owner=-1,
|
owner=-1,
|
||||||
|
ticket_title=None,
|
||||||
priority=-1,
|
priority=-1,
|
||||||
new_status=None,
|
new_status=None,
|
||||||
time_spent=None,
|
time_spent=None,
|
||||||
due_date=None,
|
due_date=None,
|
||||||
new_checklists=None,
|
new_checklists=None,
|
||||||
|
message_id=None,
|
||||||
):
|
):
|
||||||
# We need to allow the 'ticket' and 'queue' contexts to be applied to the
|
# We need to allow the 'ticket' and 'queue' contexts to be applied to the
|
||||||
# comment.
|
# comment.
|
||||||
@ -235,7 +237,7 @@ def update_ticket(
|
|||||||
owner = ticket.assigned_to.id
|
owner = ticket.assigned_to.id
|
||||||
|
|
||||||
f = FollowUp(ticket=ticket, date=timezone.now(), comment=comment,
|
f = FollowUp(ticket=ticket, date=timezone.now(), comment=comment,
|
||||||
time_spent=time_spent)
|
time_spent=time_spent, message_id=message_id, title=title)
|
||||||
|
|
||||||
if is_helpdesk_staff(user):
|
if is_helpdesk_staff(user):
|
||||||
f.user = user
|
f.user = user
|
||||||
@ -262,15 +264,15 @@ def update_ticket(
|
|||||||
|
|
||||||
files = process_attachments(f, files) if files else []
|
files = process_attachments(f, files) if files else []
|
||||||
|
|
||||||
if title and title != ticket.title:
|
if ticket_title and ticket_title != ticket.title:
|
||||||
c = TicketChange(
|
c = TicketChange(
|
||||||
followup=f,
|
followup=f,
|
||||||
field=_('Title'),
|
field=_('Title'),
|
||||||
old_value=ticket.title,
|
old_value=ticket.title,
|
||||||
new_value=title,
|
new_value=ticket_title,
|
||||||
)
|
)
|
||||||
c.save()
|
c.save()
|
||||||
ticket.title = title
|
ticket.title = ticket_title
|
||||||
|
|
||||||
if new_status != old_status:
|
if new_status != old_status:
|
||||||
c = TicketChange(
|
c = TicketChange(
|
||||||
@ -386,4 +388,5 @@ def update_ticket(
|
|||||||
|
|
||||||
# auto subscribe user if enabled
|
# auto subscribe user if enabled
|
||||||
add_staff_subscription(user, ticket)
|
add_staff_subscription(user, ticket)
|
||||||
|
return f
|
||||||
|
|
||||||
|
@ -54,6 +54,9 @@ class FollowUpViewSet(viewsets.ModelViewSet):
|
|||||||
pagination_class = ConservativePagination
|
pagination_class = ConservativePagination
|
||||||
permission_classes = [IsAdminUser]
|
permission_classes = [IsAdminUser]
|
||||||
|
|
||||||
|
def perform_create(self, serializer):
|
||||||
|
serializer.save(user=self.request.user)
|
||||||
|
|
||||||
|
|
||||||
class FollowUpAttachmentViewSet(viewsets.ModelViewSet):
|
class FollowUpAttachmentViewSet(viewsets.ModelViewSet):
|
||||||
queryset = FollowUpAttachment.objects.all()
|
queryset = FollowUpAttachment.objects.all()
|
||||||
|
@ -1214,11 +1214,10 @@ def hold_ticket(request, ticket_id, unhold=False):
|
|||||||
ticket.on_hold = True
|
ticket.on_hold = True
|
||||||
title = _('Ticket placed on hold')
|
title = _('Ticket placed on hold')
|
||||||
|
|
||||||
f = FollowUp(
|
f = update_ticket(
|
||||||
ticket=ticket,
|
|
||||||
user=request.user,
|
user=request.user,
|
||||||
|
ticket=ticket,
|
||||||
title=title,
|
title=title,
|
||||||
date=timezone.now(),
|
|
||||||
public=True,
|
public=True,
|
||||||
)
|
)
|
||||||
f.save()
|
f.save()
|
||||||
|
Loading…
Reference in New Issue
Block a user