generated from nathanwoodburn/python-webserver-template
fix: Add refresh button to bypass cache
All checks were successful
Build Docker / BuildImage (push) Successful in 37s
All checks were successful
Build Docker / BuildImage (push) Successful in 37s
This commit is contained in:
parent
ed5595c79c
commit
0ce3f9c629
36
server.py
36
server.py
@ -217,10 +217,12 @@ def delete_email(conversation_id, email):
|
||||
# Get email by id
|
||||
conversation = get_conversation(conversation_id)
|
||||
if not conversation:
|
||||
print("No conversation found")
|
||||
return
|
||||
print(conversation)
|
||||
|
||||
if len(conversation) < 1:
|
||||
print("No conversation found")
|
||||
return
|
||||
|
||||
headers = {
|
||||
@ -231,6 +233,7 @@ def delete_email(conversation_id, email):
|
||||
if email in message["to"]:
|
||||
requests.delete(
|
||||
f"https://ticket.woodburn.au/api/conversations/{thread['id']}", headers=headers)
|
||||
clear_cache()
|
||||
return
|
||||
|
||||
|
||||
@ -249,11 +252,11 @@ def newemail():
|
||||
|
||||
return jsonify(json)
|
||||
|
||||
|
||||
@app.route("/api/email/<path:path>")
|
||||
def getemail(path):
|
||||
email = f'{path}@login.hns.au'
|
||||
return jsonify(get_email(email))
|
||||
# Removed for now
|
||||
# @app.route("/api/email/<path:path>")
|
||||
# def getemail(path):
|
||||
# email = f'{path}@login.hns.au'
|
||||
# return jsonify(get_email(email))
|
||||
|
||||
|
||||
def send_notification(data):
|
||||
@ -327,7 +330,7 @@ def send_webhook(webhook, data):
|
||||
}
|
||||
}
|
||||
],
|
||||
"username": "HNS Login Email",
|
||||
"username": "HNS Email",
|
||||
"avatar_url": "https://hns.au/favicon.png",
|
||||
"attachments": []
|
||||
}
|
||||
@ -339,6 +342,24 @@ def send_webhook(webhook, data):
|
||||
req = requests.post(
|
||||
webhook, json=body)
|
||||
|
||||
@app.route("/refresh")
|
||||
def refresh():
|
||||
# Check if user is logged in
|
||||
token = request.cookies.get("token")
|
||||
if not token:
|
||||
return redirect("/")
|
||||
|
||||
# Get user info
|
||||
user = get_user(token)
|
||||
if not user:
|
||||
return redirect("/logout")
|
||||
|
||||
clear_cache()
|
||||
return redirect("/inbox")
|
||||
|
||||
|
||||
def clear_cache():
|
||||
get_email.cache_clear()
|
||||
|
||||
@cache
|
||||
def get_user(token):
|
||||
@ -445,7 +466,8 @@ def parse_email(conversation):
|
||||
"name": f'{thread["createdBy"]["firstName"]} {thread["createdBy"]["lastName"]}',
|
||||
"body": thread["body"],
|
||||
"date": thread["createdAt"],
|
||||
"to": thread["to"]
|
||||
"to": thread["to"],
|
||||
"subject": conversation["subject"]
|
||||
})
|
||||
|
||||
return {"messages": messages, "id": conversation["id"]}
|
||||
|
@ -12,16 +12,21 @@
|
||||
<body>
|
||||
<header style="display: inline;">
|
||||
<img src="/favicon.png" style="width:50px;height:50px;">
|
||||
<h1>HNS Email</h1> <span style="float:right">{{emails.email}} | <a href="/notifications">Notifications</a> | <a href="/logout">Logout</a></span>
|
||||
<h1>HNS Email</h1> <span style="float:right">{{emails.email}} | <a href="/notifications">Notifications</a> | <a
|
||||
href="/logout">Logout</a></span>
|
||||
</header>
|
||||
|
||||
<br>
|
||||
<a href="/refresh" class="button" style="float: right;">Refresh</a>
|
||||
<div class="centre">
|
||||
|
||||
{% for conversation in emails.conversations %}
|
||||
<div class="conversation">
|
||||
<span>Conversation: {{conversation.id}}</span>
|
||||
{% for message in conversation.messages %}
|
||||
<div class="email">
|
||||
<div class="from">{{message.name}} ({{message.from}})</div> <div class="date">{{message.date}}</div>
|
||||
<div class="from">{{message.name}} ({{message.from}})</div>
|
||||
<div class="date">{{message.date}}</div>
|
||||
<div class="subject">{{message.subject}}</div>
|
||||
<div class="body">{{message.body|safe}}</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
Loading…
Reference in New Issue
Block a user