Updated with more PR comments

This commit is contained in:
Adrià Casajús 2022-02-09 16:41:04 +01:00
parent 95fa95649d
commit 8aee883aae
No known key found for this signature in database
GPG Key ID: F0033226A5AFC9B9
2 changed files with 38 additions and 40 deletions

View File

@ -20,7 +20,7 @@ VALID_MIME_TYPES = ['text/plain', 'message/rfc822']
def show_support_dialog():
if not ZENDESK_HOST:
return render_template("dashboard/support_disabled.html")
return render_template("dashboard/support.html", ticketEmail=current_user.email)
return render_template("dashboard/support.html", ticket_email=current_user.email)
def check_zendesk_response_status(response_code: int) -> bool:
@ -33,7 +33,7 @@ def check_zendesk_response_status(response_code: int) -> bool:
return True
def upload_file_to_zendesk(file: FileStorage) -> Union[None, str]:
def upload_file_to_zendesk_and_get_upload_token(file: FileStorage) -> Union[None, str]:
if file.mimetype not in VALID_MIME_TYPES and not file.mimetype.startswith('image/'):
flash('File {} is not an image, text or an email'.format(file.filename), "warning")
return
@ -47,10 +47,12 @@ def upload_file_to_zendesk(file: FileStorage) -> Union[None, str]:
return data['upload']['token']
def create_zendesk_request(email: str, contents: str, files: [FileStorage]) -> bool:
def create_zendesk_request(email: str, content: str, files: [FileStorage]) -> bool:
tokens = []
for file in files:
token = upload_file_to_zendesk(file)
if not file.filename:
continue
token = upload_file_to_zendesk_and_get_upload_token(file)
if token is None:
return False
tokens.append(token)
@ -59,7 +61,7 @@ def create_zendesk_request(email: str, contents: str, files: [FileStorage]) -> b
'subject': 'Ticket created for user {}'.format(current_user.id),
'comment': {
'type': 'Comment',
'body': contents,
'body': content,
'uploads': tokens
},
'requester': {
@ -83,14 +85,14 @@ def create_zendesk_request(email: str, contents: str, files: [FileStorage]) -> b
def process_support_dialog():
if not ZENDESK_HOST:
return render_template("dashboard/support_disabled.html")
contents = request.form.get("ticketContents") or ""
email = request.form.get("ticketEmail") or ""
if not contents:
content = request.form.get("ticket_content") or ""
email = request.form.get("ticket_email") or ""
if not content:
flash("Please add a description", "warning")
return render_template("dashboard/support.html", ticketEmail=email)
return render_template("dashboard/support.html", ticket_email=email)
if not email:
flash("Please add an email", "warning")
return render_template("dashboard/support.html", ticketContents=contents)
if create_zendesk_request(email, contents, request.files.getlist('ticketFiles')):
return render_template("dashboard/support_ticket_created.html", ticketEmail=email)
return render_template("dashboard/support.html", ticketEmail=email, ticketContents=contents)
return render_template("dashboard/support.html", ticket_content=content)
if create_zendesk_request(email, content, request.files.getlist('ticket_files')):
return render_template("dashboard/support_ticket_created.html", ticket_email=email)
return render_template("dashboard/support.html", ticket_email=email, ticket_content=content)

View File

@ -18,33 +18,29 @@
{% block script %}
<script>
$( document ).ready(function() {
var app = new Vue({
el: '#aliasGroup',
data: {
ticketEmail: '{{ ticketEmail }}'
},
methods: {
generateRandomAlias: async function(event){
let result = await fetch('/api/alias/random/new', { method: 'POST'})
if(result.ok){
let data = await result.json();
this.ticketEmail = data.alias;
}
new Vue({
el: '#aliasGroup',
data: {
ticket_email: '{{ ticket_email }}'
},
methods: {
generateRandomAlias: async function(event){
let result = await fetch('/api/alias/random/new', { method: 'POST'})
if(result.ok){
let data = await result.json();
this.ticket_email = data.alias;
}
}
});
}
});
$('.custom-file input').change(function (e) {
var files = [];
for (var i = 0; i < $(this)[0].files.length; i++) {
files.push($(this)[0].files[i].name);
}
$(this).next('.custom-file-label').html(files.join(', '));
});
})
$('.custom-file input').change(function (e) {
var files = [];
for (var i = 0; i < $(this)[0].files.length; i++) {
files.push($(this)[0].files[i].name);
}
$(this).next('.custom-file-label').html(files.join(', '));
});
</script>
{% endblock %}
@ -64,14 +60,14 @@
<form id="supportZendeskForm" method="post" enctype="multipart/form-data">
<div class="mt-4 mb-5">
<label for="issueDescription" class="form-label">What happened?</label>
<textarea class="form-control" name="ticketContents" id="issueDescription" rows="3" placeholder="Please provide as much information as possible. For example which alias(es), mailbox(es) ar affected, if this is a persistent issue...">{{- ticketContents or '' -}}</textarea>
<textarea class="form-control" name="ticket_content" id="issueDescription" rows="3" placeholder="Please provide as much information as possible. For example which alias(es), mailbox(es) ar affected, if this is a persistent issue...">{{- ticket_content or '' -}}</textarea>
</div>
<div class="mt-5 font-weight-bold">
Attach files to support request
</div>
<div class="mt-1 text-muted">Only images, text and emails are accepted</div>
<div class="custom-file mt-2">
<input type="file" class="custom-file-input" name="ticketFiles" id="ticketFileGroup" multiple="multiple">
<input type="file" class="custom-file-input" name="ticket_files" id="ticketFileGroup" multiple="multiple">
<label class="custom-file-label" for="ticketFileGroup">Choose file</label>
</div>
<div class="mt-5 font-weight-bold">
@ -81,7 +77,7 @@
Conversations related to this ticket will be sent to this address. Feel free to use an alias here.
</div>
<div class="input-group mb-3" id="aliasGroup">
<input type="text" class="form-control" placeholder="Email" name="ticketEmail" v-model='ticketEmail' aria-label="Email to send responses to" aria-describedby="button-addon2">
<input type="text" class="form-control" placeholder="Email" name="ticket_email" v-model='ticket_email' aria-label="Email to send responses to" aria-describedby="button-addon2">
<div class="input-group-append">
<button class="btn btn-outline-primary" type="button" @click="generateRandomAlias" id="button-addon2">Generate a random alias</button>
</div>