From 2de234870e1913827f7559df6c32c20b3d67610a Mon Sep 17 00:00:00 2001 From: augustin64 Date: Thu, 26 Oct 2023 23:38:09 +0200 Subject: [PATCH] Fix groupe deletion (removed orphans) --- partitioncloud/modules/classes/album.py | 14 +++++++++++++- partitioncloud/modules/classes/groupe.py | 4 ++-- partitioncloud/modules/classes/user.py | 7 ++++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/partitioncloud/modules/classes/album.py b/partitioncloud/modules/classes/album.py index 2b00231..e0e2ffd 100644 --- a/partitioncloud/modules/classes/album.py +++ b/partitioncloud/modules/classes/album.py @@ -2,7 +2,7 @@ import os from ..db import get_db - +from .attachment import Attachment class Album(): def __init__(self, uuid=None, id=None): @@ -116,6 +116,18 @@ class Album(): """ ) for partition in partitions.fetchall(): + data = db.execute( + """ + SELECT * FROM attachments + WHERE partition_uuid = ? + """, + (partition["uuid"],) + ) + attachments = [Attachment(data=i) for i in data] + + for attachment in attachments: + attachment.delete() + os.remove(f"partitioncloud/partitions/{partition['uuid']}.pdf") if os.path.exists(f"partitioncloud/static/thumbnails/{partition['uuid']}.jpg"): os.remove(f"partitioncloud/static/thumbnails/{partition['uuid']}.jpg") diff --git a/partitioncloud/modules/classes/groupe.py b/partitioncloud/modules/classes/groupe.py index 9a318ad..19398a8 100644 --- a/partitioncloud/modules/classes/groupe.py +++ b/partitioncloud/modules/classes/groupe.py @@ -54,9 +54,9 @@ class Groupe(): """ SELECT id FROM album LEFT JOIN groupe_contient_album - LEFT JOIN contient_user ON groupe_contient_album.album_id=album.id - AND contient_user.album_id=album.id + LEFT JOIN contient_user + ON contient_user.album_id=album.id WHERE user_id IS NULL AND groupe_id IS NULL """ ).fetchall() diff --git a/partitioncloud/modules/classes/user.py b/partitioncloud/modules/classes/user.py index 90110ad..d222b32 100644 --- a/partitioncloud/modules/classes/user.py +++ b/partitioncloud/modules/classes/user.py @@ -194,15 +194,16 @@ class User(): def quit_album(self, album_uuid): db = get_db() - album = Album(uuid=album_uuid) db.execute( """ DELETE FROM contient_user + JOIN album + ON album.id = album_id WHERE user_id = ? - AND album_id = ? + AND album.uuid = ? """, - (self.id, album.id) + (self.id, album_uuid) ) db.commit()