Render readable Markdown release notes in the web updater #151
No files matched your search
@@ -608,6 +608,15 @@ in-place procedure for custom service unit changes and for environments
|
|||||||
missing a dependency required by the target version. From 0.11 onward, the
|
missing a dependency required by the target version. From 0.11 onward, the
|
||||||
updater checks installed dependencies before stopping panel services.
|
updater checks installed dependencies before stopping panel services.
|
||||||
|
|
||||||
|
Markdown release notes require `markdown-it-py` in the panel's virtual
|
||||||
|
environment. To use the web updater for the first release with this feature,
|
||||||
|
install the dependency before starting the update. The in-place procedure
|
||||||
|
installs it with the panel package.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudo /opt/coulobre/bin/python -m pip install 'markdown-it-py>=4.3,<5'
|
||||||
|
```
|
||||||
|
|
||||||
The panel and its workers pause during the upgrade. Refresh **Updates** after
|
The panel and its workers pause during the upgrade. Refresh **Updates** after
|
||||||
the panel returns. The latest update status names the recovery directory in
|
the panel returns. The latest update status names the recovery directory in
|
||||||
`/var/lib/coulobre-update/`. The root-only directory holds the previous
|
`/var/lib/coulobre-update/`. The root-only directory holds the previous
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ dependencies = [
|
|||||||
"cryptography>=50",
|
"cryptography>=50",
|
||||||
"dnspython>=2.9.2,<3",
|
"dnspython>=2.9.2,<3",
|
||||||
"idna>=3.15,<4",
|
"idna>=3.15,<4",
|
||||||
|
"markdown-it-py>=4.3,<5",
|
||||||
"qrcode>=8.2,<9",
|
"qrcode>=8.2,<9",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -452,6 +452,55 @@ h2 {
|
|||||||
overflow-wrap: anywhere;
|
overflow-wrap: anywhere;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.update-release {
|
||||||
|
padding: 0.75rem 0.9rem;
|
||||||
|
border: 1px solid var(--line);
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.update-release > summary {
|
||||||
|
cursor: pointer;
|
||||||
|
font-weight: 680;
|
||||||
|
}
|
||||||
|
|
||||||
|
.release-notes {
|
||||||
|
max-width: 80ch;
|
||||||
|
margin-top: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.release-notes :is(h1, h2, h3, h4, h5, h6) {
|
||||||
|
margin: 1rem 0 0.25rem;
|
||||||
|
font-size: 1rem;
|
||||||
|
line-height: 1.3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.release-notes :is(p, ul, ol, pre, blockquote) {
|
||||||
|
margin: 0.5rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.release-notes :is(ul, ol) {
|
||||||
|
padding-inline-start: 1.35rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.release-notes pre {
|
||||||
|
padding: 0.7rem 0.85rem;
|
||||||
|
border-radius: 0.4rem;
|
||||||
|
background: var(--code-bg);
|
||||||
|
color: var(--code-text);
|
||||||
|
font-size: 0.85rem;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.update-release-form {
|
||||||
|
margin-top: 0.9rem;
|
||||||
|
padding-top: 0.85rem;
|
||||||
|
border-top: 1px solid var(--line);
|
||||||
|
}
|
||||||
|
|
||||||
|
.update-release-form .button {
|
||||||
|
justify-self: start;
|
||||||
|
}
|
||||||
|
|
||||||
.account-toolbar {
|
.account-toolbar {
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{% extends "hosting/base.html" %}
|
{% extends "hosting/base.html" %}
|
||||||
|
{% load release_notes %}
|
||||||
{% block title %}Updates · Coulobre Panel{% endblock %}
|
{% block title %}Updates · Coulobre Panel{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<header class="page-heading">
|
<header class="page-heading">
|
||||||
@@ -44,11 +45,13 @@
|
|||||||
<section class="surface" aria-labelledby="available-updates">
|
<section class="surface" aria-labelledby="available-updates">
|
||||||
<header class="section-heading"><h2 id="available-updates">Compatible releases</h2></header>
|
<header class="section-heading"><h2 id="available-updates">Compatible releases</h2></header>
|
||||||
{% for release in releases %}
|
{% for release in releases %}
|
||||||
<details class="section-text">
|
<details class="section-text update-release">
|
||||||
<summary>{{ release.version }}{% if release.prerelease %} · Prerelease{% endif %}</summary>
|
<summary>{{ release.version }}{% if release.prerelease %} · Prerelease{% endif %}</summary>
|
||||||
{{ release.notes|linebreaks }}
|
{% if release.notes %}
|
||||||
|
<div class="release-notes">{{ release.notes|release_notes_html }}</div>
|
||||||
|
{% endif %}
|
||||||
{% if may_apply and release.version in applyable_versions and update_status.state != "running" and update_status.state != "recovery_required" %}
|
{% if may_apply and release.version in applyable_versions and update_status.state != "running" and update_status.state != "recovery_required" %}
|
||||||
<form method="post" class="editor">
|
<form method="post" class="editor update-release-form">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input type="hidden" name="version" value="{{ release.version }}">
|
<input type="hidden" name="version" value="{{ release.version }}">
|
||||||
<input type="hidden" name="sha256" value="{{ release.sha256 }}">
|
<input type="hidden" name="sha256" value="{{ release.sha256 }}">
|
||||||
|
|||||||
Whitespace-only changes.
@@ -0,0 +1,29 @@
|
|||||||
|
from urllib.parse import urlsplit
|
||||||
|
|
||||||
|
from django import template
|
||||||
|
from django.utils.safestring import mark_safe
|
||||||
|
from markdown_it import MarkdownIt
|
||||||
|
|
||||||
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
|
class ReleaseNotesMarkdown(MarkdownIt):
|
||||||
|
def validateLink(self, url): # noqa: N802 - markdown-it-py hook
|
||||||
|
try:
|
||||||
|
link = urlsplit(url)
|
||||||
|
return (
|
||||||
|
link.scheme in {"https", "http"}
|
||||||
|
and bool(link.hostname)
|
||||||
|
and link.username is None
|
||||||
|
and link.password is None
|
||||||
|
)
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
markdown = ReleaseNotesMarkdown("js-default").disable("image")
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def release_notes_html(notes):
|
||||||
|
return mark_safe(markdown.render(notes))
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
from django.core.cache import cache
|
||||||
|
from django.test import TestCase
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from coulobre.release_updates import Release
|
||||||
|
|
||||||
|
|
||||||
|
class UpdateViewTests(TestCase):
|
||||||
|
@classmethod
|
||||||
|
def setUpTestData(cls):
|
||||||
|
cls.admin = get_user_model().objects.create_superuser("operator")
|
||||||
|
|
||||||
|
def test_catalog_renders_markdown_and_escapes_untrusted_content(self):
|
||||||
|
checksum = "a" * 64
|
||||||
|
notes = f"""## Changes
|
||||||
|
|
||||||
|
- **Upgrade** from the previous release.
|
||||||
|
- Follow the [deployment guide](https://example.test/docs#upgrade).
|
||||||
|
|
||||||
|
```text
|
||||||
|
{checksum} coulobre_panel-0.11.1rc1.tar.gz
|
||||||
|
```
|
||||||
|
|
||||||
|
<script>Should stay visible as text.</script>
|
||||||
|
|
||||||
|
[Unsafe](javascript:invalid) [Local action](/updates/)
|
||||||
|
|
||||||
|

|
||||||
|
"""
|
||||||
|
release = Release("0.11.1rc1", notes, True, checksum)
|
||||||
|
self.client.force_login(self.admin)
|
||||||
|
cache.clear()
|
||||||
|
self.addCleanup(cache.clear)
|
||||||
|
path = "coulobre.hosting.update_views"
|
||||||
|
with (
|
||||||
|
patch(f"{path}.SOCKET", **{"is_socket.return_value": True}),
|
||||||
|
patch(f"{path}.inspect_linked_nodes", return_value={"nodes": []}),
|
||||||
|
patch(f"{path}.available_releases", return_value=[release]),
|
||||||
|
):
|
||||||
|
response = self.client.get(reverse("panel:updates"))
|
||||||
|
|
||||||
|
self.assertContains(response, "<h2>Changes</h2>", html=True)
|
||||||
|
self.assertContains(response, "<strong>Upgrade</strong>", html=True)
|
||||||
|
self.assertContains(response, '<pre><code class="language-text">')
|
||||||
|
self.assertContains(response, f"{checksum} coulobre_panel-")
|
||||||
|
self.assertContains(
|
||||||
|
response, 'href="https://example.test/docs#upgrade"'
|
||||||
|
)
|
||||||
|
self.assertContains(response, "<script>")
|
||||||
|
self.assertNotContains(response, "<script>Should stay")
|
||||||
|
self.assertNotContains(response, 'href="javascript:')
|
||||||
|
self.assertNotContains(response, 'href="/updates/">Local action')
|
||||||
|
self.assertNotContains(response, '<img src="https://example.test/')
|
||||||
Reference in new issue
Block a user