add alias log page

This commit is contained in:
Son NK 2019-11-16 18:45:23 +01:00
parent 032322a3d4
commit 5b8bc68da1
7 changed files with 139 additions and 1 deletions

View File

@ -1 +1 @@
from .views import index, pricing, setting, custom_alias, billing
from .views import index, pricing, setting, custom_alias, billing, alias_log

View File

@ -0,0 +1,62 @@
{% extends 'default.html' %}
{% set active_page = "dashboard" %}
{% block title %}
Alias Activity
{% endblock %}
{% block default_content %}
<div class="page-header row">
<h3 class="page-title col">
Alias Activity {{ alias }}
</h3>
</div>
<div class="row row-cards row-deck mt-4">
<div class="col-12">
<div class="card">
<div class="table-responsive">
<table class="table table-hover table-outline table-vcenter text-nowrap card-table">
<thead>
<tr>
<th>Activity</th>
<th>Website Email</th>
<th>
Forward/Reply
</th>
<th>Alias</th>
</tr>
</thead>
<tbody>
{% for log in logs %}
<tr>
<td>{{ log.when | dt }}</td>
<td>{{ log.website_email }}</td>
<td>
{% if log.is_reply %}
<img src="{{ url_for('static', filename='arrows/reply-arrow.svg') }}" class="arrow">
{% elif log.blocked %}
<img src="{{ url_for('static', filename='arrows/blocked-arrow.svg') }}" class="arrow">
{% else %}
<img src="{{ url_for('static', filename='arrows/forward-arrow.svg') }}" class="arrow">
{% endif %}
</td>
<td>{{ log.alias }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
{% endblock %}
{% block script %}
{% endblock %}

View File

@ -0,0 +1,62 @@
from dataclasses import dataclass
import arrow
from flask import render_template, flash, redirect, url_for
from flask_login import login_required, current_user
from app.dashboard.base import dashboard_bp
from app.extensions import db
from app.models import GenEmail, ForwardEmailLog, ForwardEmail
@dataclass
class AliasLog:
website_email: str
alias: str
when: arrow.Arrow
is_reply: bool
blocked: bool
@dashboard_bp.route("/alias_log/<alias>", methods=["GET"])
@login_required
def alias_log(alias):
gen_email = GenEmail.get_by(email=alias)
# sanity check
if not gen_email:
flash("You do not have access to this page", "warning")
return redirect(url_for("dashboard.index"))
if gen_email.user_id != current_user.id:
flash("You do not have access to this page", "warning")
return redirect(url_for("dashboard.index"))
return render_template(
"dashboard/alias_log.html", logs=get_alias_log(gen_email), alias=alias
)
def get_alias_log(gen_email: GenEmail):
logs: [AliasLog] = []
q = (
db.session.query(ForwardEmail, ForwardEmailLog)
.filter(ForwardEmail.id == ForwardEmailLog.forward_id)
.filter(ForwardEmail.gen_email_id == gen_email.id)
.all()
)
for fe, fel in q:
al = AliasLog(
website_email=fe.website_email,
alias=gen_email.email,
when=fel.created_at,
is_reply=fel.is_reply,
blocked=fel.blocked,
)
logs.append(al)
logs = sorted(logs, key=lambda l: l.when, reverse=True)
return logs

View File

@ -0,0 +1,4 @@
<svg width="238" height="123" viewBox="0 0 238 123" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M236.475 64.4749C237.842 63.108 237.842 60.892 236.475 59.5251L214.201 37.2513C212.834 35.8844 210.618 35.8844 209.251 37.2513C207.884 38.6181 207.884 40.8342 209.251 42.201L229.05 62L209.251 81.799C207.884 83.1658 207.884 85.3819 209.251 86.7487C210.618 88.1156 212.834 88.1156 214.201 86.7487L236.475 64.4749ZM0 65.5H234V58.5H0L0 65.5Z" fill="#5675E2"/>
<path d="M128.5 25.7C129.633 25.3667 131.2 25.2 133.2 25.2C135.267 25.2 137.033 25.5333 138.5 26.2L138.8 26.9L119.6 57.9L140.9 92.4C138.633 93.9333 136.2 94.7 133.6 94.7C131.067 94.7 128.9 93.2667 127.1 90.4L112.6 67L96.3 94C95.1667 94.3333 93.5333 94.5 91.4 94.5C89.3333 94.5 87.5667 94.1667 86.1 93.5L85.8 92.8L107.2 58.3L88.2 27.3C90.4667 25.7667 92.8667 25 95.4 25C98 25 100.167 26.4 101.9 29.2L114.2 49.2L128.5 25.7Z" fill="#EC1515"/>
</svg>

After

Width:  |  Height:  |  Size: 912 B

View File

@ -0,0 +1,3 @@
<svg width="211" height="54" viewBox="0 0 211 54" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M209.499 28.4507C210.852 27.0707 210.831 24.8547 209.451 23.5012L186.962 1.44464C185.582 0.0911427 183.366 0.112657 182.012 1.4927C180.659 2.87274 180.68 5.08871 182.06 6.44221L202.05 26.0481L182.445 46.0383C181.091 47.4184 181.113 49.6343 182.493 50.9878C183.873 52.3413 186.089 52.3198 187.442 50.9398L209.499 28.4507ZM1.03398 31.4998L207.034 29.4998L206.966 22.5002L0.966021 24.5002L1.03398 31.4998Z" fill="#5675E2"/>
</svg>

After

Width:  |  Height:  |  Size: 535 B

View File

@ -0,0 +1,3 @@
<svg width="212" height="52" viewBox="0 0 212 52" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M1.52513 23.5251C0.158291 24.8919 0.158291 27.108 1.52513 28.4749L23.799 50.7487C25.1658 52.1156 27.3819 52.1156 28.7487 50.7487C30.1156 49.3819 30.1156 47.1658 28.7487 45.799L8.94975 26L28.7487 6.20099C30.1156 4.83416 30.1156 2.61808 28.7487 1.25125C27.3819 -0.115589 25.1658 -0.115589 23.799 1.25125L1.52513 23.5251ZM212 22.5L4 22.5L4 29.5L212 29.5L212 22.5Z" fill="#5675E2"/>
</svg>

After

Width:  |  Height:  |  Size: 493 B

View File

@ -46,4 +46,8 @@
.highlight-row {
background-color: #eee;
font-weight: bolder;
}
.arrow {
width: 50px;
}