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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 55 additions and 8 deletions

View File

@ -42,6 +42,10 @@ export default {
value: true, value: true,
text: this.$t("group.groups"), text: this.$t("group.groups"),
}, },
notifications: {
value: true,
text: this.$t("events.notification"),
},
}, },
}; };
}, },
@ -57,6 +61,7 @@ export default {
pages: this.options.pages.value, pages: this.options.pages.value,
users: this.options.users.value, users: this.options.users.value,
groups: this.options.groups.value, groups: this.options.groups.value,
notifications: this.options.notifications.value,
}); });
}, },
}, },

View File

@ -98,6 +98,7 @@ export default {
pages: true, pages: true,
users: true, users: true,
groups: true, groups: true,
notifications: true,
}; };
this.availableTemplates = []; this.availableTemplates = [];
this.selectedTemplates = []; this.selectedTemplates = [];
@ -122,10 +123,13 @@ export default {
themes: this.options.themes, themes: this.options.themes,
users: this.options.users, users: this.options.users,
groups: this.options.groups, groups: this.options.groups,
notifications: this.options.notifications,
}, },
templates: this.selectedTemplates, templates: this.selectedTemplates,
}; };
console.log(data);
if (await api.backups.create(data)) { if (await api.backups.create(data)) {
this.$emit("created"); this.$emit("created");
} }

View File

@ -97,6 +97,7 @@ export default {
themes: this.options.themes, themes: this.options.themes,
users: this.options.users, users: this.options.users,
groups: this.options.groups, groups: this.options.groups,
notifications: this.options.notifications,
}; };
this.loading = true; this.loading = true;
const importData = await this.importBackup(eventData); const importData = await this.importBackup(eventData);

View File

@ -120,13 +120,7 @@ export default {
let data = { let data = {
tag: this.tag, tag: this.tag,
options: { options: {},
recipes: true,
settings: true,
themes: true,
users: true,
groups: true,
},
templates: [], templates: [],
}; };

View File

@ -46,6 +46,7 @@ def export_database(background_tasks: BackgroundTasks, data: BackupJob, session:
export_themes=data.options.themes, export_themes=data.options.themes,
export_users=data.options.users, export_users=data.options.users,
export_groups=data.options.groups, export_groups=data.options.groups,
export_notifications=data.options.notifications,
) )
background_tasks.add_task( background_tasks.add_task(
create_backup_event, "Database Backup", f"Manual Backup Created '{Path(export_path).name}'", session 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 themes: bool = True
groups: bool = True groups: bool = True
users: bool = True users: bool = True
notifications: bool = True
class Config: class Config:
schema_extra = { schema_extra = {

View File

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

View File

@ -111,6 +111,7 @@ def backup_all(
export_themes=True, export_themes=True,
export_users=True, export_users=True,
export_groups=True, export_groups=True,
export_notifications=True,
): ):
db_export = ExportDatabase(tag=tag, templates=templates) db_export = ExportDatabase(tag=tag, templates=templates)
@ -140,6 +141,10 @@ def backup_all(
all_themes = db.themes.get_all(session) all_themes = db.themes.get_all(session)
db_export.export_items(all_themes, "themes") 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() return db_export.finish_export()

View File

@ -6,8 +6,17 @@ from typing import Callable
from mealie.core.config import app_dirs from mealie.core.config import app_dirs
from mealie.db.database import db from mealie.db.database import db
from mealie.schema.event_notifications import EventNotificationIn
from mealie.schema.recipe import Recipe 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.settings import CustomPageOut, SiteSettings
from mealie.schema.theme import SiteTheme from mealie.schema.theme import SiteTheme
from mealie.schema.user import UpdateGroup, UserInDB from mealie.schema.user import UpdateGroup, UserInDB
@ -148,6 +157,24 @@ class ImportDatabase:
return theme_imports 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 def import_settings(self): # ! Broken
settings_file = self.import_dir.joinpath("settings", "settings.json") settings_file = self.import_dir.joinpath("settings", "settings.json")
settings = ImportDatabase.read_models_file(settings_file, SiteSettings) settings = ImportDatabase.read_models_file(settings_file, SiteSettings)
@ -304,6 +331,7 @@ def import_database(
import_themes=True, import_themes=True,
import_users=True, import_users=True,
import_groups=True, import_groups=True,
import_notifications=True,
force_import: bool = False, force_import: bool = False,
rebase: bool = False, rebase: bool = False,
): ):
@ -333,6 +361,9 @@ def import_database(
if import_users: if import_users:
user_report = import_session.import_users() user_report = import_session.import_users()
if import_notifications:
notification_report = import_session.import_notifications()
import_session.clean_up() import_session.clean_up()
return { return {
@ -342,4 +373,5 @@ def import_database(
"pageImports": page_report, "pageImports": page_report,
"groupImports": group_report, "groupImports": group_report,
"userImports": user_report, "userImports": user_report,
"notificationImports": notification_report,
} }