Merge pull request #631 from auto-mat/profile-links-pr

Add user profile links for submiters who have profiles
This commit is contained in:
Garret Wassermann 2018-09-01 23:07:08 -04:00 committed by GitHub
commit c4fd2bd59b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 2 deletions

View File

@ -9,6 +9,7 @@ models.py - Model (and hence database) definitions. This is the core of the
from __future__ import unicode_literals
from django.contrib.auth.models import Permission
from django.contrib.auth import get_user_model
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ObjectDoesNotExist
from django.db import models
@ -581,6 +582,13 @@ class Ticket(models.Model):
depends_on__status__in=OPEN_STATUSES).count() == 0
can_be_resolved = property(_can_be_resolved)
def get_submitter_userprofile(self):
User = get_user_model()
try:
return User.objects.get(email=self.submitter_email)
except User.DoesNotExist:
return None
class Meta:
get_latest_by = "created"
ordering = ('id',)

View File

@ -38,7 +38,7 @@
<tr>
<td colspan='2'>{{ ticket.resolution|force_escape|urlizetrunc:50|linebreaksbr }}</td>
</tr>{% endif %}
<tr>
<th>{% trans "Due Date" %}</th>
<td>{{ ticket.due_date|date:"r" }} ({{ ticket.due_date|naturaltime }})</td>
@ -55,7 +55,9 @@
<tr>
<th>{% trans "Submitter E-Mail" %}</th>
<td>{{ ticket.submitter_email }}{% if user.is_superuser %} <strong><a href='{% url 'helpdesk:email_ignore_add' %}?email={{ ticket.submitter_email }}'><button type="button" class="btn btn-warning btn-xs"><i class="fa fa-eye-slash"></i>&nbsp;{% trans "Ignore" %}</button></a></strong>{% endif %}</td>
<td>{{ ticket.submitter_email }}
{% if user.is_superuser %} {% if submitter_userprofile_url %}<strong><a href='{{submitter_userprofile_url}}'><button type="button" class="btn btn-primary btn-xs"><i class="fa fa-address-book"></i>&nbsp;{% trans "Profile" %}</button></a></strong>{% endif %}
<strong><a href='{% url 'helpdesk:email_ignore_add' %}?email={{ ticket.submitter_email }}'><button type="button" class="btn btn-warning btn-xs"><i class="fa fa-eye-slash"></i>&nbsp;{% trans "Ignore" %}</button></a></strong>{% endif %}</td>
</tr>
<tr>

View File

@ -14,6 +14,7 @@ from django import VERSION as DJANGO_VERSION
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.decorators import user_passes_test
from django.contrib.contenttypes.models import ContentType
from django.urls import reverse
from django.core.exceptions import ValidationError, PermissionDenied
from django.db import connection
@ -319,8 +320,18 @@ def view_ticket(request, ticket_id):
ticketcc_string, show_subscribe = \
return_ticketccstring_and_show_subscribe(request.user, ticket)
submitter_userprofile = ticket.get_submitter_userprofile()
if submitter_userprofile is not None:
content_type = ContentType.objects.get_for_model(submitter_userprofile)
submitter_userprofile_url = reverse(
'admin:{app}_{model}_change'.format(app=content_type.app_label, model=content_type.model),
kwargs={'object_id': submitter_userprofile.id}
)
else:
submitter_userprofile_url = None
return render(request, 'helpdesk/ticket.html', {
'ticket': ticket,
'submitter_userprofile_url': submitter_userprofile_url,
'form': form,
'active_users': users,
'priorities': Ticket.PRIORITY_CHOICES,