notification import/export (#413)
Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
parent
2c970b8f92
commit
dcd9567059
9 changed files with 55 additions and 8 deletions
|
@ -42,6 +42,10 @@ export default {
|
|||
value: true,
|
||||
text: this.$t("group.groups"),
|
||||
},
|
||||
notifications: {
|
||||
value: true,
|
||||
text: this.$t("events.notification"),
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
|
@ -57,6 +61,7 @@ export default {
|
|||
pages: this.options.pages.value,
|
||||
users: this.options.users.value,
|
||||
groups: this.options.groups.value,
|
||||
notifications: this.options.notifications.value,
|
||||
});
|
||||
},
|
||||
},
|
||||
|
|
|
@ -98,6 +98,7 @@ export default {
|
|||
pages: true,
|
||||
users: true,
|
||||
groups: true,
|
||||
notifications: true,
|
||||
};
|
||||
this.availableTemplates = [];
|
||||
this.selectedTemplates = [];
|
||||
|
@ -122,10 +123,13 @@ export default {
|
|||
themes: this.options.themes,
|
||||
users: this.options.users,
|
||||
groups: this.options.groups,
|
||||
notifications: this.options.notifications,
|
||||
},
|
||||
templates: this.selectedTemplates,
|
||||
};
|
||||
|
||||
console.log(data);
|
||||
|
||||
if (await api.backups.create(data)) {
|
||||
this.$emit("created");
|
||||
}
|
||||
|
|
|
@ -97,6 +97,7 @@ export default {
|
|||
themes: this.options.themes,
|
||||
users: this.options.users,
|
||||
groups: this.options.groups,
|
||||
notifications: this.options.notifications,
|
||||
};
|
||||
this.loading = true;
|
||||
const importData = await this.importBackup(eventData);
|
||||
|
|
|
@ -120,13 +120,7 @@ export default {
|
|||
|
||||
let data = {
|
||||
tag: this.tag,
|
||||
options: {
|
||||
recipes: true,
|
||||
settings: true,
|
||||
themes: true,
|
||||
users: true,
|
||||
groups: true,
|
||||
},
|
||||
options: {},
|
||||
templates: [],
|
||||
};
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -11,6 +11,7 @@ class BackupOptions(BaseModel):
|
|||
themes: bool = True
|
||||
groups: bool = True
|
||||
users: bool = True
|
||||
notifications: bool = True
|
||||
|
||||
class Config:
|
||||
schema_extra = {
|
||||
|
|
|
@ -31,3 +31,7 @@ class UserImport(ImportBase):
|
|||
|
||||
class CustomPageImport(ImportBase):
|
||||
pass
|
||||
|
||||
|
||||
class NotificationImport(ImportBase):
|
||||
pass
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue