forked from extern/django-helpdesk
Remove all the deprecated API related files and references
This commit is contained in:
parent
790f1fc003
commit
53ed0d3a2c
@ -1,8 +0,0 @@
|
||||
Ticket API
|
||||
==========
|
||||
|
||||
*Warning*: The django-helpdesk API is deprecated, and no longer maintained. See https://github.com/django-helpdesk/django-helpdesk/issues/198 for more details.
|
||||
|
||||
The API will be removed in January 2016 - you should instead build an integration with eg django-rest-framework.
|
||||
|
||||
For details on the current API including usage instructions and command syntax, see the file ``templates/helpdesk/api_help.html``, or visit http://helpdesk/api/help/.
|
@ -16,7 +16,6 @@ Contents
|
||||
settings
|
||||
spam
|
||||
custom_fields
|
||||
api
|
||||
contributing
|
||||
|
||||
|
||||
@ -49,7 +48,7 @@ Customers (who are not 'staff' users in Django) can:
|
||||
3. Review open and closed requests they submitted
|
||||
|
||||
Staff Capabilities
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
If a user is a staff member, they get general helpdesk access, including:
|
||||
|
||||
|
@ -42,7 +42,6 @@ If you want to override the default settings for your users, create ``HELPDESK_D
|
||||
'email_on_ticket_assign': True,
|
||||
'email_on_ticket_change': True,
|
||||
'login_view_ticketlist': True,
|
||||
'email_on_ticket_apichange': True,
|
||||
'tickets_per_page': 25
|
||||
}
|
||||
|
||||
|
@ -532,12 +532,6 @@ class UserSettingsForm(forms.Form):
|
||||
required=False,
|
||||
)
|
||||
|
||||
email_on_ticket_apichange = forms.BooleanField(
|
||||
label=_('E-mail me when a ticket is changed via the API?'),
|
||||
help_text=_('If a ticket is altered by the API, do you want to receive an e-mail?'),
|
||||
required=False,
|
||||
)
|
||||
|
||||
tickets_per_page = forms.IntegerField(
|
||||
label=_('Number of tickets to show per page'),
|
||||
help_text=_('How many tickets do you want to see on the Ticket List page?'),
|
||||
|
@ -17,7 +17,6 @@ if not isinstance(DEFAULT_USER_SETTINGS, dict):
|
||||
'email_on_ticket_assign': True,
|
||||
'email_on_ticket_change': True,
|
||||
'login_view_ticketlist': True,
|
||||
'email_on_ticket_apichange': True,
|
||||
'tickets_per_page': 25
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,6 @@
|
||||
<div id='footer' class="row">
|
||||
<div class="col-md-2">{% include "helpdesk/attribution.html" %}</div>
|
||||
<div class="col-md-2"><a href='{% url 'helpdesk:rss_index' %}'><img src='{% static "helpdesk/rss_icon.png" %}' width='14' height='14' alt='{% trans "RSS Icon" %}' title='{% trans "RSS Feeds" %}' border='0' />{% trans "RSS Feeds" %}</a></div>
|
||||
<div class="col-md-2"><s><a href='{% url 'helpdesk:api_help' %}'>{% trans "API" %}</a></s></div>
|
||||
{% if user.is_superuser %}<div class="col-md-2"><a href='{% url 'helpdesk:system_settings' %}'>{% trans "System Settings" %}</a></div>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,277 +0,0 @@
|
||||
{% extends "helpdesk/help_base.html" %}
|
||||
|
||||
{% block title %}django-helpdesk API Documentation{% endblock %}
|
||||
{% block heading %}django-helpdesk API Documentation{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Contents</h2>
|
||||
|
||||
<ul>
|
||||
<li><a href='#introduction'>Introduction</a></li>
|
||||
<li><a href='#request'>Request Basics & Authentication</a></li>
|
||||
<li><a href='#response'>Responses</a></li>
|
||||
<li><a href='#methods'>Method Documentation</a>
|
||||
<ul>
|
||||
<li><a href='#method_create_ticket'>create_ticket</a></li>
|
||||
<li><a href='#method_delete_ticket'>delete_ticket</a></li>
|
||||
<li><a href='#method_hold_ticket'>hold_ticket</a></li>
|
||||
<li><a href='#method_unhold_ticket'>unhold_ticket</a></li>
|
||||
<li><a href='#method_add_followup'>add_followup</a></li>
|
||||
<li><a href='#method_resolve'>resolve</a></li>
|
||||
<li><a href='#method_list_queues'>list_queues</a></li>
|
||||
<li><a href='#method_find_user'>find_user</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<h2 id='warning'>Deprecation Warning</h2>
|
||||
|
||||
<P>This API has been deprecated and will be removed in January 2016. Please <a href='https://github.com/django-helpdesk/django-helpdesk/issues/198'>See the GitHub Issue Tracker</a> for more details.</p>
|
||||
<P>Do <strong>not</strong> build new integrations using this API.</p>
|
||||
|
||||
<p>We recommend using django-rest-framework or similar for all integrations.</p>
|
||||
|
||||
<h2 id='introduction'>Introduction</h2>
|
||||
|
||||
<p>django-helpdesk provides a powerful <acronym title='Application Programming Interface'>API</acronym> to allow you to interact with your helpdesk tickets by a means not otherwise provided by the helpdesk.</p>
|
||||
|
||||
<p>For example, you may use this API to implement a system to automatically open a ticket when an invoice is raised in your invoicing system, or to automatically close a ticket from an instant messenger application.</p>
|
||||
|
||||
<p>Your use of this system is open-ended: most business cases should be addressible with a little bit of coding to allow you to interact nicely with your helpdesk.</p>
|
||||
|
||||
<h2 id='request'>Request Basics & Authentication</h2>
|
||||
|
||||
<p>All requests to the API must be made using <acroynm title='HyperText Transfer Protocol'>HTTP</acronym> POST requests. Any request that is not made using POST will raise an error.</p>
|
||||
|
||||
<p>Your requests must be made up of the following elements:</p>
|
||||
|
||||
<ol>
|
||||
<li>A <em>method</em>, or action. This tells the API what core functionality to execute.</li>
|
||||
<li>A <em>username</em> and <em>password</em> which are valid and active within your helpdesk system. You may wish to create a specific API user just for API usage.</li>
|
||||
<li>A set of <em>data</em> to be saved into the database. This data will vary from request to request, and is outlined in <a href='#methods'>Methods</a> below.</li>
|
||||
</ol>
|
||||
|
||||
<p>To build your request, send a HTTP POST request to <em>{% url 'helpdesk:api' "method" %}</em>, where <em>method</em> is the name of a <a href='#methods'>valid method</a> from the list below.</p>
|
||||
|
||||
<p>Your POST must include both <em>user</em> and <em>password</em> parameters.</p>
|
||||
|
||||
<p>A sample request for the method <em>hold_ticket</em> may look like this:</p>
|
||||
|
||||
<ul>
|
||||
<li>A HTTP POST to <em>{% url 'helpdesk:api' "hold_ticket" %}</em></li>
|
||||
<li>A set of POST data containing:<ul>
|
||||
<li>username=susan</li>
|
||||
<li>password=fido</li>
|
||||
<li>ticket=31794</li>
|
||||
</ul></li>
|
||||
</ul>
|
||||
|
||||
<p>To complete this from a command-line using the <a href='http://curl.haxx.se/'>cURL</a> application, you may use a command such as this:</p>
|
||||
|
||||
<pre>/usr/bin/curl {% url 'helpdesk:api' "hold_ticket" %} --data "user=susan&password=fido&ticket=31794"</pre>
|
||||
|
||||
<p>In <a href='http://www.php.net/'>PHP</a>, providing you have access to the <a href='http://www.php.net/curl'>cURL libraries</a>, you may use code such as this:</p>
|
||||
|
||||
<pre><?php
|
||||
$api = curl_init();
|
||||
curl_setopt($api, CURLOPT_URL, "{% url 'helpdesk:api' "hold_ticket" %}");
|
||||
curl_setopt($api, CURLOPT_POST, 1);
|
||||
curl_setopt($api, CURLOPT_POSTFIELDS, "user=susan&password=fido&ticket=31794");
|
||||
$result = curl_exec($api);
|
||||
curl_close($api);
|
||||
echo $result;
|
||||
?></pre>
|
||||
|
||||
<p>Note that cURL expects all data to be urlencoded, this is left as an exercise for the reader.</p>
|
||||
|
||||
<h2 id='response'>Responses</h2>
|
||||
|
||||
<p>The API system makes proper use of the following HTTP response codes:</p>
|
||||
|
||||
<dl>
|
||||
<dt>200</dt>
|
||||
<dd>OK - Data updated successfully</dd>
|
||||
|
||||
<dt>400</dt>
|
||||
<dd>ERROR - Generic error. See returned text for details</dd>
|
||||
|
||||
<dt>404</dt>
|
||||
<dd>ERROR - Data not found (eg, incorrect ticket). See returned text for details</dd>
|
||||
|
||||
<dt>403</dt>
|
||||
<dd>ERROR - Invalid permissions (eg, incorrect username and/or password)</dd>
|
||||
|
||||
<dt>405</dt>
|
||||
<dd>ERROR - Invalid method. You probably tried using GET, PUT or DELETE however we require POST.</dd>
|
||||
</dl>
|
||||
|
||||
<p>Responses will have one of two content-types:</p>
|
||||
|
||||
<dl>
|
||||
<dt>text/plain</dt>
|
||||
<dd>Any error messages, or simple responses (eg a ticket ID)</dd>
|
||||
|
||||
<dt>text/json</dt>
|
||||
<dd>Any complex responses, such as a list of data.</dd>
|
||||
</dl>
|
||||
|
||||
<h2 id='methods'>Method Documentation</h2>
|
||||
|
||||
<p>The following public methods are available for use via the API. Each of them requires <a href='#request'>a valid request and authentication</a>, and each has it's own parameters as described below.</p>
|
||||
|
||||
<ul>
|
||||
<li><a href='#method_create_ticket'>create_ticket</a></li>
|
||||
<li><a href='#method_delete_ticket'>delete_ticket</a></li>
|
||||
<li><a href='#method_hold_ticket'>hold_ticket</a></li>
|
||||
<li><a href='#method_unhold_ticket'>unhold_ticket</a></li>
|
||||
<li><a href='#method_add_followup'>add_followup</a></li>
|
||||
<li><a href='#method_resolve'>resolve</a></li>
|
||||
<li><a href='#method_list_queues'>list_queues</a></li>
|
||||
<li><a href='#method_find_user'>find_user</a></li>
|
||||
</ul>
|
||||
|
||||
<h3 id='method_create_ticket'>create_ticket</h3>
|
||||
|
||||
<p>This method creates a new helpdesk ticket.</p>
|
||||
|
||||
<h4>Parameters</h4>
|
||||
|
||||
<dl>
|
||||
<dt>queue</dt>
|
||||
<dd>Queue ID (use <a href='#method_list_queues'>list_queues</a> to get queue ID's) - this is an integer field.</dd>
|
||||
|
||||
<dt>title</dt>
|
||||
<dd>Title or header of this ticket. Character field, maximum 100 characters.</dd>
|
||||
|
||||
<dt>submitter_email</dt>
|
||||
<dd>(Optional) e-mail address of the person submitting this ticket. This e-mail address will receive copies of all public updates to this ticket, and will receive a notification when the ticket is created.</dd>
|
||||
|
||||
<dt>assigned_to</dt>
|
||||
<dd>(Optional) Integer ID of the user to which this ticket should be assigned. Use <a href='#method_find_user'>find_user</a> to find a user ID from a username.</dd>
|
||||
|
||||
<dt>priority</dt>
|
||||
<dd>(Optional) Priority as an integer from 1 (high) to 5 (low). Defaults to 3 if no priority given.</dd>
|
||||
</dl>
|
||||
|
||||
<h4>Response</h4>
|
||||
|
||||
<p>This method responds with <strong>plain-text</strong>.</p>
|
||||
|
||||
<p>If you receive a 200 OK <a href='#response'>response</a>, then the content of the response will be the ticket ID.</p>
|
||||
|
||||
<h3 id='method_delete_ticket'>delete_ticket</h3>
|
||||
|
||||
<p>When given a ticket ID and confirmation, this method will delete a ticket entirely. This also deletes any followups, attachments, and other details.</p>
|
||||
|
||||
<h4>Parameters</h4>
|
||||
|
||||
<dl>
|
||||
<dt>ticket</dt>
|
||||
<dd>The numeric ticket ID to be deleted</dd>
|
||||
|
||||
<dt>confirm</dt>
|
||||
<dd>You must provide this field, with any value, to enable deletion to continue</dd>
|
||||
</dl>
|
||||
|
||||
<h4>Response</h4>
|
||||
|
||||
<p>A standard <a href='#response'>200 OK response</a> is given on success, or an error message on failure.</p>
|
||||
|
||||
<h3 id='method_hold_ticket'>hold_ticket</h3>
|
||||
|
||||
<p>If a ticket needs to be placed on hold, preventing it from being escalated, use this method.</p>
|
||||
|
||||
<h4>Parameters</h4>
|
||||
<dl>
|
||||
<dt>ticket</dt>
|
||||
<dd>The numeric ticket ID to be placed on hold</dd>
|
||||
</dl>
|
||||
|
||||
<h4>Response</h4>
|
||||
|
||||
<p>A standard <a href='#response'>200 OK response</a> is given on success, or an error message on failure.</p>
|
||||
|
||||
|
||||
<h3 id='method_unhold_ticket'>unhold_ticket</h3>
|
||||
|
||||
<p>If a ticket is currently on hold and you wish to remove that hold, use this method.</p>
|
||||
|
||||
<h4>Parameters</h4>
|
||||
<dl>
|
||||
<dt>ticket</dt>
|
||||
<dd>The numeric ticket ID to be taken off hold</dd>
|
||||
</dl>
|
||||
|
||||
<h4>Response</h4>
|
||||
|
||||
<p>A standard <a href='#response'>200 OK response</a> is given on success, or an error message on failure.</p>
|
||||
|
||||
|
||||
<h3 id='method_add_followup'>add_followup</h3>
|
||||
|
||||
<p>This method adds a comment / followup to a ticket. The followup can be public, in which case it is e-mailed to the submitter, or private. The followup will also be sent to others involved in the ticket: The owner and the queue notification / CC address.</p>
|
||||
|
||||
<h4>Parameters</h4>
|
||||
|
||||
<dl>
|
||||
<dt>ticket</dt>
|
||||
<dd>The numeric ticket ID to which this followup should be added</dd>
|
||||
|
||||
<dt>message</dt>
|
||||
<dd>Text of 'unlimited' length - optionally formatted with HTML - to add to the message.</dd>
|
||||
|
||||
<dt>public</dt>
|
||||
<dd>Either 'y' for public, or 'n' for private. This is optional, and it is assumed that followups are private if it is not provided. Private tickets are <strong>not</strong> e-mailed to the ticket submitter.</dd>
|
||||
</dl>
|
||||
|
||||
<h4>Response</h4>
|
||||
|
||||
<p>A standard <a href='#response'>200 OK response</a> is given on success, or an error message on failure.</p>
|
||||
|
||||
|
||||
<h3 id='method_resolve'>resolve</h3>
|
||||
|
||||
<p>This method adds a resolution to a ticket and marks it as resolved. The resolution will be e-mailed to everybody involved with the ticket, including the submitter.</p>
|
||||
|
||||
<h4>Parameters</h4>
|
||||
|
||||
<dl>
|
||||
<dt>ticket</dt>
|
||||
<dd>The numeric ticket ID to which this followup should be added</dd>
|
||||
|
||||
<dt>resolution</dt>
|
||||
<dd>Text of 'unlimited' length - optionally formatted with HTML. This is the resolution for this ticket.</dd>
|
||||
</dl>
|
||||
|
||||
<h4>Response</h4>
|
||||
|
||||
<p>A standard <a href='#response'>200 OK response</a> is given on success, or an error message on failure.</p>
|
||||
|
||||
|
||||
<h3 id='method_list_queues'>list_queues</h3>
|
||||
|
||||
<p>This method provides a JSON-parsable list of queues, letting you access the individual queue ID in order to create tickets.</p>
|
||||
|
||||
<h4>Response</h4>
|
||||
|
||||
<p>This method responds with <strong>json</strong>.</p>
|
||||
|
||||
<p>It provides a list of queues in JSON format. The fields provided are ID and Title.</p>
|
||||
|
||||
|
||||
<h3 id='method_find_user'>find_user</h3>
|
||||
|
||||
<p>When given a username, this method provides the related numeric user ID - commonly used when creating or reassigning tickets.</p>
|
||||
|
||||
<h4>Parameters</h4>
|
||||
|
||||
<dl>
|
||||
<dt>username</dt>
|
||||
<dd>The case-sensitive username of the user for which you require the user ID</dd>
|
||||
</dl>
|
||||
|
||||
<h4>Response</h4>
|
||||
|
||||
<p>This method responds with <strong>plain-text</strong>.</p>
|
||||
|
||||
<p>If you receive a 200 OK <a href='#response'>response</a>, then the content of the response will be the users ID.</p>
|
||||
{% endblock %}
|
@ -13,7 +13,7 @@ from django.contrib.auth import views as auth_views
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
from helpdesk import settings as helpdesk_settings
|
||||
from helpdesk.views import feeds, staff, public, api, kb
|
||||
from helpdesk.views import feeds, staff, public, kb
|
||||
|
||||
|
||||
class DirectTemplateView(TemplateView):
|
||||
@ -183,10 +183,6 @@ urlpatterns += [
|
||||
|
||||
|
||||
urlpatterns += [
|
||||
url(r'^api/(?P<method>[a-z_-]+)/$',
|
||||
api.api,
|
||||
name='api'),
|
||||
|
||||
url(r'^login/$',
|
||||
auth_views.login,
|
||||
{'template_name': 'helpdesk/registration/login.html'},
|
||||
@ -218,10 +214,6 @@ if helpdesk_settings.HELPDESK_KB_ENABLED:
|
||||
]
|
||||
|
||||
urlpatterns += [
|
||||
url(r'^api/$',
|
||||
TemplateView.as_view(template_name='helpdesk/help_api.html'),
|
||||
name='api_help'),
|
||||
|
||||
url(r'^help/context/$',
|
||||
TemplateView.as_view(template_name='helpdesk/help_context.html'),
|
||||
name='help_context'),
|
||||
|
@ -1,340 +0,0 @@
|
||||
""" ..
|
||||
django-helpdesk - A Django powered ticket tracker for small enterprise.
|
||||
|
||||
(c) Copyright 2008 Jutda. All Rights Reserved. See LICENSE for details.
|
||||
|
||||
api.py - Wrapper around API calls, and core functions to provide complete
|
||||
API to third party applications.
|
||||
|
||||
The API documentation can be accessed by visiting http://helpdesk/api/help/
|
||||
(obviously, substitute helpdesk for your django-helpdesk URI), or by reading
|
||||
through templates/helpdesk/help_api.html.
|
||||
"""
|
||||
|
||||
from django.contrib.auth import authenticate
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import render
|
||||
import simplejson
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
try:
|
||||
from django.utils import timezone
|
||||
except ImportError:
|
||||
from datetime import datetime as timezone
|
||||
|
||||
from helpdesk.forms import TicketForm
|
||||
from helpdesk.lib import send_templated_mail, safe_template_context
|
||||
from helpdesk.models import Ticket, Queue, FollowUp
|
||||
|
||||
import warnings
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
STATUS_OK = 200
|
||||
|
||||
STATUS_ERROR = 400
|
||||
STATUS_ERROR_NOT_FOUND = 404
|
||||
STATUS_ERROR_PERMISSIONS = 403
|
||||
STATUS_ERROR_BADMETHOD = 405
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
def api(request, method):
|
||||
"""
|
||||
Regardless of any other paramaters, we provide a help screen
|
||||
to the user if they requested one.
|
||||
|
||||
If the user isn't looking for help, then we enforce a few conditions:
|
||||
* The request must be sent via HTTP POST
|
||||
* The request must contain a 'user' and 'password' which
|
||||
must be valid users
|
||||
* The method must match one of the public methods of the API class.
|
||||
|
||||
|
||||
THIS IS DEPRECATED AS OF DECEMBER 2015 AND WILL BE REMOVED IN JANUARY 2016.
|
||||
SEE https://github.com/django-helpdesk/django-helpdesk/issues/198 FOR DETAILS
|
||||
|
||||
"""
|
||||
|
||||
warnings.warn("django-helpdesk API will be removed in January 2016. "
|
||||
"See https://github.com/django-helpdesk/django-helpdesk/issues/198 for details.",
|
||||
category=DeprecationWarning)
|
||||
|
||||
if method == 'help':
|
||||
return render(request, template_name='helpdesk/help_api.html')
|
||||
|
||||
if request.method != 'POST':
|
||||
return api_return(STATUS_ERROR_BADMETHOD)
|
||||
|
||||
# TODO: Move away from having the username & password in every request.
|
||||
request.user = authenticate(
|
||||
username=request.POST.get('user', False),
|
||||
password=request.POST.get('password'),
|
||||
)
|
||||
|
||||
if request.user is None:
|
||||
return api_return(STATUS_ERROR_PERMISSIONS)
|
||||
|
||||
api = API(request)
|
||||
if hasattr(api, 'api_public_%s' % method):
|
||||
return getattr(api, 'api_public_%s' % method)()
|
||||
|
||||
return api_return(STATUS_ERROR)
|
||||
|
||||
|
||||
def api_return(status, text='', json=False):
|
||||
content_type = 'text/plain'
|
||||
if status == STATUS_OK and json:
|
||||
content_type = 'text/json'
|
||||
|
||||
if text is None:
|
||||
if status == STATUS_ERROR:
|
||||
text = 'Error'
|
||||
elif status == STATUS_ERROR_NOT_FOUND:
|
||||
text = 'Resource Not Found'
|
||||
elif status == STATUS_ERROR_PERMISSIONS:
|
||||
text = 'Invalid username or password'
|
||||
elif status == STATUS_ERROR_BADMETHOD:
|
||||
text = 'Invalid request method'
|
||||
elif status == STATUS_OK:
|
||||
text = 'OK'
|
||||
|
||||
r = HttpResponse(status=status, content=text, content_type=content_type)
|
||||
|
||||
if status == STATUS_ERROR_BADMETHOD:
|
||||
r.Allow = 'POST'
|
||||
|
||||
return r
|
||||
|
||||
|
||||
class API:
|
||||
|
||||
def __init__(self, request):
|
||||
self.request = request
|
||||
|
||||
def api_public_create_ticket(self):
|
||||
form = TicketForm(self.request.POST)
|
||||
form.fields['queue'].choices = [[q.id, q.title] for q in Queue.objects.all()]
|
||||
form.fields['assigned_to'].choices = [[u.id, u.get_username()] for u in User.objects.filter(is_active=True)]
|
||||
|
||||
if form.is_valid():
|
||||
ticket = form.save(user=self.request.user)
|
||||
return api_return(STATUS_OK, "%s" % ticket.id)
|
||||
else:
|
||||
return api_return(STATUS_ERROR, text=form.errors.as_text())
|
||||
|
||||
def api_public_list_queues(self):
|
||||
return api_return(STATUS_OK, simplejson.dumps([
|
||||
{"id": "%s" % q.id, "title": "%s" % q.title}
|
||||
for q in Queue.objects.all()
|
||||
]), json=True)
|
||||
|
||||
def api_public_find_user(self):
|
||||
username = self.request.POST.get('username', False)
|
||||
|
||||
try:
|
||||
u = User.objects.get(username=username)
|
||||
return api_return(STATUS_OK, "%s" % u.id)
|
||||
|
||||
except User.DoesNotExist:
|
||||
return api_return(STATUS_ERROR, "Invalid username provided")
|
||||
|
||||
def api_public_delete_ticket(self):
|
||||
if not self.request.POST.get('confirm', False):
|
||||
return api_return(STATUS_ERROR, "No confirmation provided")
|
||||
|
||||
try:
|
||||
ticket = Ticket.objects.get(id=self.request.POST.get('ticket', False))
|
||||
except Ticket.DoesNotExist:
|
||||
return api_return(STATUS_ERROR, "Invalid ticket ID")
|
||||
|
||||
ticket.delete()
|
||||
|
||||
return api_return(STATUS_OK)
|
||||
|
||||
def api_public_hold_ticket(self):
|
||||
try:
|
||||
ticket = Ticket.objects.get(id=self.request.POST.get('ticket', False))
|
||||
except Ticket.DoesNotExist:
|
||||
return api_return(STATUS_ERROR, "Invalid ticket ID")
|
||||
|
||||
ticket.on_hold = True
|
||||
ticket.save()
|
||||
|
||||
return api_return(STATUS_OK)
|
||||
|
||||
def api_public_unhold_ticket(self):
|
||||
try:
|
||||
ticket = Ticket.objects.get(id=self.request.POST.get('ticket', False))
|
||||
except Ticket.DoesNotExist:
|
||||
return api_return(STATUS_ERROR, "Invalid ticket ID")
|
||||
|
||||
ticket.on_hold = False
|
||||
ticket.save()
|
||||
|
||||
return api_return(STATUS_OK)
|
||||
|
||||
def api_public_add_followup(self):
|
||||
try:
|
||||
ticket = Ticket.objects.get(id=self.request.POST.get('ticket', False))
|
||||
except Ticket.DoesNotExist:
|
||||
return api_return(STATUS_ERROR, "Invalid ticket ID")
|
||||
|
||||
message = self.request.POST.get('message', None)
|
||||
public = self.request.POST.get('public', 'n')
|
||||
|
||||
if public not in ['y', 'n']:
|
||||
return api_return(STATUS_ERROR, "Invalid 'public' flag")
|
||||
|
||||
if not message:
|
||||
return api_return(STATUS_ERROR, "Blank message")
|
||||
|
||||
f = FollowUp(
|
||||
ticket=ticket,
|
||||
date=timezone.now(),
|
||||
comment=message,
|
||||
user=self.request.user,
|
||||
title='Comment Added',
|
||||
)
|
||||
|
||||
if public:
|
||||
f.public = True
|
||||
|
||||
f.save()
|
||||
|
||||
context = safe_template_context(ticket)
|
||||
context['comment'] = f.comment
|
||||
|
||||
messages_sent_to = []
|
||||
|
||||
if public and ticket.submitter_email:
|
||||
send_templated_mail(
|
||||
'updated_submitter',
|
||||
context,
|
||||
recipients=ticket.submitter_email,
|
||||
sender=ticket.queue.from_address,
|
||||
fail_silently=True,
|
||||
)
|
||||
messages_sent_to.append(ticket.submitter_email)
|
||||
|
||||
if public:
|
||||
for cc in ticket.ticketcc_set.all():
|
||||
if cc.email_address not in messages_sent_to:
|
||||
send_templated_mail(
|
||||
'updated_submitter',
|
||||
context,
|
||||
recipients=cc.email_address,
|
||||
sender=ticket.queue.from_address,
|
||||
fail_silently=True,
|
||||
)
|
||||
messages_sent_to.append(cc.email_address)
|
||||
|
||||
if ticket.queue.updated_ticket_cc and ticket.queue.updated_ticket_cc not in messages_sent_to:
|
||||
send_templated_mail(
|
||||
'updated_cc',
|
||||
context,
|
||||
recipients=ticket.queue.updated_ticket_cc,
|
||||
sender=ticket.queue.from_address,
|
||||
fail_silently=True,
|
||||
)
|
||||
messages_sent_to.append(ticket.queue.updated_ticket_cc)
|
||||
|
||||
if (
|
||||
ticket.assigned_to and
|
||||
self.request.user != ticket.assigned_to and
|
||||
ticket.assigned_to.usersettings.settings.get('email_on_ticket_apichange', False) and
|
||||
ticket.assigned_to.email and
|
||||
ticket.assigned_to.email not in messages_sent_to
|
||||
):
|
||||
send_templated_mail(
|
||||
'updated_owner',
|
||||
context,
|
||||
recipients=ticket.assigned_to.email,
|
||||
sender=ticket.queue.from_address,
|
||||
fail_silently=True,
|
||||
)
|
||||
|
||||
ticket.save()
|
||||
|
||||
return api_return(STATUS_OK)
|
||||
|
||||
def api_public_resolve(self):
|
||||
try:
|
||||
ticket = Ticket.objects.get(id=self.request.POST.get('ticket', False))
|
||||
except Ticket.DoesNotExist:
|
||||
return api_return(STATUS_ERROR, "Invalid ticket ID")
|
||||
|
||||
resolution = self.request.POST.get('resolution', None)
|
||||
|
||||
if not resolution:
|
||||
return api_return(STATUS_ERROR, "Blank resolution")
|
||||
|
||||
f = FollowUp(
|
||||
ticket=ticket,
|
||||
date=timezone.now(),
|
||||
comment=resolution,
|
||||
user=self.request.user,
|
||||
title='Resolved',
|
||||
public=True,
|
||||
)
|
||||
f.save()
|
||||
|
||||
context = safe_template_context(ticket)
|
||||
context['resolution'] = f.comment
|
||||
|
||||
# subject = '%s %s (Resolved)' % (ticket.ticket, ticket.title)
|
||||
|
||||
messages_sent_to = []
|
||||
|
||||
if ticket.submitter_email:
|
||||
send_templated_mail(
|
||||
'resolved_submitter',
|
||||
context,
|
||||
recipients=ticket.submitter_email,
|
||||
sender=ticket.queue.from_address,
|
||||
fail_silently=True,
|
||||
)
|
||||
messages_sent_to.append(ticket.submitter_email)
|
||||
|
||||
for cc in ticket.ticketcc_set.all():
|
||||
if cc.email_address not in messages_sent_to:
|
||||
send_templated_mail(
|
||||
'resolved_submitter',
|
||||
context,
|
||||
recipients=cc.email_address,
|
||||
sender=ticket.queue.from_address,
|
||||
fail_silently=True,
|
||||
)
|
||||
messages_sent_to.append(cc.email_address)
|
||||
|
||||
if ticket.queue.updated_ticket_cc and ticket.queue.updated_ticket_cc not in messages_sent_to:
|
||||
send_templated_mail(
|
||||
'resolved_cc',
|
||||
context,
|
||||
recipients=ticket.queue.updated_ticket_cc,
|
||||
sender=ticket.queue.from_address,
|
||||
fail_silently=True,
|
||||
)
|
||||
messages_sent_to.append(ticket.queue.updated_ticket_cc)
|
||||
|
||||
if ticket.assigned_to and \
|
||||
self.request.user != ticket.assigned_to and \
|
||||
getattr(ticket.assigned_to.usersettings.settings,
|
||||
'email_on_ticket_apichange', False) and \
|
||||
ticket.assigned_to.email and \
|
||||
ticket.assigned_to.email not in messages_sent_to:
|
||||
send_templated_mail(
|
||||
'resolved_resolved',
|
||||
context,
|
||||
recipients=ticket.assigned_to.email,
|
||||
sender=ticket.queue.from_address,
|
||||
fail_silently=True,
|
||||
)
|
||||
|
||||
ticket.resoltuion = f.comment
|
||||
ticket.status = Ticket.RESOLVED_STATUS
|
||||
|
||||
ticket.save()
|
||||
|
||||
return api_return(STATUS_OK)
|
Loading…
Reference in New Issue
Block a user