Added comments from PR

This commit is contained in:
Adrià Casajús 2022-02-09 16:20:55 +01:00
parent e57dcac2d2
commit 95fa95649d
No known key found for this signature in database
GPG Key ID: F0033226A5AFC9B9
7 changed files with 82 additions and 30 deletions

View File

@ -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_HEADER = os.environ.get("PHONE_PROVIDER_2_HEADER")
PHONE_PROVIDER_2_SECRET = os.environ.get("PHONE_PROVIDER_2_SECRET") PHONE_PROVIDER_2_SECRET = os.environ.get("PHONE_PROVIDER_2_SECRET")
ZENDESK_HOST=os.environ.get('ZENDESK_HOST', 'noone.zendesk.com') ZENDESK_HOST=os.environ.get('ZENDESK_HOST')

View File

@ -18,25 +18,31 @@ VALID_MIME_TYPES = ['text/plain', 'message/rfc822']
@dashboard_bp.route("/support", methods=["GET"]) @dashboard_bp.route("/support", methods=["GET"])
@login_required @login_required
def show_support_dialog(): def show_support_dialog():
mailbox = Mailbox.get(current_user.default_mailbox_id) if not ZENDESK_HOST:
return render_template("dashboard/support.html", ticketEmail=mailbox.email) return render_template("dashboard/support_disabled.html")
return render_template("dashboard/support.html", ticketEmail=current_user.email)
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')
else:
LOG.debug('Problem with the request. Status {}'.format(response_code))
return False
return True
def upload_file_to_zendesk(file: FileStorage) -> Union[None, str]: def upload_file_to_zendesk(file: FileStorage) -> Union[None, str]:
if file.mimetype not in VALID_MIME_TYPES and not file.mimetype.startswith('image/'): 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") flash('File {} is not an image, text or an email'.format(file.filename), "warning")
return None return
escaped_filename = urllib.parse.urlencode({'filename': file.filename}) escaped_filename = urllib.parse.urlencode({'filename': file.filename})
url = 'https://{}/api/v2/uploads?{}'.format(ZENDESK_HOST, escaped_filename) url = 'https://{}/api/v2/uploads?{}'.format(ZENDESK_HOST, escaped_filename)
headers = {'content-type': file.mimetype} headers = {'content-type': file.mimetype}
response = requests.post(url, headers=headers, data=file.stream) response = requests.post(url, headers=headers, data=file.stream)
if response.status_code != 201: if not check_zendesk_response_status(response.status_code):
if response.status_code == 401 or 422: return
LOG.debug('Could not authenticate')
return None
else:
LOG.debug('Problem with the request. Status ' + str(response.status_code))
return None
data = response.json() data = response.json()
return data['upload']['token'] return data['upload']['token']
@ -64,14 +70,9 @@ def create_zendesk_request(email: str, contents: str, files: [FileStorage]) -> b
} }
url = 'https://{}/api/v2/requests.json'.format(ZENDESK_HOST) url = 'https://{}/api/v2/requests.json'.format(ZENDESK_HOST)
headers = {'content-type': 'application/json'} headers = {'content-type': 'application/json'}
r = requests.post(url, data=json.dumps(data), headers=headers) response = requests.post(url, data=json.dumps(data), headers=headers)
if r.status_code != 201: if not check_zendesk_response_status(response.status_code):
if r.status_code == 401 or 422: return False
LOG.debug('Could not authenticate')
return False
else:
LOG.debug('Problem with the request. Status ' + str(r.status_code))
return False
flash("Ticket was created. You should receive an email notification", "success") flash("Ticket was created. You should receive an email notification", "success")
LOG.debug('Ticket created') LOG.debug('Ticket created')
return True return True
@ -80,6 +81,8 @@ def create_zendesk_request(email: str, contents: str, files: [FileStorage]) -> b
@dashboard_bp.route("/support", methods=["POST"]) @dashboard_bp.route("/support", methods=["POST"])
@login_required @login_required
def process_support_dialog(): def process_support_dialog():
if not ZENDESK_HOST:
return render_template("dashboard/support_disabled.html")
contents = request.form.get("ticketContents") or "" contents = request.form.get("ticketContents") or ""
email = request.form.get("ticketEmail") or "" email = request.form.get("ticketEmail") or ""
if not contents: if not contents:

View File

