From b74c08620a9b5c791828ff72ae6ebc240d8bf9a5 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 3 Feb 2021 21:19:43 +0100 Subject: [PATCH] admin: add link to changelog to update events --- authentik/admin/tasks.py | 12 ++++++++++-- authentik/admin/tests/test_tasks.py | 5 ++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/authentik/admin/tasks.py b/authentik/admin/tasks.py index 336cfa37ac..3d5f937f1d 100644 --- a/authentik/admin/tasks.py +++ b/authentik/admin/tasks.py @@ -1,5 +1,8 @@ """authentik admin tasks""" +import re + from django.core.cache import cache +from django.core.validators import URLValidator from packaging.version import parse from requests import RequestException, get from structlog.stdlib import get_logger @@ -11,7 +14,9 @@ from authentik.root.celery import CELERY_APP LOGGER = get_logger() VERSION_CACHE_KEY = "authentik_latest_version" -VERSION_CACHE_TIMEOUT = 2 * 60 * 60 # 2 hours +VERSION_CACHE_TIMEOUT = 8 * 60 * 60 # 8 hours +# Chop of the first ^ because we want to search the entire string +URL_FINDER = URLValidator.regex.pattern[1:] @CELERY_APP.task(bind=True, base=MonitoredTask) @@ -39,7 +44,10 @@ def update_latest_version(self: MonitoredTask): context__new_version=upstream_version, ).exists(): return - Event.new(EventAction.UPDATE_AVAILABLE, new_version=upstream_version).save() + event_dict = {"new_version": upstream_version} + if m := re.search(URL_FINDER, data.get("body", "")): + event_dict["message"] = f"Changelog: {m.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) self.set_status(TaskResult(TaskResultStatus.ERROR).with_error(exc)) diff --git a/authentik/admin/tests/test_tasks.py b/authentik/admin/tests/test_tasks.py index a1ccc4add2..17cf946dcf 100644 --- a/authentik/admin/tests/test_tasks.py +++ b/authentik/admin/tests/test_tasks.py @@ -32,7 +32,8 @@ REQUEST_MOCK_VALID = Mock( return_value=MockResponse( 200, """{ - "tag_name": "version/99999999.9999999" + "tag_name": "version/99999999.9999999", + "body": "https://goauthentik.io/test" }""", ) ) @@ -52,6 +53,7 @@ class TestAdminTasks(TestCase): Event.objects.filter( action=EventAction.UPDATE_AVAILABLE, context__new_version="99999999.9999999", + context__message="Changelog: https://goauthentik.io/test", ).exists() ) # test that a consecutive check doesn't create a duplicate event @@ -61,6 +63,7 @@ class TestAdminTasks(TestCase): Event.objects.filter( action=EventAction.UPDATE_AVAILABLE, context__new_version="99999999.9999999", + context__message="Changelog: https://goauthentik.io/test", ) ), 1,