diff --git a/helpdesk/models.py b/helpdesk/models.py index fd6979f3..8e4e90d4 100644 --- a/helpdesk/models.py +++ b/helpdesk/models.py @@ -1343,6 +1343,9 @@ class KBItem(models.Model): def num_open_tickets(self): return Ticket.objects.filter(kbitem=self, status__in=(1, 2)).count() + def unassigned_tickets(self): + return Ticket.objects.filter(kbitem=self, status__in=(1, 2), assigned_to__isnull=True) + def get_markdown(self): return get_markdown(self.answer) diff --git a/helpdesk/templates/helpdesk/include/unassigned.html b/helpdesk/templates/helpdesk/include/unassigned.html index 9632ab36..743d0eb9 100644 --- a/helpdesk/templates/helpdesk/include/unassigned.html +++ b/helpdesk/templates/helpdesk/include/unassigned.html @@ -1,6 +1,5 @@ {% load i18n humanize %} -
@@ -40,3 +39,43 @@
+{% for kbitem in kbitems %} +
+
+ + {% trans "KBItem:" %} {{kbitem.title}} {% trans "Team:" %} {{kbitem.team.name}} {% trans "(pick up a ticket if you start to work on it)" %} +
+
+
+ + + + + + + + + + + + {% for ticket in kbitem.unassigned_tickets %} + + + + + + + + {% empty %} + + {% endfor %} + +
{% trans "Ticket" %}{% trans "Prority" %}{% trans "Queue" %}{% trans "Created" %}{% trans "Actions" %}
{{ ticket.id }}. {{ ticket.title }} {{ ticket.priority }}{{ ticket.queue }}{{ ticket.created|naturaltime }} + + +
{% trans "There are no unassigned tickets." %}
+
+
+ +
+{% endfor %} diff --git a/helpdesk/templates/helpdesk/ticket_list.html b/helpdesk/templates/helpdesk/ticket_list.html index 8cdfd0b5..6bb0dbd7 100644 --- a/helpdesk/templates/helpdesk/ticket_list.html +++ b/helpdesk/templates/helpdesk/ticket_list.html @@ -96,6 +96,10 @@ {% for u in user_choices %}{% endfor %} + + + {% for kbi in kb_items %}{% endfor %} +

diff --git a/helpdesk/user.py b/helpdesk/user.py index 8f3ec088..03958e41 100644 --- a/helpdesk/user.py +++ b/helpdesk/user.py @@ -2,6 +2,7 @@ from helpdesk.models import ( Ticket, Queue, KBCategory, + KBItem, ) from helpdesk import settings as helpdesk_settings @@ -35,13 +36,20 @@ class HelpdeskUser: else: return all_queues - def get_kb_categories(self): + def get_allowed_kb_categories(self): categories = [] for cat in KBCategory.objects.all(): if self.can_access_kbcategory(cat): categories.append(cat) return categories + def get_assigned_kb_items(self): + kbitems = [] + for item in KBItem.objects.all(): + if item.team and item.team.is_member(self.user): + kbitems.append(item) + return kbitems + def get_tickets_in_queues(self): return Ticket.objects.filter(queue__in=self.get_queues()) diff --git a/helpdesk/views/kb.py b/helpdesk/views/kb.py index bb9d45ce..a1bead71 100644 --- a/helpdesk/views/kb.py +++ b/helpdesk/views/kb.py @@ -21,7 +21,7 @@ def index(request): huser = user.huser_from_request(request) # TODO: It'd be great to have a list of most popular items here. return render(request, 'helpdesk/kb_index.html', { - 'kb_categories': huser.get_kb_categories(), + 'kb_categories': huser.get_allowed_kb_categories(), 'helpdesk_settings': helpdesk_settings, }) diff --git a/helpdesk/views/public.py b/helpdesk/views/public.py index 3ef9b1e9..470ae8ab 100644 --- a/helpdesk/views/public.py +++ b/helpdesk/views/public.py @@ -130,7 +130,7 @@ class Homepage(CreateTicketView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context['kb_categories'] = huser_from_request(self.request).get_kb_categories() + context['kb_categories'] = huser_from_request(self.request).get_allowed_kb_categories() return context diff --git a/helpdesk/views/staff.py b/helpdesk/views/staff.py index 0563976b..1cd7e293 100644 --- a/helpdesk/views/staff.py +++ b/helpdesk/views/staff.py @@ -103,6 +103,7 @@ def dashboard(request): showing ticket counts by queue/status, and a list of unassigned tickets with options for them to 'Take' ownership of said tickets. """ + huser = HelpdeskUser(request.user) active_tickets = Ticket.objects.select_related('queue').exclude( status__in=[Ticket.CLOSED_STATUS, Ticket.RESOLVED_STATUS], ) @@ -117,13 +118,16 @@ def dashboard(request): assigned_to=request.user, status__in=[Ticket.CLOSED_STATUS, Ticket.RESOLVED_STATUS]) - user_queues = HelpdeskUser(request.user).get_queues() + user_queues = huser.get_queues() unassigned_tickets = active_tickets.filter( assigned_to__isnull=True, + kbitem__isnull=True, queue__in=user_queues ) + kbitems = huser.get_assigned_kb_items() + # all tickets, reported by current user all_tickets_reported_by_current_user = '' email_current_user = request.user.email @@ -157,6 +161,7 @@ def dashboard(request): 'user_tickets': tickets, 'user_tickets_closed_resolved': tickets_closed_resolved, 'unassigned_tickets': unassigned_tickets, + 'kbitems': kbitems, 'all_tickets_reported_by_current_user': all_tickets_reported_by_current_user, 'basic_ticket_stats': basic_ticket_stats, }) @@ -706,6 +711,13 @@ def mass_update(request): parts = action.split('_') user = User.objects.get(id=parts[1]) action = 'assign' + if action == 'kbitem_none': + kbitem = None + action = 'set_kbitem' + if action.startswith('kbitem_'): + parts = action.split('_') + kbitem = KBItem.objects.get(id=parts[1]) + action = 'set_kbitem' elif action == 'take': user = request.user action = 'assign' @@ -735,6 +747,15 @@ def mass_update(request): public=True, user=request.user) f.save() + elif action == 'set_kbitem': + t.kbitem = kbitem + t.save() + f = FollowUp(ticket=t, + date=timezone.now(), + title=_('KBItem set in bulk update'), + public=False, + user=request.user) + f.save() elif action == 'close' and t.status != Ticket.CLOSED_STATUS: t.status = Ticket.CLOSED_STATUS t.save() @@ -917,6 +938,7 @@ def ticket_list(request): context, default_tickets_per_page=request.user.usersettings_helpdesk.tickets_per_page, user_choices=User.objects.filter(is_active=True, is_staff=True), + kb_items=KBItem.objects.all(), queue_choices=huser.get_queues(), status_choices=Ticket.STATUS_CHOICES, kbitem_choices=kbitem_choices,