From d29d161ac66d4239d5a1f5ba2aa578699227610a Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 5 Oct 2021 20:36:38 +0200 Subject: [PATCH] admin: clear update notification when notification's version matches current version Signed-off-by: Jens Langhammer --- authentik/admin/apps.py | 5 +++++ authentik/admin/tasks.py | 14 +++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/authentik/admin/apps.py b/authentik/admin/apps.py index 0c1da4d62..e3e3567ae 100644 --- a/authentik/admin/apps.py +++ b/authentik/admin/apps.py @@ -8,3 +8,8 @@ class AuthentikAdminConfig(AppConfig): name = "authentik.admin" label = "authentik_admin" verbose_name = "authentik Admin" + + def ready(self): + from authentik.admin.tasks import clear_update_notifications + + clear_update_notifications.delay() diff --git a/authentik/admin/tasks.py b/authentik/admin/tasks.py index 018b05f26..4149b210f 100644 --- a/authentik/admin/tasks.py +++ b/authentik/admin/tasks.py @@ -10,7 +10,7 @@ from requests import RequestException from structlog.stdlib import get_logger from authentik import ENV_GIT_HASH_KEY, __version__ -from authentik.events.models import Event, EventAction +from authentik.events.models import Event, EventAction, Notification from authentik.events.monitored_tasks import MonitoredTask, TaskResult, TaskResultStatus from authentik.lib.config import CONFIG from authentik.lib.utils.http import get_http_session @@ -35,6 +35,18 @@ def _set_prom_info(): ) +@CELERY_APP.task() +def clear_update_notifications(): + """Clear update notifications on startup if the notification was for the version + we're running now.""" + for notification in Notification.objects.filter(event__action=EventAction.UPDATE_AVAILABLE): + if "new_version" not in notification.event.context: + continue + notification_version = notification.event.context["new_version"] + if notification_version == __version__: + notification.delete() + + @CELERY_APP.task(bind=True, base=MonitoredTask) def update_latest_version(self: MonitoredTask): """Update latest version info"""