Formatting
This commit is contained in:
parent
8aee883aae
commit
f59c5499fb
|
@ -413,4 +413,4 @@ PHONE_PROVIDER_1_SECRET = os.environ.get("PHONE_PROVIDER_1_SECRET")
|
|||
PHONE_PROVIDER_2_HEADER = os.environ.get("PHONE_PROVIDER_2_HEADER")
|
||||
PHONE_PROVIDER_2_SECRET = os.environ.get("PHONE_PROVIDER_2_SECRET")
|
||||
|
||||
ZENDESK_HOST=os.environ.get('ZENDESK_HOST')
|
||||
ZENDESK_HOST = os.environ.get("ZENDESK_HOST")
|
||||
|
|
|
@ -12,7 +12,7 @@ from app.log import LOG
|
|||
from app.models import Mailbox
|
||||
from app.config import ZENDESK_HOST
|
||||
|
||||
VALID_MIME_TYPES = ['text/plain', 'message/rfc822']
|
||||
VALID_MIME_TYPES = ["text/plain", "message/rfc822"]
|
||||
|
||||
|
||||
@dashboard_bp.route("/support", methods=["GET"])
|
||||
|
@ -26,25 +26,27 @@ def show_support_dialog():
|
|||
def check_zendesk_response_status(response_code: int) -> bool:
|
||||
if response_code != 201:
|
||||
if response_code in (401 or 422):
|
||||
LOG.debug('Could not authenticate')
|
||||
LOG.debug("Could not authenticate")
|
||||
else:
|
||||
LOG.debug('Problem with the request. Status {}'.format(response_code))
|
||||
LOG.debug("Problem with the request. Status {}".format(response_code))
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
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")
|
||||
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
|
||||
escaped_filename = urllib.parse.urlencode({'filename': file.filename})
|
||||
url = 'https://{}/api/v2/uploads?{}'.format(ZENDESK_HOST, escaped_filename)
|
||||
headers = {'content-type': file.mimetype}
|
||||
escaped_filename = urllib.parse.urlencode({"filename": file.filename})
|
||||
url = "https://{}/api/v2/uploads?{}".format(ZENDESK_HOST, escaped_filename)
|
||||
headers = {"content-type": file.mimetype}
|
||||
response = requests.post(url, headers=headers, data=file.stream)
|
||||
if not check_zendesk_response_status(response.status_code):
|
||||
return
|
||||
data = response.json()
|
||||
return data['upload']['token']
|
||||
return data["upload"]["token"]
|
||||
|
||||
|
||||
def create_zendesk_request(email: str, content: str, files: [FileStorage]) -> bool:
|
||||
|
@ -57,26 +59,22 @@ def create_zendesk_request(email: str, content: str, files: [FileStorage]) -> bo
|
|||
return False
|
||||
tokens.append(token)
|
||||
data = {
|
||||
'request': {
|
||||
'subject': 'Ticket created for user {}'.format(current_user.id),
|
||||
'comment': {
|
||||
'type': 'Comment',
|
||||
'body': content,
|
||||
'uploads': tokens
|
||||
"request": {
|
||||
"subject": "Ticket created for user {}".format(current_user.id),
|
||||
"comment": {"type": "Comment", "body": content, "uploads": tokens},
|
||||
"requester": {
|
||||
"name": "SimpleLogin user {}".format(current_user.id),
|
||||
"email": email,
|
||||
},
|
||||
'requester': {
|
||||
'name': "SimpleLogin user {}".format(current_user.id),
|
||||
'email': email
|
||||
}
|
||||
}
|
||||
}
|
||||
url = 'https://{}/api/v2/requests.json'.format(ZENDESK_HOST)
|
||||
headers = {'content-type': 'application/json'}
|
||||
url = "https://{}/api/v2/requests.json".format(ZENDESK_HOST)
|
||||
headers = {"content-type": "application/json"}
|
||||
response = requests.post(url, data=json.dumps(data), headers=headers)
|
||||
if not check_zendesk_response_status(response.status_code):
|
||||
return False
|
||||
flash("Ticket was created. You should receive an email notification", "success")
|
||||
LOG.debug('Ticket created')
|
||||
LOG.debug("Ticket created")
|
||||
return True
|
||||
|
||||
|
||||
|
@ -93,6 +91,10 @@ def process_support_dialog():
|
|||
if not email:
|
||||
flash("Please add an email", "warning")
|
||||
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)
|
||||
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
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue