Logged in user doesn't have plausible script

This commit is contained in:
Gabriel Augendre 2020-11-10 16:04:07 +01:00
parent b6b9d81081
commit db31dcadeb
No known key found for this signature in database
GPG key ID: 1E693F4CE4AEE7B4
3 changed files with 13 additions and 4 deletions

View file

@ -1,3 +1,3 @@
{% if plausible_domain is not None %} {% if plausible_domain is not None and not user.is_authenticated %}
<script async defer data-domain="{{ plausible_domain }}" src="https://plausible.augendre.info/js/plausible.js"></script> <script async defer data-domain="{{ plausible_domain }}" src="https://plausible.augendre.info/js/plausible.js"></script>
{% endif %} {% endif %}

View file

@ -6,13 +6,13 @@ from articles.models import Article, Page, User
@pytest.fixture() @pytest.fixture()
@pytest.mark.django_db @pytest.mark.django_db
def author(): def author() -> User:
return User.objects.create_user("gaugendre") return User.objects.create_user("gaugendre")
@pytest.fixture() @pytest.fixture()
@pytest.mark.django_db @pytest.mark.django_db
def published_article(author): def published_article(author: User) -> Article:
return Article.objects.create( return Article.objects.create(
title="Some interesting article title", title="Some interesting article title",
status=Article.PUBLISHED, status=Article.PUBLISHED,
@ -25,7 +25,7 @@ def published_article(author):
@pytest.fixture() @pytest.fixture()
@pytest.mark.django_db @pytest.mark.django_db
def published_page(author): def published_page(author: User) -> Page:
return Page.objects.create( return Page.objects.create(
title="Some interesting page title", title="Some interesting page title",
status=Article.PUBLISHED, status=Article.PUBLISHED,

View file

@ -59,3 +59,12 @@ def test_doesnt_have_plausible_if_unset(client: Client, settings):
res = client.get(reverse("articles-list")) res = client.get(reverse("articles-list"))
content = res.content.decode("utf-8") content = res.content.decode("utf-8")
assert "https://plausible.augendre.info/js/plausible.js" not in content assert "https://plausible.augendre.info/js/plausible.js" not in content
@pytest.mark.django_db
def test_logged_in_user_doesnt_have_plausible(client: Client, author: User, settings):
client.force_login(author)
settings.PLAUSIBLE_DOMAIN = "gabnotes.org"
res = client.get(reverse("articles-list"))
content = res.content.decode("utf-8")
assert "https://plausible.augendre.info/js/plausible.js" not in content