mirror of
https://github.com/partitioncloud/partitioncloud-server.git
synced 2025-01-23 09:16:25 +01:00
Ajout d'une option permettant de quitter un album
This commit is contained in:
parent
dc4f1f21d3
commit
e40a344e2b
@ -70,7 +70,8 @@ def album(uuid):
|
||||
"albums/album.html",
|
||||
album=album,
|
||||
partitions=partitions,
|
||||
not_participant=not_participant
|
||||
not_participant=not_participant,
|
||||
user=user
|
||||
)
|
||||
|
||||
except LookupError:
|
||||
@ -160,6 +161,25 @@ def join_album(uuid):
|
||||
return redirect(f"/albums/{uuid}")
|
||||
|
||||
|
||||
@bp.route("/<uuid>/quit")
|
||||
@login_required
|
||||
def quit_album(uuid):
|
||||
user = User(session.get("user_id"))
|
||||
album = Album(uuid=uuid)
|
||||
users = album.get_users()
|
||||
if user.id not in [u["id"] for u in users]:
|
||||
flash("Vous ne faites pas partie de cet album")
|
||||
return redirect(f"/albums/{uuid}")
|
||||
|
||||
if len(users) == 1:
|
||||
flash("Vous êtes seul dans cet album, le quitter entraînera sa suppression.")
|
||||
return redirect(f"/albums/{uuid}/delete")
|
||||
|
||||
user.quit_album(uuid)
|
||||
flash("Album quitté.")
|
||||
return redirect(f"/albums")
|
||||
|
||||
|
||||
@bp.route("/<uuid>/delete", methods=["GET", "POST"])
|
||||
@login_required
|
||||
def delete_album(uuid):
|
||||
@ -298,7 +318,7 @@ def add_partition_from_search():
|
||||
error = "Il est nécessaire de sélectionner une partition."
|
||||
elif "partition-type" not in request.form:
|
||||
error = "Il est nécessaire de spécifier un type de partition."
|
||||
elif not user.is_participant(request.form["album-uuid"]):
|
||||
elif (not user.is_participant(request.form["album-uuid"])) and (user.access_level != 1):
|
||||
error = "Vous ne participez pas à cet album."
|
||||
|
||||
if error is not None:
|
||||
|
@ -6,16 +6,25 @@
|
||||
|
||||
{% block header_actions %}
|
||||
<div id="users-list">
|
||||
{% for user in album.users %}
|
||||
<div class="user-profile-picture" style="background-color:{{ user.color }};" title="{{ user.username }}">
|
||||
{{ user.username[0] | upper }}
|
||||
{% for album_user in album.users %}
|
||||
<div class="user-profile-picture" style="background-color:{{ album_user.color }};" title="{{ album_user.username }}">
|
||||
{{ album_user.username[0] | upper }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% if user.access_level == 1 %}
|
||||
<a class="button-href" href="/albums/{{ album.uuid }}/delete">
|
||||
<button id="delete-album">Supprimer</button>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if not_participant %}
|
||||
<a class="button-href" href="/albums/{{ album.uuid }}/join">
|
||||
<button id="join-album">Rejoindre</button>
|
||||
</a>
|
||||
{% else %}
|
||||
<a class="button-href" href="/albums/{{ album.uuid }}/quit">
|
||||
<button id="quit-album">Quitter</button>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if g.user %}
|
||||
<a class="button-href" href="/albums/{{ album.uuid }}/add-partition">
|
||||
|
@ -26,8 +26,7 @@ class User():
|
||||
|
||||
def is_participant(self, album_uuid):
|
||||
db = get_db()
|
||||
if self.access_level == 1:
|
||||
return True
|
||||
|
||||
return len(db.execute(
|
||||
"""
|
||||
SELECT album.id FROM album
|
||||
@ -71,6 +70,20 @@ class User():
|
||||
)
|
||||
db.commit()
|
||||
|
||||
def quit_album(self, album_uuid):
|
||||
db = get_db()
|
||||
album = Album(uuid=album_uuid)
|
||||
|
||||
db.execute(
|
||||
"""
|
||||
DELETE FROM contient_user
|
||||
WHERE user_id = ?
|
||||
AND album_id = ?
|
||||
""",
|
||||
(self.id, album.id)
|
||||
)
|
||||
db.commit()
|
||||
|
||||
|
||||
def get_color(self):
|
||||
integer = int.from_bytes(self.username.encode(), "little") % 16777215
|
||||
|
Loading…
Reference in New Issue
Block a user