forked from extern/django-helpdesk
Merge pull request #354 from reduxionist/bug/per-queue-membership-but-no-memberships
Fix QueueMembership bug revealed by django.test's DiscoverRunner
This commit is contained in:
commit
aae2501cab
@ -17,6 +17,7 @@ class PerQueueStaffMembershipTestCase(TestCase):
|
|||||||
and user_2 with access to queue_2 containing 2 tickets
|
and user_2 with access to queue_2 containing 2 tickets
|
||||||
and superuser who should be able to access both queues
|
and superuser who should be able to access both queues
|
||||||
"""
|
"""
|
||||||
|
self.HELPDESK_ENABLE_PER_QUEUE_STAFF_MEMBERSHIP = settings.HELPDESK_ENABLE_PER_QUEUE_STAFF_MEMBERSHIP
|
||||||
settings.HELPDESK_ENABLE_PER_QUEUE_STAFF_MEMBERSHIP = True
|
settings.HELPDESK_ENABLE_PER_QUEUE_STAFF_MEMBERSHIP = True
|
||||||
self.client = Client()
|
self.client = Client()
|
||||||
User = get_user_model()
|
User = get_user_model()
|
||||||
@ -59,6 +60,12 @@ class PerQueueStaffMembershipTestCase(TestCase):
|
|||||||
assigned_to=user,
|
assigned_to=user,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
"""
|
||||||
|
Reset HELPDESK_ENABLE_PER_QUEUE_STAFF_MEMBERSHIP to original value
|
||||||
|
"""
|
||||||
|
settings.HELPDESK_ENABLE_PER_QUEUE_STAFF_MEMBERSHIP = self.HELPDESK_ENABLE_PER_QUEUE_STAFF_MEMBERSHIP
|
||||||
|
|
||||||
def test_dashboard_ticket_counts(self):
|
def test_dashboard_ticket_counts(self):
|
||||||
"""
|
"""
|
||||||
Check that the regular users' dashboard only shows 1 of the 2 queues,
|
Check that the regular users' dashboard only shows 1 of the 2 queues,
|
||||||
@ -213,9 +220,3 @@ class PerQueueStaffMembershipTestCase(TestCase):
|
|||||||
3,
|
3,
|
||||||
'Queue choices were improperly limited by queue membership for a superuser'
|
'Queue choices were improperly limited by queue membership for a superuser'
|
||||||
)
|
)
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
"""
|
|
||||||
Don't interfere with subsequent tests that do not expect this setting
|
|
||||||
"""
|
|
||||||
settings.HELPDESK_ENABLE_PER_QUEUE_STAFF_MEMBERSHIP = False
|
|
||||||
|
@ -39,7 +39,7 @@ except ImportError:
|
|||||||
|
|
||||||
from helpdesk.forms import TicketForm, UserSettingsForm, EmailIgnoreForm, EditTicketForm, TicketCCForm, EditFollowUpForm, TicketDependencyForm
|
from helpdesk.forms import TicketForm, UserSettingsForm, EmailIgnoreForm, EditTicketForm, TicketCCForm, EditFollowUpForm, TicketDependencyForm
|
||||||
from helpdesk.lib import send_templated_mail, query_to_dict, apply_query, safe_template_context
|
from helpdesk.lib import send_templated_mail, query_to_dict, apply_query, safe_template_context
|
||||||
from helpdesk.models import Ticket, Queue, FollowUp, TicketChange, PreSetReply, Attachment, SavedSearch, IgnoreEmail, TicketCC, TicketDependency
|
from helpdesk.models import Ticket, Queue, FollowUp, TicketChange, PreSetReply, Attachment, SavedSearch, IgnoreEmail, TicketCC, TicketDependency, QueueMembership
|
||||||
from helpdesk import settings as helpdesk_settings
|
from helpdesk import settings as helpdesk_settings
|
||||||
|
|
||||||
if helpdesk_settings.HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE:
|
if helpdesk_settings.HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE:
|
||||||
@ -78,9 +78,12 @@ def dashboard(request):
|
|||||||
)
|
)
|
||||||
limit_queues_by_user = helpdesk_settings.HELPDESK_ENABLE_PER_QUEUE_STAFF_MEMBERSHIP and not request.user.is_superuser
|
limit_queues_by_user = helpdesk_settings.HELPDESK_ENABLE_PER_QUEUE_STAFF_MEMBERSHIP and not request.user.is_superuser
|
||||||
if limit_queues_by_user:
|
if limit_queues_by_user:
|
||||||
unassigned_tickets = unassigned_tickets.filter(
|
try:
|
||||||
queue__in=request.user.queuemembership.queues.all(),
|
unassigned_tickets = unassigned_tickets.filter(
|
||||||
)
|
queue__in=request.user.queuemembership.queues.all(),
|
||||||
|
)
|
||||||
|
except QueueMembership.DoesNotExist:
|
||||||
|
unassigned_tickets = unassigned_tickets.none()
|
||||||
|
|
||||||
# all tickets, reported by current user
|
# all tickets, reported by current user
|
||||||
all_tickets_reported_by_current_user = ''
|
all_tickets_reported_by_current_user = ''
|
||||||
@ -92,9 +95,12 @@ def dashboard(request):
|
|||||||
|
|
||||||
Tickets = Ticket.objects
|
Tickets = Ticket.objects
|
||||||
if limit_queues_by_user:
|
if limit_queues_by_user:
|
||||||
Tickets = Tickets.filter(
|
try:
|
||||||
queue__in=request.user.queuemembership.queues.all(),
|
Tickets = Tickets.filter(
|
||||||
)
|
queue__in=request.user.queuemembership.queues.all(),
|
||||||
|
)
|
||||||
|
except QueueMembership.DoesNotExist:
|
||||||
|
Tickets = Tickets.none()
|
||||||
basic_ticket_stats = calc_basic_ticket_stats(Tickets)
|
basic_ticket_stats = calc_basic_ticket_stats(Tickets)
|
||||||
|
|
||||||
# The following query builds a grid of queues & ticket statuses,
|
# The following query builds a grid of queues & ticket statuses,
|
||||||
@ -367,7 +373,7 @@ def update_ticket(request, ticket_id, public=False):
|
|||||||
# if comment contains some django code, like "why does {% if bla %} crash",
|
# if comment contains some django code, like "why does {% if bla %} crash",
|
||||||
# then the following line will give us a crash, since django expects {% if %}
|
# then the following line will give us a crash, since django expects {% if %}
|
||||||
# to be closed with an {% endif %} tag.
|
# to be closed with an {% endif %} tag.
|
||||||
|
|
||||||
|
|
||||||
# get_template_from_string was removed in Django 1.8 http://django.readthedocs.org/en/1.8.x/ref/templates/upgrading.html
|
# get_template_from_string was removed in Django 1.8 http://django.readthedocs.org/en/1.8.x/ref/templates/upgrading.html
|
||||||
try:
|
try:
|
||||||
@ -1001,9 +1007,12 @@ def run_report(request, report):
|
|||||||
report_queryset = Ticket.objects.all().select_related()
|
report_queryset = Ticket.objects.all().select_related()
|
||||||
limit_queues_by_user = helpdesk_settings.HELPDESK_ENABLE_PER_QUEUE_STAFF_MEMBERSHIP and not request.user.is_superuser
|
limit_queues_by_user = helpdesk_settings.HELPDESK_ENABLE_PER_QUEUE_STAFF_MEMBERSHIP and not request.user.is_superuser
|
||||||
if limit_queues_by_user:
|
if limit_queues_by_user:
|
||||||
report_queryset = report_queryset.filter(
|
try:
|
||||||
queue__in=request.user.queuemembership.queues.all(),
|
report_queryset = report_queryset.filter(
|
||||||
)
|
queue__in=request.user.queuemembership.queues.all(),
|
||||||
|
)
|
||||||
|
except QueueMembership.DoesNotExist:
|
||||||
|
report_queryset = report_queryset.none()
|
||||||
|
|
||||||
from_saved_query = False
|
from_saved_query = False
|
||||||
saved_query = None
|
saved_query = None
|
||||||
@ -1065,9 +1074,12 @@ def run_report(request, report):
|
|||||||
col1heading = _('User')
|
col1heading = _('User')
|
||||||
queue_options = Queue.objects.all()
|
queue_options = Queue.objects.all()
|
||||||
if limit_queues_by_user:
|
if limit_queues_by_user:
|
||||||
queue_options = queue_options.filter(
|
try:
|
||||||
pk__in=request.user.queuemembership.queues.all(),
|
queue_options = queue_options.filter(
|
||||||
)
|
pk__in=request.user.queuemembership.queues.all(),
|
||||||
|
)
|
||||||
|
except QueueMembership.DoesNotExist:
|
||||||
|
queue_options = queue_options.none()
|
||||||
possible_options = [q.title.encode('utf-8') for q in queue_options]
|
possible_options = [q.title.encode('utf-8') for q in queue_options]
|
||||||
charttype = 'bar'
|
charttype = 'bar'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user