admin: add link to changelog to update events
This commit is contained in:
parent
e25d03d8f4
commit
b74c08620a
|
@ -1,5 +1,8 @@
|
||||||
"""authentik admin tasks"""
|
"""authentik admin tasks"""
|
||||||
|
import re
|
||||||
|
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
|
from django.core.validators import URLValidator
|
||||||
from packaging.version import parse
|
from packaging.version import parse
|
||||||
from requests import RequestException, get
|
from requests import RequestException, get
|
||||||
from structlog.stdlib import get_logger
|
from structlog.stdlib import get_logger
|
||||||
|
@ -11,7 +14,9 @@ from authentik.root.celery import CELERY_APP
|
||||||
|
|
||||||
LOGGER = get_logger()
|
LOGGER = get_logger()
|
||||||
VERSION_CACHE_KEY = "authentik_latest_version"
|
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)
|
@CELERY_APP.task(bind=True, base=MonitoredTask)
|
||||||
|
@ -39,7 +44,10 @@ def update_latest_version(self: MonitoredTask):
|
||||||
context__new_version=upstream_version,
|
context__new_version=upstream_version,
|
||||||
).exists():
|
).exists():
|
||||||
return
|
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:
|
except (RequestException, IndexError) as exc:
|
||||||
cache.set(VERSION_CACHE_KEY, "0.0.0", VERSION_CACHE_TIMEOUT)
|
cache.set(VERSION_CACHE_KEY, "0.0.0", VERSION_CACHE_TIMEOUT)
|
||||||
self.set_status(TaskResult(TaskResultStatus.ERROR).with_error(exc))
|
self.set_status(TaskResult(TaskResultStatus.ERROR).with_error(exc))
|
||||||
|
|
|
@ -32,7 +32,8 @@ REQUEST_MOCK_VALID = Mock(
|
||||||
return_value=MockResponse(
|
return_value=MockResponse(
|
||||||
200,
|
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(
|
Event.objects.filter(
|
||||||
action=EventAction.UPDATE_AVAILABLE,
|
action=EventAction.UPDATE_AVAILABLE,
|
||||||
context__new_version="99999999.9999999",
|
context__new_version="99999999.9999999",
|
||||||
|
context__message="Changelog: https://goauthentik.io/test",
|
||||||
).exists()
|
).exists()
|
||||||
)
|
)
|
||||||
# test that a consecutive check doesn't create a duplicate event
|
# test that a consecutive check doesn't create a duplicate event
|
||||||
|
@ -61,6 +63,7 @@ class TestAdminTasks(TestCase):
|
||||||
Event.objects.filter(
|
Event.objects.filter(
|
||||||
action=EventAction.UPDATE_AVAILABLE,
|
action=EventAction.UPDATE_AVAILABLE,
|
||||||
context__new_version="99999999.9999999",
|
context__new_version="99999999.9999999",
|
||||||
|
context__message="Changelog: https://goauthentik.io/test",
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
1,
|
1,
|
||||||
|
|
Reference in New Issue