mirror of
https://github.com/simple-login/app.git
synced 2025-02-21 22:32:56 +08:00
Added comments from PR
This commit is contained in:
parent
e57dcac2d2
commit
95fa95649d
7 changed files with 82 additions and 30 deletions
|
@ -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', 'noone.zendesk.com')
|
||||
ZENDESK_HOST=os.environ.get('ZENDESK_HOST')
|
||||
|
|
|
@ -18,25 +18,31 @@ VALID_MIME_TYPES = ['text/plain', 'message/rfc822']
|
|||
@dashboard_bp.route("/support", methods=["GET"])
|
||||
@login_required
|
||||
def show_support_dialog():
|
||||
mailbox = Mailbox.get(current_user.default_mailbox_id)
|
||||
return render_template("dashboard/support.html", ticketEmail=mailbox.email)
|
||||
if not ZENDESK_HOST:
|
||||
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]:
|
||||
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 None
|
||||
return
|
||||
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 response.status_code != 201:
|
||||
if response.status_code == 401 or 422:
|
||||
LOG.debug('Could not authenticate')
|
||||
return None
|
||||
else:
|
||||
LOG.debug('Problem with the request. Status ' + str(response.status_code))
|
||||
return None
|
||||
if not check_zendesk_response_status(response.status_code):
|
||||
return
|
||||
data = response.json()
|
||||
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)
|
||||
headers = {'content-type': 'application/json'}
|
||||
r = requests.post(url, data=json.dumps(data), headers=headers)
|
||||
if r.status_code != 201:
|
||||
if r.status_code == 401 or 422:
|
||||
LOG.debug('Could not authenticate')
|
||||
return False
|
||||
else:
|
||||
LOG.debug('Problem with the request. Status ' + str(r.status_code))
|
||||
return False
|
||||
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')
|
||||
return True
|
||||
|
@ -80,6 +81,8 @@ def create_zendesk_request(email: str, contents: str, files: [FileStorage]) -> b
|
|||
@dashboard_bp.route("/support", methods=["POST"])
|
||||
@login_required
|
||||
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:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{% extends 'default.html' %}
|
||||
|
||||
{% set active_page = None %}
|
||||
{% set active_page = 'dashboard' %}
|
||||
|
||||
{% block title %}
|
||||
Support
|
||||
|
@ -14,14 +14,15 @@
|
|||
margin-bottom: 3px;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
<script src="{{ url_for('static', filename='node_modules/vue/dist/vue.min.js') }}"></script>
|
||||
{% block script %}
|
||||
<script>
|
||||
$( document ).ready(function() {
|
||||
var app = new Vue({
|
||||
el: '#aliasGroup',
|
||||
data: {
|
||||
ticketEmail: document.querySelector("input[name=ticketEmail]").value
|
||||
ticketEmail: '{{ ticketEmail }}'
|
||||
},
|
||||
methods: {
|
||||
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.
|
||||
</div>
|
||||
<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">
|
||||
<button class="btn btn-outline-primary" type="button" @click="generateRandomAlias" id="button-addon2">Generate a random alias</button>
|
||||
</div>
|
||||
|
|
34
templates/dashboard/support_disabled.html
Normal file
34
templates/dashboard/support_disabled.html
Normal 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 %}
|
||||
|
||||
|
||||
|
|
@ -24,7 +24,7 @@
|
|||
<div class="card-body">
|
||||
<div class="card-title mb-3">Support ticket has been created for {{ ticketEmail }}</div>
|
||||
<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>
|
||||
|
|
|
@ -66,7 +66,6 @@
|
|||
href="https://github.com/simple-login/app/projects/1">Roadmap</a></li>
|
||||
<li><a class="list-group-item text-white footer-item"
|
||||
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"
|
||||
href="https://simplelogin.io/imprint/">Imprint</a></li>
|
||||
</ul>
|
||||
|
|
|
@ -71,11 +71,25 @@
|
|||
|
||||
</div>
|
||||
|
||||
<div class="nav-item">
|
||||
<a href="https://simplelogin.io/docs/" target="_blank">
|
||||
Docs
|
||||
<i class="fa fa-external-link" aria-hidden="true"></i>
|
||||
</a>
|
||||
<div class="dropdown nav-item d-flex align-items-center">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Help</a>
|
||||
<div class="dropdown-menu dropdown-menu-left dropdown-menu-arrow">
|
||||
<div class="dropdown-item">
|
||||
<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>
|
||||
|
||||
{% if current_user.should_show_upgrade_button() %}
|
||||
|
@ -84,6 +98,7 @@
|
|||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
<div class="dropdown">
|
||||
<a href="#" class="nav-link pr-0 leading-none" data-toggle="dropdown">
|
||||
{% if current_user.profile_picture_id %}
|
||||
|
|
Loading…
Reference in a new issue