admin: Handle latest version unknown in admin dashboard (#8858)

* Handle latest  version unknown in admin dashboard

* fix tests

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* fix tsc

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

---------

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
Co-authored-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
RoboMagus
2024-03-15 17:49:02 +01:00
committed by GitHub
parent 56f267146f
commit ce0775239d
4 changed files with 22 additions and 5 deletions

View File

@ -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))

View File

@ -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)

View File

@ -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

View File

@ -31,9 +31,15 @@ export class VersionStatusCard extends AdminStatusCard<Version> {
message: html`${msg(str`${value.versionLatest} is available!`)}`,
});
}
if (value.versionLatestValid) {
return Promise.resolve<AdminStatus>({
icon: "fa fa-check-circle pf-m-success",
message: html`${msg("Up-to-date!")}`,
});
}
return Promise.resolve<AdminStatus>({
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")}`,
});
}