Private
Public Access
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7afda7d0ba |
No files matched your search
@@ -438,3 +438,38 @@ def test_stream_pagination_links_keep_the_feed_scope(client, alice):
|
|||||||
_, content = _stream_article_ids(client, {"filter": "all", "feed": feed.pk})
|
_, content = _stream_article_ids(client, {"filter": "all", "feed": feed.pk})
|
||||||
|
|
||||||
assert _link_query(content, "Older")["feed"] == str(feed.pk)
|
assert _link_query(content, "Older")["feed"] == str(feed.pk)
|
||||||
|
|
||||||
|
|
||||||
|
def test_templates_use_no_inline_event_handlers():
|
||||||
|
"""Production's CSP (script-src 'self') blocks inline on*= handlers —
|
||||||
|
they work in dev, where no CSP is sent, and silently do nothing in
|
||||||
|
production. Behavior belongs in static/js."""
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
pattern = re.compile(r"""<[^>]+\s(on[a-z]+)\s*=""", re.IGNORECASE)
|
||||||
|
offenders = []
|
||||||
|
for template in Path(settings.BASE_DIR, "templates").rglob("*.html"):
|
||||||
|
for match in pattern.finditer(template.read_text()):
|
||||||
|
offenders.append(f"{template.name}: {match.group(1)}")
|
||||||
|
assert offenders == []
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_article_detail_back_link_keeps_the_stream_scope(client, alice):
|
||||||
|
feed = Feed.objects.create(feed_url="https://example.com/feed.xml")
|
||||||
|
Subscription.objects.create(user=alice, feed=feed)
|
||||||
|
article = Article.objects.create(feed=feed, guid="g1", title="Hello")
|
||||||
|
|
||||||
|
client.login(username="alice", password="pw-alice-123")
|
||||||
|
stream = client.get(
|
||||||
|
reverse("reader:stream"), {"filter": "all", "feed": feed.pk}
|
||||||
|
).content.decode()
|
||||||
|
link = re.search(r'href="(/articles/\d+/\?[^"]+)"', stream)
|
||||||
|
assert link is not None
|
||||||
|
|
||||||
|
detail = client.get(link.group(1).replace("&", "&")).content.decode()
|
||||||
|
assert f"filter=all&feed={feed.pk}" in detail
|
||||||
|
assert "Back to stream" in detail
|
||||||
|
assert article.title in detail
|
||||||
@@ -238,6 +238,7 @@ def stream(request):
|
|||||||
# regardless of how a feed backdates an entry's published date.
|
# regardless of how a feed backdates an entry's published date.
|
||||||
"latest_article_id": queryset.aggregate(Max("id"))["id__max"] or 0,
|
"latest_article_id": queryset.aggregate(Max("id"))["id__max"] or 0,
|
||||||
"new_check_qs": urlencode(scope_params),
|
"new_check_qs": urlencode(scope_params),
|
||||||
|
"scope_qs": urlencode(scope_params),
|
||||||
}
|
}
|
||||||
return render(request, "reader/stream.html", context)
|
return render(request, "reader/stream.html", context)
|
||||||
|
|
||||||
@@ -311,7 +312,14 @@ def _load_article_and_mark_read(user, article_id):
|
|||||||
@login_required
|
@login_required
|
||||||
def article_detail(request, article_id):
|
def article_detail(request, article_id):
|
||||||
article = _load_article_and_mark_read(request.user, article_id)
|
article = _load_article_and_mark_read(request.user, article_id)
|
||||||
return render(request, "reader/article_detail.html", {"article": article})
|
# The stream passes its filter/tag/feed scope through the link so
|
||||||
|
# "Back to stream" returns to it instead of resetting to every feed.
|
||||||
|
back_params = {k: request.GET[k] for k in ("filter", "tag", "feed") if request.GET.get(k)}
|
||||||
|
return render(
|
||||||
|
request,
|
||||||
|
"reader/article_detail.html",
|
||||||
|
{"article": article, "back_qs": urlencode(back_params)},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
|||||||
+23
-5
@@ -1,8 +1,11 @@
|
|||||||
function toggleArticle(event, id) {
|
// Delegated listeners, not inline onclick="" attributes: production's
|
||||||
event.preventDefault();
|
// Content Security Policy (config/settings/prod.py, script-src 'self')
|
||||||
var link = event.currentTarget;
|
// blocks inline event handlers, which silently turned the title click into
|
||||||
|
// a plain link to the detail page and the new-articles banner into a no-op.
|
||||||
|
|
||||||
|
function toggleArticle(link) {
|
||||||
var row = link.closest("li.article-row");
|
var row = link.closest("li.article-row");
|
||||||
var body = document.getElementById("article-body-" + id);
|
var body = row.querySelector(".article-inline-body");
|
||||||
var wasOpen = row.classList.contains("is-expanded");
|
var wasOpen = row.classList.contains("is-expanded");
|
||||||
|
|
||||||
document.querySelectorAll("li.article-row.is-expanded").forEach(function (openRow) {
|
document.querySelectorAll("li.article-row.is-expanded").forEach(function (openRow) {
|
||||||
@@ -25,5 +28,20 @@ function toggleArticle(event, id) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.addEventListener("click", function (event) {
|
||||||
|
var link = event.target.closest("a.article-title[data-inline-url]");
|
||||||
|
if (link) {
|
||||||
|
// Leave modified clicks alone so "open in new tab" still works.
|
||||||
|
if (event.button !== 0 || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
event.preventDefault();
|
||||||
|
toggleArticle(link);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.target.closest(".new-articles-banner")) {
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -6,9 +6,8 @@
|
|||||||
<img src="{{ article.feed.favicon_url }}" alt="" class="feed-favicon">
|
<img src="{{ article.feed.favicon_url }}" alt="" class="feed-favicon">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<span class="article-feed-name">{{ article.feed.title|default:article.feed.feed_url }}</span>
|
<span class="article-feed-name">{{ article.feed.title|default:article.feed.feed_url }}</span>
|
||||||
<a href="{% url 'reader:article_detail' article.pk %}" class="article-title"
|
<a href="{% url 'reader:article_detail' article.pk %}{% if scope_qs %}?{{ scope_qs }}{% endif %}" class="article-title"
|
||||||
data-inline-url="{% url 'reader:article_inline' article.pk %}"
|
data-inline-url="{% url 'reader:article_inline' article.pk %}">{{ article.title|default:"(untitled)" }}</a>
|
||||||
onclick="return toggleArticle(event, {{ article.pk }})">{{ article.title|default:"(untitled)" }}</a>
|
|
||||||
{% if article.published_at %}
|
{% if article.published_at %}
|
||||||
<time class="article-time" datetime="{{ article.published_at|date:"c" }}" data-local-format="short">{{ article.published_at|date:"g:i A" }}</time>
|
<time class="article-time" datetime="{{ article.published_at|date:"c" }}" data-local-format="short">{{ article.published_at|date:"g:i A" }}</time>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{% if new_count %}
|
{% if new_count %}
|
||||||
<button type="button" class="new-articles-banner" onclick="location.reload()">
|
<button type="button" class="new-articles-banner">
|
||||||
{{ new_count }} new article{{ new_count|pluralize }} — click to show
|
{{ new_count }} new article{{ new_count|pluralize }} — click to show
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% block title %}{{ article.title|default:"Article" }} — Evection{% endblock %}
|
{% block title %}{{ article.title|default:"Article" }} — Evection{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<p><a href="{% url 'reader:stream' %}">← Back to stream</a></p>
|
<p><a href="{% url 'reader:stream' %}{% if back_qs %}?{{ back_qs }}{% endif %}">← Back to stream</a></p>
|
||||||
<article>
|
<article>
|
||||||
{% include "reader/_article_actions.html" %}
|
{% include "reader/_article_actions.html" %}
|
||||||
{% include "reader/_article_content.html" %}
|
{% include "reader/_article_content.html" %}
|
||||||
|
|||||||
Reference in new issue
Block a user