Skip to content

Commit

Permalink
Task/WP-699: Fixes for RT ticket form/attachments (#1449)
Browse files Browse the repository at this point in the history
* Fixes for RT ticket form/attachments

* fix attachments in replies
  • Loading branch information
jarosenb authored Oct 3, 2024
1 parent 88c67db commit 68ea396
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
1 change: 0 additions & 1 deletion designsafe/apps/djangoRT/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class BaseTicketForm(forms.Form):
"""
first_name = forms.CharField(widget=forms.TextInput(), max_length=255, required=True)
last_name = forms.CharField(widget=forms.TextInput(), max_length=255, required=True)
email = forms.EmailField(widget=forms.EmailInput(), required=True)
subject = forms.CharField(widget=forms.TextInput(), max_length=255, required=True)

category_choices = (('', 'Choose one'),) + settings.TICKET_CATEGORIES
Expand Down
18 changes: 10 additions & 8 deletions designsafe/apps/djangoRT/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from designsafe.apps.djangoRT import rtUtil, forms, rtModels
from django.contrib.auth.decorators import login_required
from django.contrib import messages
from django.core.files.base import ContentFile
from django.conf import settings
from designsafe.apps.api.exceptions import ApiException
from designsafe.apps.api.views import BaseApiView
Expand Down Expand Up @@ -73,7 +74,8 @@ def ticketcreate(request):
requestor_meta = '%s %s <%s>' % (
form.cleaned_data['first_name'],
form.cleaned_data['last_name'],
form.cleaned_data['email'])
request.user.email
)

meta = (
('Opened by', request.user),
Expand All @@ -95,7 +97,7 @@ def ticketcreate(request):

ticket = rtModels.Ticket(subject=form.cleaned_data['subject'],
problem_description="\n ".join(ticket_body.splitlines()),
requestor=form.cleaned_data['email'],
requestor=request.user.email,
cc=form.cleaned_data.get('cc', ''))

logger.debug('Creating ticket for user: %s' % form.cleaned_data)
Expand All @@ -105,12 +107,12 @@ def ticketcreate(request):
if ticket_id > -1:
messages.success(request, 'Your ticket has been submitted.')
if 'attachment' in request.FILES:
f = request.FILES['attachment']
rt.replyToTicket(
ticket_id,
files=([request.FILES['attachment'].name,
request.FILES['attachment'],
mimetypes.guess_type(request.FILES['attachment'].name)],
))
files=[(f.name,
ContentFile(f.read()), f.content_type)
])

if request.user.is_authenticated:
return HttpResponseRedirect(reverse('djangoRT:ticketdetail',
Expand Down Expand Up @@ -163,8 +165,8 @@ def ticketreply(request, ticketId):
(
request.FILES['attachment'].name,
request.FILES['attachment'],
mimetypes.guess_type(request.FILES['attachment'].name),
))
request.FILES['attachment'].content_type),
)
if rt.replyToTicket(ticketId, text=reply_text, files=attachments):
return HttpResponseRedirect(reverse('djangoRT:ticketdetail',
args=[ticketId]))
Expand Down

0 comments on commit 68ea396

Please sign in to comment.