Ajout d'un panneau d'administration

This commit is contained in:
augustin64 2022-08-31 13:54:13 +02:00
parent 1c7e272f91
commit 2a0787441c
13 changed files with 121 additions and 17 deletions

View File

@ -7,9 +7,9 @@ import os
from flask import Flask, g, redirect, render_template, request, send_file, flash
from werkzeug.security import generate_password_hash
from . import albums, auth, partition
from .auth import admin_required
from .db import get_db
from .modules import albums, auth, partition, admin
from .modules.auth import admin_required
from .modules.db import get_db
app = Flask(__name__)
@ -23,6 +23,7 @@ else:
print("[WARNING] Using default config")
app.register_blueprint(auth.bp)
app.register_blueprint(admin.bp)
app.register_blueprint(albums.bp)
app.register_blueprint(partition.bp)

View File

@ -0,0 +1,31 @@
#!/usr/bin/python3
"""
Admin Panel
"""
import os
from flask import Blueprint, abort, send_file, render_template
from .db import get_db
from .auth import admin_required
from .utils import User
bp = Blueprint("admin", __name__, url_prefix="/admin")
@bp.route("/")
@admin_required
def index():
db = get_db()
users_id = db.execute(
"""
SELECT id FROM user
"""
)
users = [User(u["id"]) for u in users_id]
for u in users:
u.albums = u.get_albums()
db.close()
return render_template(
"admin/index.html",
users=users
)

View File

@ -70,8 +70,7 @@ def album(uuid):
"albums/album.html",
album=album,
partitions=partitions,
not_participant=not_participant,
user=user
not_participant=not_participant
)
except LookupError:

View File

@ -50,4 +50,4 @@ def partition_search(uuid):
@admin_required
def index():
partitions = get_all_partitions().fetchall()
return render_template("partitions/view-all.html", partitions=partitions)
return render_template("admin/partitions.html", partitions=partitions)

View File

@ -5,6 +5,7 @@ from .db import get_db
class User():
def __init__(self, user_id):
self.id = user_id
self.albums = None
db = get_db()
if self.id is None:

View File

@ -215,13 +215,12 @@ input[type=submit] {
height: 22px;
text-align: center;
padding-top: 3px;
border-radius: 20px;
border-width: 1px;
border-color: black;
border-radius: 50%;
margin: 1px;
color: white;
text-shadow: 1px 1px 4px #000000;
font-size: 18px;
border: 1px solid black;
}
#users-list {
@ -239,6 +238,13 @@ input[type=submit] {
border-radius: 3px;
}
.userdropbtn {
background-color: lightgray;
height: 30px;
border: none;
border-radius: 3px;
}
.dropdown {
position: relative;
float: right;
@ -276,4 +282,26 @@ input[type=submit] {
background-color: #c61918;
border-radius: 5px;
color: whitesmoke;
}
table {
border: medium solid #b9c6dd;
border-collapse: collapse;
text-align: center;
width: 80%;
margin: 10%;
}
.user-profile {
display: inline-flex;
width: 80%;
}
.table-username {
margin-left: 10px;
}
td {
border-color: black;
border: thin solid;
}

View File

@ -0,0 +1,36 @@
{% extends 'base.html' %}
{% block header %}
<h1>Panneau d'administration</h1>
{% endblock %}
{% block header_actions %}
{% endblock %}
{% block content %}
<table>
<thead>
<tr>
<th scope="col">Utilisateur</th>
<th scope="col">Albums</th>
<th scope="col">Privilèges</th>
</tr>
</thead>
<tbody>
{% for user in users %}
<tr>
<td>
<div class="user-profile">
<div class="user-profile-picture" style="background-color:{{ user.color }};" title="{{ user.username }}">
{{ user.username[0] | upper }}
</div>
<div class="table-username">{{ user.username }}</div>
</div>
</td>
<td>{{ user.albums | length }}</td>
<td>{% if user.access_level != 1 %}❌{% else %}✅{% endif %}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

View File

@ -23,7 +23,7 @@
{% else %}
<a href="/albums/{{ album.uuid }}/quit">Quitter</a>
{% endif %}
{% if user.access_level == 1 %}
{% if g.user.access_level == 1 %}
<a id="delete-album" href="/albums/{{ album.uuid }}/delete">Supprimer</a>
{% endif %}
</div>

View File

@ -10,15 +10,23 @@
</head>
<nav>
<h1><a href="{{ url_for('albums.index') }}">PartitionCloud</a></h1>
<ul>
{% if g.user %}
<li><span>{{ g.user['username'] }}</span>
<li><a href="{{ url_for('auth.logout') }}">Déconnexion</a>
<div class="dropdown">
{% if g.user %}
<button class="userdropbtn">{{ g.user['username'] }}</button>
{% else %}
<li><a href="{{ url_for('auth.register') }}">Créer un compte</a>
<li><a href="{{ url_for('auth.login') }}">Se connecter</a>
<button class="userdropbtn">Connexion</button>
{% endif %}
</ul>
<div class="dropdown-content">
{% if not g.user %}
<a href="{{ url_for('auth.register') }}">Créer un compte</a>
<a href="{{ url_for('auth.login') }}">Se connecter</a>
{% else %}
{% if g.user.access_level == 1 %}
<a href="/admin">Panneau Admin</a>
{% endif %}
<a href="{{ url_for('auth.logout') }}">Déconnexion</a>
{% endif %}
</div>
</nav>
<section class="content">
<header>