extract the app/website to a separate page

This commit is contained in:
Son NK 2021-04-01 14:09:16 +02:00
parent 3c4a1413e0
commit efae1710c8
7 changed files with 125 additions and 81 deletions

View File

@ -26,4 +26,5 @@ from .views import (
setup_done,
batch_import,
alias_transfer,
app,
)

View File

@ -0,0 +1,74 @@
{% extends 'default.html' %}
{% set active_page = "app" %}
{% block title %}
Sign in with SimpleLogin apps
{% endblock %}
{% block default_content %}
<div class="row">
<div class="col">
<h1 class="h3"> Apps </h1>
<div class="small-text">
List of websites/apps that you have used <b>Sign in with SimpleLogin</b> on
</div>
</div>
</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>
App
</th>
<th>
Info
<i class="fe fe-help-circle" data-toggle="tooltip"
title="Info sent to this app/website"></i>
</th>
<th class="text-center">
First used
<i class="fe fe-help-circle" data-toggle="tooltip"
title="The first time you have used the SimpleLogin on this app/website"></i>
</th>
<!--<th class="text-center">Last used</th>-->
</tr>
</thead>
<tbody>
{% for client_user in client_users %}
<tr>
<td>
{{ client_user.client.name }}
</td>
<td>
{% for scope, val in client_user.get_user_info().items() %}
<div>
{% if scope == "email" %}
Email: <a href="mailto:{{ val }}">{{ val }}</a>
{% elif scope == "name" %}
Name: {{ val }}
{% endif %}
</div>
{% endfor %}
</td>
<td class="text-center">
{{ client_user.created_at | dt }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -472,75 +472,6 @@
</div>
</div>
{% if client_users %}
<div class="row">
<h3 class="page-title col"
data-intro="Here you can find the list of website/app on which
you have used the <em>Connect with SimpleLogin</em> button <br><br>
You also see what information that SimpleLogin has communicated to these website/app when you sign in."
data-step="5"
>
Apps
</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>
App
</th>
<th>
Info
<i class="fe fe-help-circle" data-toggle="tooltip"
title="Info sent to this app/website"></i>
</th>
<th class="text-center">
First used
<i class="fe fe-help-circle" data-toggle="tooltip"
title="The first time you have used the SimpleLogin on this app/website"></i>
</th>
<!--<th class="text-center">Last used</th>-->
</tr>
</thead>
<tbody>
{% for client_user in client_users %}
<tr>
<td>
{{ client_user.client.name }}
</td>
<td>
{% for scope, val in client_user.get_user_info().items() %}
<div>
{% if scope == "email" %}
Email: <a href="mailto:{{ val }}">{{ val }}</a>
{% elif scope == "name" %}
Name: {{ val }}
{% endif %}
</div>
{% endfor %}
</td>
<td class="text-center">
{{ client_user.created_at | dt }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
{% endif %}
{% endblock %}
{% block script %}

View File

@ -0,0 +1,30 @@
"""
List of apps that user has used via the "Sign in with SimpleLogin"
"""
from flask import render_template
from flask_login import login_required, current_user
from sqlalchemy.orm import joinedload
from app.dashboard.base import dashboard_bp
from app.models import (
ClientUser,
)
@dashboard_bp.route("/app", methods=["GET", "POST"])
@login_required
def app_route():
client_users = (
ClientUser.filter_by(user_id=current_user.id)
.options(joinedload(ClientUser.client))
.options(joinedload(ClientUser.alias))
.all()
)
sorted(client_users, key=lambda cu: cu.client.name)
return render_template(
"dashboard/app.html",
client_users=client_users,
)

View File

@ -2,7 +2,6 @@ from dataclasses import dataclass
from flask import render_template, request, redirect, url_for, flash
from flask_login import login_required, current_user
from sqlalchemy.orm import joinedload
from app import alias_utils
from app.api.serializer import get_alias_infos_with_pagination_v3
@ -12,7 +11,6 @@ from app.extensions import db, limiter
from app.log import LOG
from app.models import (
Alias,
ClientUser,
AliasGeneratorEnum,
User,
EmailLog,
@ -139,15 +137,6 @@ def index():
url_for("dashboard.index", query=query, sort=sort, filter=alias_filter)
)
client_users = (
ClientUser.filter_by(user_id=current_user.id)
.options(joinedload(ClientUser.client))
.options(joinedload(ClientUser.alias))
.all()
)
sorted(client_users, key=lambda cu: cu.client.name)
mailboxes = current_user.mailboxes()
show_intro = False
@ -168,7 +157,6 @@ def index():
return render_template(
"dashboard/index.html",
client_users=client_users,
alias_infos=alias_infos,
highlight_alias_id=highlight_alias_id,
query=query,

View File

@ -710,6 +710,16 @@ class User(db.Model, ModelMixin, UserMixin):
# can have duplicate where a "root" user has a domain that's also listed in SL domains
return list(set(domains))
def should_show_app_page(self) -> bool:
"""whether to show the app page"""
return (
# when user has used the "Sign in with SL" button before
ClientUser.query.filter(ClientUser.user_id == self.id).count()
# or when user has created an app
+ Client.query.filter(Client.user_id == self.id).count()
> 0
)
def __repr__(self):
return f"<User {self.id} {self.name} {self.email}>"

View File

@ -46,6 +46,16 @@
</a>
</li>
{% if current_user.should_show_app_page() %}
<li class="nav-item">
<a href="{{ url_for('dashboard.app_route') }}"
class="nav-link {{ 'active' if active_page == 'app' }}">
<i class="fe fe-grid"></i>
Apps
</a>
</li>
{% endif %}
<li class="nav-item">
<a href="{{ url_for('dashboard.setting') }}"
class="nav-link {{ 'active' if active_page == 'setting' }}">