diff --git a/.gitignore b/.gitignore index d3b153ad..86cf2616 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,4 @@ docker/* !docker/docker-compose.yml lang_sort_log.txt lang_sort.txt +app/migrations/status diff --git a/app/classes/shared/helpers.py b/app/classes/shared/helpers.py index 89de0d5b..5a03d04f 100644 --- a/app/classes/shared/helpers.py +++ b/app/classes/shared/helpers.py @@ -58,6 +58,7 @@ class Helpers: def __init__(self): self.root_dir = os.path.abspath(os.path.curdir) + self.read_annc = False self.config_dir = os.path.join(self.root_dir, "app", "config") self.webroot = os.path.join(self.root_dir, "app", "frontend") self.servers_dir = os.path.join(self.root_dir, "servers") @@ -615,12 +616,49 @@ class Helpers: return version_data - def get_announcements(self): + def check_migrations(self) -> None: + if self.read_annc == False: + self.read_annc = True + for file in os.listdir( + os.path.join(self.root_dir, "app", "migrations", "status") + ): + with open( + os.path.join(self.root_dir, "app", "migrations", "status", file), + "r", + encoding="utf-8", + ) as notif_file: + file_json = json.load(notif_file) + for notif in file_json: + if not file_json[notif].get("status"): + self.migration_notifications.append(file_json[notif]) + + def get_announcements(self, lang=None): try: data = [] response = requests.get("https://craftycontrol.com/notify", timeout=2) data = json.loads(response.content) - data.extend(self.migration_notifications) + if not lang: + lang = self.get_setting("language") + self.check_migrations() + for migration_warning in self.migration_notifications: + if not migration_warning.get("status"): + data.append( + { + "id": migration_warning.get("pid"), + "title": self.translation.translate( + "notify", + f"{migration_warning.get('type')}_title", + lang, + ), + "date": "", + "desc": self.translation.translate( + "notify", + f"{migration_warning.get('type')}_desc", + lang, + ), + "link": "", + } + ) if self.update_available: data.append(self.update_available) return data diff --git a/app/classes/web/routes/api/crafty/announcements/index.py b/app/classes/web/routes/api/crafty/announcements/index.py index d66c4473..2cd80ba6 100644 --- a/app/classes/web/routes/api/crafty/announcements/index.py +++ b/app/classes/web/routes/api/crafty/announcements/index.py @@ -29,7 +29,7 @@ class ApiAnnounceIndexHandler(BaseApiHandler): _, ) = auth_data - data = self.helper.get_announcements() + data = self.helper.get_announcements(auth_data[4]["lang"]) if not data: return self.finish_json( 424, diff --git a/app/migrations/20240308_multi-backup.py b/app/migrations/20240308_multi-backup.py index 4c7f8279..be0ffce4 100644 --- a/app/migrations/20240308_multi-backup.py +++ b/app/migrations/20240308_multi-backup.py @@ -25,6 +25,8 @@ def migrate(migrator: Migrator, database, **kwargs): """ Write your migrations here. """ + backup_migration_status = True + schedule_migration_status = True db = database Console.info("Starting Backups migrations") Console.info( @@ -241,6 +243,7 @@ def migrate(migrator: Migrator, database, **kwargs): try: backup = NewBackups.get(NewBackups.server_id == schedule.server_id) except: + schedule_migration_status = False Console.error( "Could not find backup with selected server ID. Omitting from register." ) @@ -272,17 +275,29 @@ def migrate(migrator: Migrator, database, **kwargs): # Rename the new table to backups migrator.rename_table("new_schedules", "schedules") - with open("status/20240308_multi-backup.json", "w", encoding="utf-8") as file: + with open( + os.path.join( + os.path.abspath(os.path.curdir), + "app", + "migrations", + "status", + "20240308_multi-backup.json", + ), + "w", + encoding="utf-8", + ) as file: file.write( json.dumps( { "backup_migration": { + "type": "backup", "status": backup_migration_status, - "pid": uuid.uuid4(), + "pid": str(uuid.uuid4()), }, "schedule_migration": { + "type": "schedule", "status": schedule_migration_status, - "pid": uuid.uuid4(), + "pid": str(uuid.uuid4()), }, } ) diff --git a/app/translations/en_EN.json b/app/translations/en_EN.json index ed35ae9c..8d57bfc1 100644 --- a/app/translations/en_EN.json +++ b/app/translations/en_EN.json @@ -235,7 +235,11 @@ "finishedPreparing": "We've finished preparing your support logs. Please click download to download", "logout": "Logout", "preparingLogs": " Please wait while we prepare your logs... We`ll send a notification when they`re ready. This may take a while for large deployments.", - "supportLogs": "Support Logs" + "supportLogs": "Support Logs", + "backup_title": "Backup Migration Warning", + "backup_desc": "We detected the backup migration may have partially or fully failed. Please confirm your backups records on the backups tab.", + "schedule_title": "Schedules Migration Warning", + "schedule_desc": "We detected some or all of your scheduled tasks were not successfully transfered during the upgrade. Please confirm your schedules in the schedules tab." }, "offline": { "offline": "Offline", @@ -695,4 +699,4 @@ "webhook_body": "Webhook Body", "webhooks": "Webhooks" } -} +} \ No newline at end of file