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 flask import Flask, g, redirect, render_template, request, send_file, flash
|
||||||
from werkzeug.security import generate_password_hash
|
from werkzeug.security import generate_password_hash
|
||||||
|
|
||||||
from . import albums, auth, partition
|
from .modules import albums, auth, partition, admin
|
||||||
from .auth import admin_required
|
from .modules.auth import admin_required
|
||||||
from .db import get_db
|
from .modules.db import get_db
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
@ -23,6 +23,7 @@ else:
|
|||||||
print("[WARNING] Using default config")
|
print("[WARNING] Using default config")
|
||||||
|
|
||||||
app.register_blueprint(auth.bp)
|
app.register_blueprint(auth.bp)
|
||||||
|
app.register_blueprint(admin.bp)
|
||||||
app.register_blueprint(albums.bp)
|
app.register_blueprint(albums.bp)
|
||||||
app.register_blueprint(partition.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",
|
"albums/album.html",
|
||||||
album=album,
|
album=album,
|
||||||
partitions=partitions,
|
partitions=partitions,
|
||||||
not_participant=not_participant,
|
not_participant=not_participant
|
||||||
user=user
|
|
||||||
)
|
)
|
||||||
|
|
||||||
except LookupError:
|
except LookupError:
|
@ -50,4 +50,4 @@ def partition_search(uuid):
|
|||||||
@admin_required
|
@admin_required
|
||||||
def index():
|
def index():
|
||||||
partitions = get_all_partitions().fetchall()
|
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():
|
class User():
|
||||||
def __init__(self, user_id):
|
def __init__(self, user_id):
|
||||||
self.id = user_id
|
self.id = user_id
|
||||||
|
self.albums = None
|
||||||
|
|
||||||
db = get_db()
|
db = get_db()
|
||||||
if self.id is None:
|
if self.id is None:
|
@ -215,13 +215,12 @@ input[type=submit] {
|
|||||||
height: 22px;
|
height: 22px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
padding-top: 3px;
|
padding-top: 3px;
|
||||||
border-radius: 20px;
|
border-radius: 50%;
|
||||||
border-width: 1px;
|
|
||||||
border-color: black;
|
|
||||||
margin: 1px;
|
margin: 1px;
|
||||||
color: white;
|
color: white;
|
||||||
text-shadow: 1px 1px 4px #000000;
|
text-shadow: 1px 1px 4px #000000;
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
|
border: 1px solid black;
|
||||||
}
|
}
|
||||||
|
|
||||||
#users-list {
|
#users-list {
|
||||||
@ -239,6 +238,13 @@ input[type=submit] {
|
|||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.userdropbtn {
|
||||||
|
background-color: lightgray;
|
||||||
|
height: 30px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
.dropdown {
|
.dropdown {
|
||||||
position: relative;
|
position: relative;
|
||||||
float: right;
|
float: right;
|
||||||
@ -276,4 +282,26 @@ input[type=submit] {
|
|||||||
background-color: #c61918;
|
background-color: #c61918;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
color: whitesmoke;
|
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 %}
|
{% else %}
|
||||||
<a href="/albums/{{ album.uuid }}/quit">Quitter</a>
|
<a href="/albums/{{ album.uuid }}/quit">Quitter</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if user.access_level == 1 %}
|
{% if g.user.access_level == 1 %}
|
||||||
<a id="delete-album" href="/albums/{{ album.uuid }}/delete">Supprimer</a>
|
<a id="delete-album" href="/albums/{{ album.uuid }}/delete">Supprimer</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
@ -10,15 +10,23 @@
|
|||||||
</head>
|
</head>
|
||||||
<nav>
|
<nav>
|
||||||
<h1><a href="{{ url_for('albums.index') }}">PartitionCloud</a></h1>
|
<h1><a href="{{ url_for('albums.index') }}">PartitionCloud</a></h1>
|
||||||
<ul>
|
<div class="dropdown">
|
||||||
{% if g.user %}
|
{% if g.user %}
|
||||||
<li><span>{{ g.user['username'] }}</span>
|
<button class="userdropbtn">{{ g.user['username'] }}</button>
|
||||||
<li><a href="{{ url_for('auth.logout') }}">Déconnexion</a>
|
|
||||||
{% else %}
|
{% else %}
|
||||||
<li><a href="{{ url_for('auth.register') }}">Créer un compte</a>
|
<button class="userdropbtn">Connexion</button>
|
||||||
<li><a href="{{ url_for('auth.login') }}">Se connecter</a>
|
|
||||||
{% endif %}
|
{% 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>
|
</nav>
|
||||||
<section class="content">
|
<section class="content">
|
||||||
<header>
|
<header>
|
||||||
|
Loading…
Reference in New Issue
Block a user