@ -1,6 +1,6 @@
{% extends 'default.html' %} {% extends 'default.html' %}
{% set active_page = None %} {% set active_page = 'dashboard' %}
{% block title %} {% block title %}
Support Support
@ -14,14 +14,15 @@
margin-bottom: 3px; margin-bottom: 3px;
} }
</style> </style>
{% endblock %}
<script src="{{ url_for('static', filename='node_modules/vue/dist/vue.min.js') }}"></script> {% block script %}
<script> <script>
$( document ).ready(function() { $( document ).ready(function() {
var app = new Vue({ var app = new Vue({
el: '#aliasGroup', el: '#aliasGroup',
data: { data: {
ticketEmail: document.querySelector("input[name=ticketEmail]").value ticketEmail: '{{ ticketEmail }}'
}, },
methods: { methods: {
generateRandomAlias: async function(event){ generateRandomAlias: async function(event){
@ -80,7 +81,7 @@
Conversations related to this ticket will be sent to this address. Feel free to use an alias here. Conversations related to this ticket will be sent to this address. Feel free to use an alias here.
</div> </div>
<div class="input-group mb-3" id="aliasGroup"> <div class="input-group mb-3" id="aliasGroup">
<input type="text" class="form-control" placeholder="Email" value="{{ ticketEmail }}" 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="ticketEmail" v-model='ticketEmail' aria-label="Email to send responses to" aria-describedby="button-addon2">
<div class="input-group-append"> <div class="input-group-append">
<button class="btn btn-outline-primary" type="button" @click="generateRandomAlias" id="button-addon2">Generate a random alias</button> <button class="btn btn-outline-primary" type="button" @click="generateRandomAlias" id="button-addon2">Generate a random alias</button>
</div> </div>

View File

@ -0,0 +1,34 @@
{% extends 'default.html' %}
{% set active_page = None %}
{% block title %}
Support
{% endblock %}
{% block head %}
<style>
.card-title {
font-size: 22px;
font-weight: 600;
margin-bottom: 3px;
}
</style>
{% endblock %}
{% block default_content %}
<div class="col pb-3">
<!-- Current plan -->
<div class="card">
<div class="card-body">
<div class="card-title mb-3">Support form is disabled. Please configure Zendesk integration.</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -24,7 +24,7 @@
<div class="card-body"> <div class="card-body">
<div class="card-title mb-3">Support ticket has been created for {{ ticketEmail }}</div> <div class="card-title mb-3">Support ticket has been created for {{ ticketEmail }}</div>
<div class="mt-2"> <div class="mt-2">
Head back to <a href="/dashboard">your dashboard</a> You should have received an email notification. We'll get in contact with you shortly.
</div> </div>
</div> </div>
</div> </div>

View File

@ -66,7 +66,6 @@
href="https://github.com/simple-login/app/projects/1">Roadmap</a></li> href="https://github.com/simple-login/app/projects/1">Roadmap</a></li>
<li><a class="list-group-item text-white footer-item" <li><a class="list-group-item text-white footer-item"
href="https://simplelogin.io/contact/">Contact Us</a></li> href="https://simplelogin.io/contact/">Contact Us</a></li>
<li><a class="list-group-item text-white footer-item" href="/dashboard/support">Support</a></li>
<li><a class="list-group-item text-white footer-item" <li><a class="list-group-item text-white footer-item"
href="https://simplelogin.io/imprint/">Imprint</a></li> href="https://simplelogin.io/imprint/">Imprint</a></li>
</ul> </ul>

View File

@ -71,11 +71,25 @@
</div> </div>
<div class="nav-item"> <div class="dropdown nav-item d-flex align-items-center">
<a href="https://simplelogin.io/docs/" target="_blank"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Help</a>
Docs <div class="dropdown-menu dropdown-menu-left dropdown-menu-arrow">
<i class="fa fa-external-link" aria-hidden="true"></i> <div class="dropdown-item">
</a> <a href="https://simplelogin.io/docs/" target="_blank">
Docs
<i class="fa fa-external-link" aria-hidden="true"></i>
</a>
</div>
<div class="dropdown-item">
<a href="https://forum.simplelogin.io/" target="_blank">
Forum
<i class="fa fa-external-link" aria-hidden="true"></i>
</a>
</div>
<div class="dropdown-item">
<a href="/dashboard/support">Support</a>
</div>
</div>
</div> </div>
{% if current_user.should_show_upgrade_button() %} {% if current_user.should_show_upgrade_button() %}
@ -84,6 +98,7 @@
</div> </div>
{% endif %} {% endif %}
<div class="dropdown"> <div class="dropdown">
<a href="#" class="nav-link pr-0 leading-none" data-toggle="dropdown"> <a href="#" class="nav-link pr-0 leading-none" data-toggle="dropdown">
{% if current_user.profile_picture_id %} {% if current_user.profile_picture_id %}