def _create_ticket_for_pi_request(user): """ This is a stop-gap solution for https://collab.tacc.utexas.edu/issues/8327. """ rt = rtUtil.DjangoRt() subject = "Chameleon PI Eligibility Request: %s" % user['username'] ticket = rtModels.Ticket(subject=subject, problem_description="", requestor="*****@*****.**") rt.createTicket(ticket)
def _create_ticket_for_pi_request(self, user): """ This is a stop-gap solution for https://collab.tacc.utexas.edu/issues/8327. """ rt = rtUtil.DjangoRt() subject = f"Chameleon PI Eligibility Request: {user.username}" problem_description = ( "This PI Eligibility request can be reviewed at " "https://www.chameleoncloud.org/admin/chameleon/pieligibility/") ticket = rtModels.Ticket( subject=subject, problem_description=problem_description, requestor="*****@*****.**", ) rt.createTicket(ticket)
def ticketcreateguest(request): rt = rtUtil.DjangoRt() data = {} if request.user.is_authenticated(): return HttpResponseRedirect(reverse('djangoRT:ticketcreate'), ) if request.method == 'POST': form = forms.TicketGuestForm(request.POST, request.FILES) if form.is_valid(): ticket = rtModels.Ticket( subject=form.cleaned_data['subject'], problem_description=form.cleaned_data['problem_description'], requestor=form.cleaned_data['email']) ticket_id = rt.createTicket(ticket) if ticket_id > -1: if 'attachment' in request.FILES: rt.replyToTicket(ticket_id, files=([ request.FILES['attachment'].name, request.FILES['attachment'], mimetypes.guess_type( request.FILES['attachment'].name) ], )) messages.add_message( request, messages.SUCCESS, 'Ticket #%s has been successfully created. We will respond to your request as soon as possible.' % ticket_id) form = forms.TicketGuestForm() return render(request, 'djangoRT/ticketCreateGuest.html', {'form': form}) else: # make this cleaner probably messages.error( 'An unexpected error occurred while creating your ticket. Please try again.' ) data['first_name'] = form.cleaned_data['first_name'] data['last_name'] = form.cleaned_data['last_name'] data['requestor'] = ticket.requestor data['subject'] = ticket.subject data['problem_description'] = ticket.problem_description data['cc'] = ticket.cc form = forms.TicketGuestForm(data) else: form = forms.TicketGuestForm(initial=data) return render(request, 'djangoRT/ticketCreateGuest.html', {'form': form})
def _create_ticket_for_pending_allocation(self, requestor, problem_description, owner): rt = rtUtil.DjangoRt() subject = ( "More information required to approve your Chameleon allocation request" ) ticket = rtModels.Ticket( subject=subject, problem_description= "Ticket created to contact the PI for more information.", requestor=requestor, owner=owner, ) ticket_id = rt.createTicket(ticket) rt.replyToTicket(ticket_id, text=problem_description) return ticket_id
def _handle_ticket_form(request, form): """Generic ticket handling helper function. If the form is invalid: render an error to the user. If the ticket cannot be created: render an error to the user. If the ticket could be created but the attachment could not be attached: just log an error. Args: request (Request): The parent request. form (Form): The TicketForm to process. It is assumed this already has the POST/FILES data attached. Returns: The ID of the ticket created, if successful. Returns None on error. """ if not form.is_valid(): messages.error( request, "The form is invalid, ensure all required fields are provided." ) return None requestor = form.cleaned_data["email"] requestor_meta = " ".join( [ form.cleaned_data["first_name"], form.cleaned_data["last_name"], requestor, ] ) header = "\n".join( [ f"[{key}] {value}" for key, value in [ ("Opened by", request.user), ("Category", form.cleaned_data["category"]), ("Resource", "Chameleon"), ] ] ) ticket_body = f"""{header} {form.cleaned_data["problem_description"]} --- {requestor_meta} """ rt = rtUtil.DjangoRt() ticket = rtModels.Ticket( subject=form.cleaned_data["subject"], problem_description=ticket_body, requestor=requestor, cc=form.cleaned_data.get("cc", []), ) ticket_id = rt.createTicket(ticket) if ticket_id < 0: logger.error(f"Error creating ticket for {requestor}") messages.error( request, ("There was an error creating your ticket. Please try again.") ) return None logger.info(f"Created ticket #{ticket_id} for {requestor}") if "attachment" in request.FILES: attachment = request.FILES["attachment"] mime_type, encoding = mimetypes.guess_type(attachment.name) files = [(attachment.name, attachment, mime_type)] success = rt.replyToTicket(ticket_id, files=files) if not success: logger.error(f"Error adding attachment to #{ticket_id}") add_openstack_data.apply_async( kwargs={ "username": request.user.username, "ticket_id": ticket_id, }, ) messages.success( request, ( f"Ticket #{ticket_id} has been successfully created. " "We will respond to your request as soon as possible." ), ) return ticket_id
def ticketcreate(request): rt = rtUtil.DjangoRt() if not request.user.is_authenticated(): return HttpResponseRedirect(reverse('djangoRT:ticketcreateguest'), ) data = { 'email': request.user.email, 'first_name': request.user.first_name, 'last_name': request.user.last_name } if request.method == 'POST': form = forms.TicketForm(request.POST, request.FILES) if form.is_valid(): requestor_meta = '%s %s %s' % (form.cleaned_data['first_name'], form.cleaned_data['last_name'], form.cleaned_data['email']) meta = ( ('Opened by', request.user), ('Category', form.cleaned_data['category']), ('Resource', 'Chameleon'), ) header = '\n'.join('[%s] %s' % m for m in meta) ticket_body = '%s\n\n%s\n\n---\n%s' % ( header, form.cleaned_data['problem_description'], requestor_meta) region_list = [] for region in list(settings.OPENSTACK_AUTH_REGIONS.keys()): try: token = get_token(request, region=region) region_list.append( get_openstack_data(request.user.username, token, region)) except Exception as err: logger.error( f'Failed to get OpenStack data for region {region}: {err}' ) user_details = render_to_string('djangoRT/project_details.txt', {'regions': region_list}) ticket_body = ticket_body + user_details ticket = rtModels.Ticket(subject=form.cleaned_data['subject'], problem_description=ticket_body, requestor=form.cleaned_data['email'], cc=form.cleaned_data['cc']) logger.debug('Creating ticket for user: %s' % form.cleaned_data + ' with project details: ' + user_details) ticket_id = rt.createTicket(ticket) if ticket_id > -1: if 'attachment' in request.FILES: rt.replyToTicket(ticket_id, files=([request.FILES['attachment'].name,\ request.FILES['attachment'], mimetypes.guess_type(request.FILES['attachment'].name)],)) return HttpResponseRedirect( reverse('djangoRT:ticketdetail', args=[ticket_id])) else: messages.error( request, 'There was an error creating your ticket. Please try again.' ) else: messages.error(request, 'Invalid') else: form = forms.TicketForm( initial={ 'email': request.user.email, 'first_name': request.user.first_name, 'last_name': request.user.last_name }) return render(request, 'djangoRT/ticketCreate.html', {'form': form})
def ticketcreate(request): rt = rtUtil.DjangoRt() if not request.user.is_authenticated(): return HttpResponseRedirect(reverse('djangoRT:ticketcreateguest'), ) data = { 'email': request.user.email, 'first_name': request.user.first_name, 'last_name': request.user.last_name } # header = "[Ticket created from Chameleon Portal by " + request.user.first_name + " " + request.user.last_name + " (" + request.user.email + ")]\n\n" if request.method == 'POST': form = forms.TicketForm(request.POST, request.FILES) if form.is_valid(): requestor_meta = '%s %s <%s>' % ( form.cleaned_data['first_name'], form.cleaned_data['last_name'], form.cleaned_data['email']) meta = ( ('Opened by', request.user), ('Category', form.cleaned_data['category']), ('Resource', 'Chameleon'), ) header = '\n'.join('[%s] %s' % m for m in meta) ticket_body = '%s\n\n%s\n\n---\n%s' % ( header, form.cleaned_data['problem_description'], requestor_meta) ticket = rtModels.Ticket(subject=form.cleaned_data['subject'], problem_description=ticket_body, requestor=form.cleaned_data['email'], cc=form.cleaned_data['cc']) logger.debug('Creating ticket for user: %s' % form.cleaned_data) ticket_id = rt.createTicket(ticket) if ticket_id > -1: if 'attachment' in request.FILES: rt.replyToTicket(ticket_id, files=([ request.FILES['attachment'].name, request.FILES['attachment'], mimetypes.guess_type( request.FILES['attachment'].name) ], )) return HttpResponseRedirect( reverse('djangoRT:ticketdetail', args=[ticket_id])) else: messages.error( request, 'There was an error creating your ticket. Please try again.' ) else: messages.error(request, 'Invalid') else: form = forms.TicketForm( initial={ 'email': request.user.email, 'first_name': request.user.first_name, 'last_name': request.user.last_name }) return render(request, 'djangoRT/ticketCreate.html', {'form': form})