diff --git a/.gitignore b/.gitignore index d5885822..9e6dab0f 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ docs/doctrees/* .project .pydevproject .directory +*.swp # ignore demo attachments that user might have added helpdesk/attachments/ diff --git a/helpdesk/forms.py b/helpdesk/forms.py index e9d4ef64..f5d1473c 100644 --- a/helpdesk/forms.py +++ b/helpdesk/forms.py @@ -301,21 +301,27 @@ class TicketForm(AbstractTicketForm): help_text=_('This e-mail address will receive copies of all public ' 'updates to this ticket.'), ) - assigned_to = forms.ChoiceField( - widget=forms.Select(attrs={'class': 'form-control'}), - choices=(), + widget=forms.Select(attrs={'class': 'form-control'}) if not helpdesk_settings.HELPDESK_CREATE_TICKET_HIDE_ASSIGNED_TO else forms.HiddenInput(), required=False, label=_('Case owner'), help_text=_('If you select an owner other than yourself, they\'ll be ' 'e-mailed details of this ticket immediately.'), + + choices=() ) def __init__(self, *args, **kwargs): """ Add any custom fields that are defined to the form. """ - super(TicketForm, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) + self.fields['queue'].choices = [('', '--------')] + [(q.id, q.title) for q in Queue.objects.all()] + if helpdesk_settings.HELPDESK_STAFF_ONLY_TICKET_OWNERS: + assignable_users = User.objects.filter(is_active=True, is_staff=True).order_by(User.USERNAME_FIELD) + else: + assignable_users = User.objects.filter(is_active=True).order_by(User.USERNAME_FIELD) + self.fields['assigned_to'].choices = [('', '--------')] + [(u.id, u.get_username()) for u in assignable_users] self._add_form_custom_fields() def save(self, user=None): @@ -375,8 +381,8 @@ class PublicTicketForm(AbstractTicketForm): self.fields['priority'].widget = forms.HiddenInput() if hasattr(settings, 'HELPDESK_PUBLIC_TICKET_DUE_DATE'): self.fields['due_date'].widget = forms.HiddenInput() - - self._add_form_custom_fields(False) + self.fields['queue'].choices = [('', '--------')] + [ + (q.id, q.title) for q in Queue.objects.filter(allow_public_submission=True)] def save(self): """ diff --git a/helpdesk/migrations/0018_ticket_secret_key.py b/helpdesk/migrations/0018_ticket_secret_key.py new file mode 100644 index 00000000..f3b2f4ee --- /dev/null +++ b/helpdesk/migrations/0018_ticket_secret_key.py @@ -0,0 +1,28 @@ +# Generated by Django 2.0.1 on 2018-09-07 21:22 + +from django.db import migrations, models +import helpdesk.models + + +def clear_secret_keys(apps, schema_editor): + Ticket = apps.get_model("helpdesk", "Ticket") + db_alias = schema_editor.connection.alias + + for ticket in Ticket.objects.using(db_alias).all(): + ticket.secret_key='' + ticket.save() + +class Migration(migrations.Migration): + + dependencies = [ + ('helpdesk', '0017_default_owner_on_delete_null'), + ] + + operations = [ + migrations.AddField( + model_name='ticket', + name='secret_key', + field=models.CharField(default=helpdesk.models.mk_secret, max_length=36, null=True, verbose_name='Secret key needed for viewing/editing ticket by non-logged in users'), + ), + migrations.RunPython(clear_secret_keys), + ] diff --git a/helpdesk/migrations/0019_ticket_secret_key.py b/helpdesk/migrations/0019_ticket_secret_key.py new file mode 100644 index 00000000..be1dd385 --- /dev/null +++ b/helpdesk/migrations/0019_ticket_secret_key.py @@ -0,0 +1,19 @@ +# Generated by Django 2.0.1 on 2018-09-07 21:22 + +from django.db import migrations, models +import helpdesk.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('helpdesk', '0018_ticket_secret_key'), + ] + + operations = [ + migrations.AlterField( + model_name='ticket', + name='secret_key', + field=models.CharField(default=helpdesk.models.mk_secret, max_length=36, verbose_name='Secret key needed for viewing/editing ticket by non-logged in users'), + ), + ] diff --git a/helpdesk/models.py b/helpdesk/models.py index 9b0b822a..cb80219d 100644 --- a/helpdesk/models.py +++ b/helpdesk/models.py @@ -21,6 +21,7 @@ from django.utils.encoding import python_2_unicode_compatible import re import six +import uuid @python_2_unicode_compatible @@ -351,6 +352,10 @@ class Queue(models.Model): pass +def mk_secret(): + return str(uuid.uuid4()) + + @python_2_unicode_compatible class Ticket(models.Model): """ @@ -480,6 +485,12 @@ class Ticket(models.Model): 'automatically by management/commands/escalate_tickets.py.'), ) + secret_key = models.CharField( + _("Secret key needed for viewing/editing ticket by non-logged in users"), + max_length=36, + default=mk_secret, + ) + def _get_assigned_to(self): """ Custom property to allow us to easily print 'Unassigned' if a ticket has no owner, or the users name if it's assigned. If the user @@ -544,11 +555,12 @@ class Ticket(models.Model): site = Site.objects.get_current() except ImproperlyConfigured: site = Site(domain='configure-django-sites.com') - return u"http://%s%s?ticket=%s&email=%s" % ( + return u"http://%s%s?ticket=%s&email=%s&key=%s" % ( site.domain, reverse('helpdesk:public_view'), self.ticket_for_url, - self.submitter_email + self.submitter_email, + self.secret_key ) ticket_url = property(_get_ticket_url) diff --git a/helpdesk/templates/helpdesk/public_create_ticket.html b/helpdesk/templates/helpdesk/public_create_ticket.html new file mode 100644 index 00000000..139657b6 --- /dev/null +++ b/helpdesk/templates/helpdesk/public_create_ticket.html @@ -0,0 +1,47 @@ +{% extends "helpdesk/public_base.html" %} +{% load i18n bootstrap %} + +{% block helpdesk_body %} + +{% if helpdesk_settings.HELPDESK_SUBMIT_A_TICKET_PUBLIC %} +
{% trans "Please provide as descriptive a title and description as possible." %}
+ + +{% trans "All fields are required." %} {% trans "Please provide as descriptive a title and description as possible." %}
+{% trans "Please provide as descriptive a title and description as possible." %}