Merge pull request #532 from gwasser/02bugs

Fix several bugs
This commit is contained in:
Jonathan Barratt 2017-08-17 14:47:06 +07:00 committed by GitHub
commit 1b00086d6e
7 changed files with 45 additions and 5 deletions

View File

@ -81,6 +81,10 @@ These changes are visible throughout django-helpdesk
- **HELPDESK_EMAIL_FALLBACK_LOCALE** Fallback locale for templated emails when queue locale not found - **HELPDESK_EMAIL_FALLBACK_LOCALE** Fallback locale for templated emails when queue locale not found
**Default:** ``HELPDESK_EMAIL_FALLBACK_LOCALE= "en"`` **Default:** ``HELPDESK_EMAIL_FALLBACK_LOCALE= "en"``
- **QUEUE_EMAIL_BOX_UPDATE_ONLY** Only process mail with a valid tracking ID; all other mail will be ignored instead of creating a new ticket.
**Default:** ``False``
Options shown on public pages Options shown on public pages

View File

@ -117,7 +117,15 @@ def send_templated_mail(template_name,
if files: if files:
for filename, filefield in files: for filename, filefield in files:
msg.attach(filename, open(filefield.path).read()) mime = mimetypes.guess_type(filename)
if mime[0] is not None and mime[0] == "text/plain":
with open(filefield.path, 'r') as file:
content = file.read()
msg.attach(filename, content)
else:
with open(filefield.path, 'rb') as file:
content = file.read()
msg.attach(filename, content)
return msg.send(fail_silently) return msg.send(fail_silently)

View File

@ -51,7 +51,7 @@ HELPDESK_TRANSLATE_TICKET_COMMENTS = getattr(settings,
# all default google translate languages will be shown. # all default google translate languages will be shown.
HELPDESK_TRANSLATE_TICKET_COMMENTS_LANG = getattr(settings, HELPDESK_TRANSLATE_TICKET_COMMENTS_LANG = getattr(settings,
'HELPDESK_TRANSLATE_TICKET_COMMENTS_LANG', 'HELPDESK_TRANSLATE_TICKET_COMMENTS_LANG',
["en", "de", "fr", "it", "ru"]) ["en", "de", "es", "fr", "it", "ru"])
# show link to 'change password' on 'User Settings' page? # show link to 'change password' on 'User Settings' page?
HELPDESK_SHOW_CHANGE_PASSWORD = getattr(settings, 'HELPDESK_SHOW_CHANGE_PASSWORD', False) HELPDESK_SHOW_CHANGE_PASSWORD = getattr(settings, 'HELPDESK_SHOW_CHANGE_PASSWORD', False)
@ -133,6 +133,8 @@ QUEUE_EMAIL_BOX_SSL = getattr(settings, 'QUEUE_EMAIL_BOX_SSL', None)
QUEUE_EMAIL_BOX_HOST = getattr(settings, 'QUEUE_EMAIL_BOX_HOST', None) QUEUE_EMAIL_BOX_HOST = getattr(settings, 'QUEUE_EMAIL_BOX_HOST', None)
QUEUE_EMAIL_BOX_USER = getattr(settings, 'QUEUE_EMAIL_BOX_USER', None) QUEUE_EMAIL_BOX_USER = getattr(settings, 'QUEUE_EMAIL_BOX_USER', None)
QUEUE_EMAIL_BOX_PASSWORD = getattr(settings, 'QUEUE_EMAIL_BOX_PASSWORD', None) QUEUE_EMAIL_BOX_PASSWORD = getattr(settings, 'QUEUE_EMAIL_BOX_PASSWORD', None)
# only process emails with a valid tracking ID? (throws away all other mail)
QUEUE_EMAIL_BOX_UPDATE_ONLY = getattr(settings, 'QUEUE_EMAIL_BOX_UPDATE_ONLY', False) QUEUE_EMAIL_BOX_UPDATE_ONLY = getattr(settings, 'QUEUE_EMAIL_BOX_UPDATE_ONLY', False)
# only allow users to access queues that they are members of? # only allow users to access queues that they are members of?

View File

@ -1,7 +1,7 @@
{% extends "helpdesk/base.html" %} {% extends "helpdesk/base.html" %}
{% load i18n bootstrap humanize %} {% load i18n bootstrap humanize %}
{% load static from staticfiles %} {% load static from staticfiles %}
{% block helpdesk_title %}{% trans "View Ticket Details" %}{% endblock %} {% block helpdesk_title %}{{ ticket.queue.slug }}-{{ ticket.id }} : {% trans "View Ticket Details" %}{% endblock %}
{% block helpdesk_head %} {% block helpdesk_head %}
<script type='text/javascript' language='javascript'> <script type='text/javascript' language='javascript'>
$(document).ready(function() { $(document).ready(function() {

View File

@ -29,7 +29,7 @@
<th colspan='2'>{% trans "Description" %}</th> <th colspan='2'>{% trans "Description" %}</th>
</tr> </tr>
<tr> <tr>
<td id="ticket-description" colspan='2'>{{ ticket.description|force_escape|urlizetrunc:50|linebreaksbr }}</td> <td id="ticket-description" colspan='2'>{{ ticket.description|force_escape|urlizetrunc:50|num_to_link|linebreaksbr }}</td>
</tr> </tr>
{% if ticket.resolution %}<tr> {% if ticket.resolution %}<tr>

View File

@ -39,7 +39,7 @@ def num_to_link(text):
if ticket: if ticket:
style = ticket.get_status_display() style = ticket.get_status_display()
text = "%s <a href='%s' class='ticket_link_status ticket_link_status_%s'>#%s</a>%s" % ( text = "%s <a href='%s' class='ticket_link_status ticket_link_status_%s'>#%s</a>%s" % (
text[:match.start()], url, style, match.groups()[0], text[match.end():]) text[:match.start() + 1], url, style, match.groups()[0], text[match.end():])
return mark_safe(text) return mark_safe(text)
register = template.Library() register = template.Library()

View File

@ -10,6 +10,8 @@ try: # python 3
except ImportError: # python 2 except ImportError: # python 2
from urlparse import urlparse from urlparse import urlparse
from helpdesk.templatetags.ticket_to_link import num_to_link
class TicketActionsTestCase(TestCase): class TicketActionsTestCase(TestCase):
fixtures = ['emailtemplate.json'] fixtures = ['emailtemplate.json']
@ -122,6 +124,30 @@ class TicketActionsTestCase(TestCase):
response = self.client.post(reverse('helpdesk:update', kwargs={'ticket_id': ticket_id}), post_data, follow=True) response = self.client.post(reverse('helpdesk:update', kwargs={'ticket_id': ticket_id}), post_data, follow=True)
self.assertContains(response, 'Changed Status from Open to Closed') self.assertContains(response, 'Changed Status from Open to Closed')
def test_num_to_link(self):
"""Test that we are correctly expanding links to tickets from IDs"""
# make staff user
self.loginUser()
initial_data = {
'title': 'Some private ticket',
'queue': self.queue_public,
'assigned_to': self.user,
'status': Ticket.OPEN_STATUS,
}
# create ticket
ticket = Ticket.objects.create(**initial_data)
ticket_id = ticket.id
# generate the URL text
result = num_to_link('this is ticket#%s' % ticket_id)
self.assertEqual(result, "this is ticket <a href='/helpdesk/tickets/%s/' class='ticket_link_status ticket_link_status_Open'>#%s</a>" % (ticket_id, ticket_id))
result2 = num_to_link('whoa another ticket is here #%s huh' % ticket_id)
self.assertEqual(result2, "whoa another ticket is here <a href='/helpdesk/tickets/%s/' class='ticket_link_status ticket_link_status_Open'>#%s</a> huh" % (ticket_id, ticket_id))
def test_create_ticket_getform(self): def test_create_ticket_getform(self):
self.loginUser() self.loginUser()
response = self.client.get(reverse('helpdesk:submit'), follow=True) response = self.client.get(reverse('helpdesk:submit'), follow=True)