notification import/export (#413)

Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
Hayden
2021-05-20 19:16:42 -08:00
committed by GitHub
parent 2c970b8f92
commit dcd9567059
9 changed files with 55 additions and 8 deletions

View File

@@ -46,6 +46,7 @@ def export_database(background_tasks: BackgroundTasks, data: BackupJob, session:
export_themes=data.options.themes,
export_users=data.options.users,
export_groups=data.options.groups,
export_notifications=data.options.notifications,
)
background_tasks.add_task(
create_backup_event, "Database Backup", f"Manual Backup Created '{Path(export_path).name}'", session

View File

@@ -11,6 +11,7 @@ class BackupOptions(BaseModel):
themes: bool = True
groups: bool = True
users: bool = True
notifications: bool = True
class Config:
schema_extra = {

View File

@@ -31,3 +31,7 @@ class UserImport(ImportBase):
class CustomPageImport(ImportBase):
pass
class NotificationImport(ImportBase):
pass

View File

@@ -111,6 +111,7 @@ def backup_all(
export_themes=True,
export_users=True,
export_groups=True,
export_notifications=True,
):
db_export = ExportDatabase(tag=tag, templates=templates)
@@ -140,6 +141,10 @@ def backup_all(
all_themes = db.themes.get_all(session)
db_export.export_items(all_themes, "themes")
if export_notifications:
all_notifications = db.event_notifications.get_all(session)
db_export.export_items(all_notifications, "notifications")
return db_export.finish_export()

View File

@@ -6,8 +6,17 @@ from typing import Callable
from mealie.core.config import app_dirs
from mealie.db.database import db
from mealie.schema.event_notifications import EventNotificationIn
from mealie.schema.recipe import Recipe
from mealie.schema.restore import CustomPageImport, GroupImport, RecipeImport, SettingsImport, ThemeImport, UserImport
from mealie.schema.restore import (
CustomPageImport,
GroupImport,
NotificationImport,
RecipeImport,
SettingsImport,
ThemeImport,
UserImport,
)
from mealie.schema.settings import CustomPageOut, SiteSettings
from mealie.schema.theme import SiteTheme
from mealie.schema.user import UpdateGroup, UserInDB
@@ -148,6 +157,24 @@ class ImportDatabase:
return theme_imports
def import_notifications(self):
notify_file = self.import_dir.joinpath("notifications", "notifications.json")
notifications = ImportDatabase.read_models_file(notify_file, EventNotificationIn)
import_notifications = []
for notify in notifications:
import_status = self.import_model(
db_table=db.event_notifications,
model=notify,
return_model=NotificationImport,
name_attr="name",
search_key="notification_url",
)
import_notifications.append(import_status)
return import_notifications
def import_settings(self): # ! Broken
settings_file = self.import_dir.joinpath("settings", "settings.json")
settings = ImportDatabase.read_models_file(settings_file, SiteSettings)
@@ -304,6 +331,7 @@ def import_database(
import_themes=True,
import_users=True,
import_groups=True,
import_notifications=True,
force_import: bool = False,
rebase: bool = False,
):
@@ -333,6 +361,9 @@ def import_database(
if import_users:
user_report = import_session.import_users()
if import_notifications:
notification_report = import_session.import_notifications()
import_session.clean_up()
return {
@@ -342,4 +373,5 @@ def import_database(
"pageImports": page_report,
"groupImports": group_report,
"userImports": user_report,
"notificationImports": notification_report,
}