mirror of
https://github.com/partitioncloud/partitioncloud-server.git
synced 2025-01-23 17:26:26 +01:00
Ajout d'un panneau d'administration
This commit is contained in:
parent
1c7e272f91
commit
2a0787441c
@ -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)
|
||||
|
||||
|
31
partitioncloud/modules/admin.py
Normal file
31
partitioncloud/modules/admin.py
Normal 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
|
||||
)
|
@ -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:
|
@ -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)
|
@ -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:
|
@ -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;
|
||||
@ -277,3 +283,25 @@ input[type=submit] {
|
||||
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;
|
||||
}
|
36
partitioncloud/templates/admin/index.html
Normal file
36
partitioncloud/templates/admin/index.html
Normal 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 %}
|
@ -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>
|
||||
|
@ -10,15 +10,23 @@
|
||||
</head>
|
||||
<nav>
|
||||
<h1><a href="{{ url_for('albums.index') }}">PartitionCloud</a></h1>
|
||||
<ul>
|
||||
<div class="dropdown">
|
||||
{% if g.user %}
|
||||
<li><span>{{ g.user['username'] }}</span>
|
||||
<li><a href="{{ url_for('auth.logout') }}">Déconnexion</a>
|
||||
<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>
|
||||
|
Loading…
Reference in New Issue
Block a user