feat: add iCal calendar subscriptions
This commit is contained in:
@@ -19,6 +19,7 @@ from backend.models import (
|
||||
BackupImport,
|
||||
BackupImportEntity,
|
||||
BackupPreflight,
|
||||
CalendarSubscription,
|
||||
Countdown,
|
||||
Folder,
|
||||
Habit,
|
||||
@@ -65,6 +66,7 @@ ENTITY_MODELS = {
|
||||
"habit_pauses": HabitPause,
|
||||
"countdowns": Countdown,
|
||||
"memos": Memo,
|
||||
"calendar_subscriptions": CalendarSubscription,
|
||||
"attachments": Attachment,
|
||||
}
|
||||
RELATIONS = {
|
||||
@@ -392,6 +394,9 @@ def _validate_recurrence_graph(parsed: ParsedArchive) -> None:
|
||||
|
||||
def validate_archive(parsed: ParsedArchive) -> None:
|
||||
unknown = set(parsed.entities) - set(ENTITY_MODELS)
|
||||
# Calendar subscriptions were introduced after backup v2. Treat their
|
||||
# absence as an empty collection so archives from older Dodo releases remain restorable.
|
||||
parsed.entities.setdefault("calendar_subscriptions", [])
|
||||
missing = set(ENTITY_MODELS) - set(parsed.entities)
|
||||
if unknown:
|
||||
raise backup_error("backup_entity_unknown", "备份包含未知实体")
|
||||
@@ -611,7 +616,16 @@ async def restore_v2(
|
||||
await db.execute(delete(HabitPause).where(
|
||||
HabitPause.habit_id.in_(select(Habit.id).where(Habit.user_id == user.id))
|
||||
))
|
||||
for model in (Attachment, Memo, Countdown, Task, Habit, TaskList, Folder):
|
||||
for model in (
|
||||
Attachment,
|
||||
CalendarSubscription,
|
||||
Memo,
|
||||
Countdown,
|
||||
Task,
|
||||
Habit,
|
||||
TaskList,
|
||||
Folder,
|
||||
):
|
||||
await db.execute(delete(model).where(model.user_id == user.id))
|
||||
await db.execute(delete(BackupImportEntity).where(BackupImportEntity.user_id == user.id))
|
||||
await db.execute(delete(BackupImport).where(BackupImport.user_id == user.id))
|
||||
|
||||
Reference in New Issue
Block a user