Fixes for kobosync with multiple users (#2230)

This commit is contained in:
Ozzie Isaacs
2022-01-08 14:24:31 +01:00
parent e3dbf7a88d
commit df67079573
3 changed files with 23 additions and 21 deletions

View File

@@ -20,7 +20,7 @@
from flask_login import current_user
from . import ub
import datetime
from sqlalchemy.sql.expression import or_, and_
from sqlalchemy.sql.expression import or_, and_, true
# Add the current book id to kobo_synced_books table for current user, if entry is already present,
# do nothing (safety precaution)
@@ -36,9 +36,13 @@ def add_synced_books(book_id):
# Select all entries of current book in kobo_synced_books table, which are from current user and delete them
def remove_synced_book(book_id):
def remove_synced_book(book_id, all=False):
if not all:
user = ub.KoboSyncedBooks.user_id == current_user.id
else:
user = true()
ub.session.query(ub.KoboSyncedBooks).filter(ub.KoboSyncedBooks.book_id == book_id) \
.filter(ub.KoboSyncedBooks.user_id == current_user.id).delete()
.filter(user).delete()
ub.session_commit()