mirror of
https://gitea.mueller.network/extern/django-helpdesk.git
synced 2024-11-25 01:13:31 +01:00
Merge pull request #476 from flinz/enhancements/issue-460-remerge
Enhancements: issue 460, backlink to helpdesk usersettings via unique name
This commit is contained in:
commit
719b03f186
@ -253,7 +253,7 @@ class AbstractTicketForm(CustomFieldMixin, forms.Form):
|
||||
|
||||
if ticket.assigned_to and \
|
||||
ticket.assigned_to != user and \
|
||||
ticket.assigned_to.usersettings.settings.get('email_on_ticket_assign', False) and \
|
||||
ticket.assigned_to.usersettings_helpdesk.settings.get('email_on_ticket_assign', False) and \
|
||||
ticket.assigned_to.email and \
|
||||
ticket.assigned_to.email not in messages_sent_to:
|
||||
send_templated_mail(
|
||||
|
20
helpdesk/migrations/0014_usersettings_related_name.py
Normal file
20
helpdesk/migrations/0014_usersettings_related_name.py
Normal file
@ -0,0 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('helpdesk', '0013_email_box_local_dir_and_logging'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='usersettings',
|
||||
name='user',
|
||||
field=models.OneToOneField(to=settings.AUTH_USER_MODEL, related_name='usersettings_helpdesk'),
|
||||
),
|
||||
]
|
@ -1084,10 +1084,12 @@ class UserSettings(models.Model):
|
||||
as notification preferences and other things that should probably be
|
||||
configurable.
|
||||
|
||||
We should always refer to user.usersettings.settings['setting_name'].
|
||||
We should always refer to user.usersettings_helpdesk.settings['setting_name'].
|
||||
"""
|
||||
|
||||
user = models.OneToOneField(settings.AUTH_USER_MODEL)
|
||||
user = models.OneToOneField(
|
||||
settings.AUTH_USER_MODEL,
|
||||
related_name="usersettings_helpdesk")
|
||||
|
||||
settings_pickled = models.TextField(
|
||||
_('Settings Dictionary'),
|
||||
|
130
helpdesk/tests/test_ticket_actions.py
Normal file
130
helpdesk/tests/test_ticket_actions.py
Normal file
@ -0,0 +1,130 @@
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core import mail
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test import TestCase
|
||||
from django.test.client import Client
|
||||
from helpdesk.models import CustomField, Queue, Ticket
|
||||
|
||||
try: # python 3
|
||||
from urllib.parse import urlparse
|
||||
except ImportError: # python 2
|
||||
from urlparse import urlparse
|
||||
|
||||
|
||||
class TicketActionsTestCase(TestCase):
|
||||
fixtures = ['emailtemplate.json']
|
||||
|
||||
def setUp(self):
|
||||
self.queue_public = Queue.objects.create(
|
||||
title='Queue 1',
|
||||
slug='q1',
|
||||
allow_public_submission=True,
|
||||
new_ticket_cc='new.public@example.com',
|
||||
updated_ticket_cc='update.public@example.com')
|
||||
|
||||
self.ticket_data = {
|
||||
'title': 'Test Ticket',
|
||||
'description': 'Some Test Ticket',
|
||||
}
|
||||
|
||||
self.client = Client()
|
||||
|
||||
def loginUser(self, is_staff=True):
|
||||
User = get_user_model()
|
||||
self.user = User.objects.create(
|
||||
username='User_1',
|
||||
is_staff=is_staff,
|
||||
)
|
||||
self.user.set_password('pass')
|
||||
self.user.save()
|
||||
self.client.login(username='User_1', password='pass')
|
||||
|
||||
def test_delete_ticket_staff(self):
|
||||
# make staff user
|
||||
self.loginUser()
|
||||
|
||||
"""Tests whether staff can delete tickets"""
|
||||
ticket_data = dict(queue=self.queue_public, **self.ticket_data)
|
||||
ticket = Ticket.objects.create(**ticket_data)
|
||||
ticket_id = ticket.id
|
||||
|
||||
response = self.client.get(reverse('helpdesk:delete', kwargs={'ticket_id': ticket_id}), follow=True)
|
||||
self.assertContains(response, 'Are you sure you want to delete this ticket')
|
||||
|
||||
response = self.client.post(reverse('helpdesk:delete', kwargs={'ticket_id': ticket_id}), follow=True)
|
||||
first_redirect = response.redirect_chain[0]
|
||||
first_redirect_url = first_redirect[0]
|
||||
|
||||
# Ensure we landed on the "View" page.
|
||||
# Django 1.9 compatible way of testing this
|
||||
# https://docs.djangoproject.com/en/1.9/releases/1.9/#http-redirects-no-longer-forced-to-absolute-uris
|
||||
urlparts = urlparse(first_redirect_url)
|
||||
self.assertEqual(urlparts.path, reverse('helpdesk:home'))
|
||||
|
||||
# test ticket deleted
|
||||
with self.assertRaises(Ticket.DoesNotExist):
|
||||
Ticket.objects.get(pk=ticket_id)
|
||||
|
||||
def test_update_ticket_staff(self):
|
||||
"""Tests whether staff can update ticket details"""
|
||||
|
||||
# make staff user
|
||||
self.loginUser()
|
||||
|
||||
# create second user
|
||||
User = get_user_model()
|
||||
self.user2 = User.objects.create(
|
||||
username='User_2',
|
||||
is_staff=True,
|
||||
)
|
||||
|
||||
initial_data = {
|
||||
'title': 'Private ticket test',
|
||||
'queue': self.queue_public,
|
||||
'assigned_to': self.user,
|
||||
'status': Ticket.OPEN_STATUS,
|
||||
}
|
||||
|
||||
# create ticket
|
||||
ticket = Ticket.objects.create(**initial_data)
|
||||
ticket_id = ticket.id
|
||||
|
||||
# assign new owner
|
||||
post_data = {
|
||||
'owner': self.user2.id,
|
||||
}
|
||||
response = self.client.post(reverse('helpdesk:update', kwargs={'ticket_id': ticket_id}), post_data, follow=True)
|
||||
self.assertContains(response, 'Changed Owner from User_1 to User_2')
|
||||
|
||||
# change status with users email assigned and submitter email assigned,
|
||||
# which triggers emails being sent
|
||||
ticket.assigned_to = self.user2
|
||||
ticket.submitter_email = 'submitter@test.com'
|
||||
ticket.save()
|
||||
self.user2.email = 'user2@test.com'
|
||||
self.user2.save()
|
||||
self.user.email = 'user1@test.com'
|
||||
self.user.save()
|
||||
post_data = {
|
||||
'new_status': Ticket.CLOSED_STATUS,
|
||||
'public': True
|
||||
}
|
||||
|
||||
# do this also to a newly assigned user (different from logged in one)
|
||||
ticket.assigned_to = self.user
|
||||
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')
|
||||
post_data = {
|
||||
'new_status': Ticket.OPEN_STATUS,
|
||||
'owner': self.user2.id,
|
||||
'public': 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')
|
||||
|
||||
def test_create_ticket_getform(self):
|
||||
self.loginUser()
|
||||
response = self.client.get(reverse('helpdesk:submit'), follow=True)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
# TODO this needs to be checked further
|
30
helpdesk/tests/test_usersettings.py
Normal file
30
helpdesk/tests/test_usersettings.py
Normal file
@ -0,0 +1,30 @@
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core import mail
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test import TestCase
|
||||
from django.test.client import Client
|
||||
from helpdesk.models import CustomField, Queue, Ticket
|
||||
|
||||
try: # python 3
|
||||
from urllib.parse import urlparse
|
||||
except ImportError: # python 2
|
||||
from urlparse import urlparse
|
||||
|
||||
|
||||
class TicketActionsTestCase(TestCase):
|
||||
fixtures = ['emailtemplate.json']
|
||||
|
||||
def setUp(self):
|
||||
User = get_user_model()
|
||||
self.user = User.objects.create(
|
||||
username='User_1',
|
||||
is_staff=True,
|
||||
)
|
||||
self.user.set_password('pass')
|
||||
self.user.save()
|
||||
self.client.login(username='User_1', password='pass')
|
||||
|
||||
def test_get_user_settings(self):
|
||||
|
||||
response = self.client.get(reverse('helpdesk:user_settings'), follow=True)
|
||||
self.assertContains(response, "Use the following options")
|
@ -27,7 +27,7 @@ def homepage(request):
|
||||
(request.user.is_authenticated() and
|
||||
helpdesk_settings.HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE):
|
||||
try:
|
||||
if request.user.usersettings.settings.get('login_view_ticketlist', False):
|
||||
if request.user.usersettings_helpdesk.settings.get('login_view_ticketlist', False):
|
||||
return HttpResponseRedirect(reverse('helpdesk:list'))
|
||||
else:
|
||||
return HttpResponseRedirect(reverse('helpdesk:dashboard'))
|
||||
|
@ -337,10 +337,11 @@ def return_ticketccstring_and_show_subscribe(user, ticket):
|
||||
|
||||
# check whether current user is a submitter or assigned to ticket
|
||||
assignedto_username = str(ticket.assigned_to).upper()
|
||||
submitter_email = ticket.submitter_email.upper()
|
||||
strings_to_check = list()
|
||||
if ticket.submitter_email is not None:
|
||||
submitter_email = ticket.submitter_email.upper()
|
||||
strings_to_check.append(submitter_email)
|
||||
strings_to_check.append(assignedto_username)
|
||||
strings_to_check.append(submitter_email)
|
||||
if strings_to_check.__contains__(username) or strings_to_check.__contains__(useremail):
|
||||
show_subscribe = False
|
||||
|
||||
@ -578,10 +579,10 @@ def update_ticket(request, ticket_id, public=False):
|
||||
|
||||
if (not reassigned or
|
||||
(reassigned and
|
||||
ticket.assigned_to.usersettings.settings.get(
|
||||
ticket.assigned_to.usersettings_helpdesk.settings.get(
|
||||
'email_on_ticket_assign', False))) or \
|
||||
(not reassigned and
|
||||
ticket.assigned_to.usersettings.settings.get(
|
||||
ticket.assigned_to.usersettings_helpdesk.settings.get(
|
||||
'email_on_ticket_change', False)):
|
||||
send_templated_mail(
|
||||
template_staff,
|
||||
@ -914,7 +915,7 @@ def ticket_list(request):
|
||||
return render(request, 'helpdesk/ticket_list.html', dict(
|
||||
context,
|
||||
tickets=ticket_qs,
|
||||
default_tickets_per_page=request.user.usersettings.settings.get('tickets_per_page') or 25,
|
||||
default_tickets_per_page=request.user.usersettings_helpdesk.settings.get('tickets_per_page') or 25,
|
||||
user_choices=User.objects.filter(is_active=True, is_staff=True),
|
||||
queue_choices=user_queues,
|
||||
status_choices=Ticket.STATUS_CHOICES,
|
||||
@ -965,7 +966,7 @@ def create_ticket(request):
|
||||
return HttpResponseRedirect(reverse('helpdesk:dashboard'))
|
||||
else:
|
||||
initial_data = {}
|
||||
if request.user.usersettings.settings.get('use_email_as_submitter', False) and request.user.email:
|
||||
if request.user.usersettings_helpdesk.settings.get('use_email_as_submitter', False) and request.user.email:
|
||||
initial_data['submitter_email'] = request.user.email
|
||||
if 'queue' in request.GET:
|
||||
initial_data['queue'] = request.GET['queue']
|
||||
@ -1312,7 +1313,7 @@ delete_saved_query = staff_member_required(delete_saved_query)
|
||||
|
||||
|
||||
def user_settings(request):
|
||||
s = request.user.usersettings
|
||||
s = request.user.usersettings_helpdesk
|
||||
if request.POST:
|
||||
form = UserSettingsForm(request.POST)
|
||||
if form.is_valid():
|
||||
|
Loading…
Reference in New Issue
Block a user