From ce0775239d7b1b4b2f864e045292dbf077301319 Mon Sep 17 00:00:00 2001 From: RoboMagus <68224306+RoboMagus@users.noreply.github.com> Date: Fri, 15 Mar 2024 17:49:02 +0100 Subject: [PATCH] admin: Handle latest version unknown in admin dashboard (#8858) * Handle latest version unknown in admin dashboard * fix tests Signed-off-by: Jens Langhammer * fix tsc Signed-off-by: Jens Langhammer --------- Signed-off-by: Jens Langhammer Co-authored-by: Jens Langhammer --- authentik/admin/api/version.py | 7 ++++++- authentik/admin/tasks.py | 5 +++-- schema.yml | 5 +++++ .../admin/admin-overview/cards/VersionStatusCard.ts | 10 ++++++++-- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/authentik/admin/api/version.py b/authentik/admin/api/version.py index 855a5016d7..d09487e9de 100644 --- a/authentik/admin/api/version.py +++ b/authentik/admin/api/version.py @@ -10,7 +10,7 @@ from rest_framework.response import Response from rest_framework.views import APIView from authentik import __version__, get_build_hash -from authentik.admin.tasks import VERSION_CACHE_KEY, update_latest_version +from authentik.admin.tasks import VERSION_CACHE_KEY, VERSION_NULL, update_latest_version from authentik.core.api.utils import PassiveSerializer @@ -19,6 +19,7 @@ class VersionSerializer(PassiveSerializer): version_current = SerializerMethodField() version_latest = SerializerMethodField() + version_latest_valid = SerializerMethodField() build_hash = SerializerMethodField() outdated = SerializerMethodField() @@ -38,6 +39,10 @@ class VersionSerializer(PassiveSerializer): return __version__ return version_in_cache + def get_version_latest_valid(self, _) -> str: + """Check if latest version is valid""" + return cache.get(VERSION_CACHE_KEY) != VERSION_NULL + def get_outdated(self, instance) -> bool: """Check if we're running the latest version""" return parse(self.get_version_current(instance)) < parse(self.get_version_latest(instance)) diff --git a/authentik/admin/tasks.py b/authentik/admin/tasks.py index f5aeff028b..8bafb3bef4 100644 --- a/authentik/admin/tasks.py +++ b/authentik/admin/tasks.py @@ -18,6 +18,7 @@ from authentik.lib.utils.http import get_http_session from authentik.root.celery import CELERY_APP LOGGER = get_logger() +VERSION_NULL = "0.0.0" VERSION_CACHE_KEY = "authentik_latest_version" VERSION_CACHE_TIMEOUT = 8 * 60 * 60 # 8 hours # Chop of the first ^ because we want to search the entire string @@ -55,7 +56,7 @@ def clear_update_notifications(): def update_latest_version(self: SystemTask): """Update latest version info""" if CONFIG.get_bool("disable_update_check"): - cache.set(VERSION_CACHE_KEY, "0.0.0", VERSION_CACHE_TIMEOUT) + cache.set(VERSION_CACHE_KEY, VERSION_NULL, VERSION_CACHE_TIMEOUT) self.set_status(TaskStatus.WARNING, "Version check disabled.") return try: @@ -82,7 +83,7 @@ def update_latest_version(self: SystemTask): event_dict["message"] = f"Changelog: {match.group()}" Event.new(EventAction.UPDATE_AVAILABLE, **event_dict).save() except (RequestException, IndexError) as exc: - cache.set(VERSION_CACHE_KEY, "0.0.0", VERSION_CACHE_TIMEOUT) + cache.set(VERSION_CACHE_KEY, VERSION_NULL, VERSION_CACHE_TIMEOUT) self.set_error(exc) diff --git a/schema.yml b/schema.yml index f2f1c2e23b..6ac8eb9eb1 100644 --- a/schema.yml +++ b/schema.yml @@ -45583,6 +45583,10 @@ components: type: string description: Get latest version from cache readOnly: true + version_latest_valid: + type: boolean + description: Latest version query is a valid non-default value + readOnly: true build_hash: type: string description: Get build hash, if version is not latest or released @@ -45596,6 +45600,7 @@ components: - outdated - version_current - version_latest + - version_latest_valid WebAuthnDevice: type: object description: Serializer for WebAuthn authenticator devices diff --git a/web/src/admin/admin-overview/cards/VersionStatusCard.ts b/web/src/admin/admin-overview/cards/VersionStatusCard.ts index 01689aede7..a8c94cc377 100644 --- a/web/src/admin/admin-overview/cards/VersionStatusCard.ts +++ b/web/src/admin/admin-overview/cards/VersionStatusCard.ts @@ -31,9 +31,15 @@ export class VersionStatusCard extends AdminStatusCard { message: html`${msg(str`${value.versionLatest} is available!`)}`, }); } + if (value.versionLatestValid) { + return Promise.resolve({ + icon: "fa fa-check-circle pf-m-success", + message: html`${msg("Up-to-date!")}`, + }); + } return Promise.resolve({ - icon: "fa fa-check-circle pf-m-success", - message: html`${msg("Up-to-date!")}`, + icon: "fa fa-question-circle", + message: html`${msg("Latest version unknown")}`, }); }