-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into section-external-content
- Loading branch information
Showing
11 changed files
with
244 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<configure | ||
xmlns="http://namespaces.zope.org/zope" | ||
xmlns:browser="http://namespaces.zope.org/browser" | ||
> | ||
<include package="plone.app.contentmenu" /> | ||
<browser:page | ||
name="stats" | ||
title="Plausible dashboard" | ||
template="plausible.pt" | ||
menu="plone_displayviews" | ||
for="plone.base.interfaces.siteroot.IPloneSiteRoot" | ||
class=".plausible.PlausibleView" | ||
permission="cmf.ModifyPortalContent" | ||
layer="imio.smartweb.core.interfaces.IImioSmartwebCoreLayer" | ||
/> | ||
|
||
</configure> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" | ||
xmlns:tal="http://xml.zope.org/namespaces/tal" | ||
xmlns:metal="http://xml.zope.org/namespaces/metal" | ||
xmlns:i18n="http://xml.zope.org/namespaces/i18n" | ||
metal:use-macro="context/main_template/macros/master" | ||
i18n:domain="imio.smartweb"> | ||
<body> | ||
<metal:main fill-slot="content-core"> | ||
<iframe plausible-embed | ||
src="" | ||
scrolling="no" | ||
frameborder="0" | ||
loading="lazy" | ||
id="plausible" | ||
style="width: 1px; min-width: 100%; height: 1600px;" | ||
tal:condition="view/is_plausible_set" | ||
tal:attributes="src view/get_iframe_src"> | ||
</iframe> | ||
<script async | ||
src="" | ||
tal:condition="view/is_plausible_set" | ||
tal:attributes="src view/get_embedhostjs_src"> | ||
</script> | ||
<h2 tal:condition="not:view/is_plausible_set" i18n:domain="imio.smartweb" i18n:translate=""> | ||
Plausible analytics is not set | ||
</h2> | ||
</metal:main> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from plone import api | ||
from Products.Five.browser import BrowserView | ||
import os | ||
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile | ||
from imio.smartweb.core.browser.utils import get_plausible_vars | ||
|
||
|
||
class PlausibleView(BrowserView): | ||
@property | ||
def is_plausible_set(self): | ||
if not get_plausible_vars(self): | ||
return False | ||
else: | ||
return True | ||
|
||
@property | ||
def get_embedhostjs_src(self): | ||
vars = get_plausible_vars(self) | ||
return f"https://{vars['plausible_url']}/js/embed.host.js" | ||
|
||
@property | ||
def get_iframe_src(self): | ||
vars = get_plausible_vars(self) | ||
return f"https://{vars['plausible_url']}/share/{vars['plausible_site']}?auth={vars['plausible_token']}&embed=true&theme=light&background=transparent" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from plone import api | ||
from imio.smartweb.core.testing import IMIO_SMARTWEB_CORE_INTEGRATION_TESTING | ||
from imio.smartweb.core.testing import ImioSmartwebTestCase | ||
from imio.smartweb.core.browser.dashboards.plausible import PlausibleView | ||
from unittest import mock | ||
from zope.component import queryMultiAdapter | ||
|
||
import os | ||
|
||
|
||
class Testplausible(ImioSmartwebTestCase): | ||
layer = IMIO_SMARTWEB_CORE_INTEGRATION_TESTING | ||
|
||
def setUp(self): | ||
"""Custom shared utility setup for tests""" | ||
self.request = self.layer["request"] | ||
self.portal = self.layer["portal"] | ||
|
||
def set_registry_records(self): | ||
api.portal.set_registry_record("smartweb.plausible_site", "site-registry.be") | ||
api.portal.set_registry_record("smartweb.plausible_token", "token-registry") | ||
api.portal.set_registry_record("smartweb.plausible_url", "url-registry.be") | ||
|
||
@mock.patch.dict( | ||
os.environ, | ||
{ | ||
"SMARTWEB_PLAUSIBLE_SITE": "", | ||
"SMARTWEB_PLAUSIBLE_TOKEN": "", | ||
"SMARTWEB_PLAUSIBLE_URL": "", | ||
}, | ||
) | ||
def test_noenv(self): | ||
view = PlausibleView(self.portal, self.request) | ||
self.assertFalse(view.is_plausible_set) | ||
self.set_registry_records() | ||
self.assertTrue(view.is_plausible_set) | ||
self.assertEqual( | ||
view.get_iframe_src, | ||
"https://url-registry.be/share/site-registry.be?auth=token-registry&embed=true&theme=light&background=transparent", | ||
) | ||
self.assertEqual( | ||
view.get_embedhostjs_src, | ||
"https://url-registry.be/js/embed.host.js", | ||
) | ||
|
||
@mock.patch.dict( | ||
os.environ, | ||
{ | ||
"SMARTWEB_PLAUSIBLE_SITE": "site-varenv.be", | ||
"SMARTWEB_PLAUSIBLE_TOKEN": "token-varenv", | ||
"SMARTWEB_PLAUSIBLE_URL": "url-varenv.be", | ||
}, | ||
) | ||
def test_env(self): | ||
view = PlausibleView(self.portal, self.request) | ||
self.assertTrue(view.is_plausible_set) | ||
self.assertEqual( | ||
view.get_iframe_src, | ||
"https://url-varenv.be/share/site-varenv.be?auth=token-varenv&embed=true&theme=light&background=transparent", | ||
) | ||
self.assertEqual( | ||
view.get_embedhostjs_src, | ||
"https://url-varenv.be/js/embed.host.js", | ||
) | ||
self.set_registry_records() | ||
self.assertEqual( | ||
view.get_iframe_src, | ||
"https://url-varenv.be/share/site-varenv.be?auth=token-varenv&embed=true&theme=light&background=transparent", | ||
) | ||
self.assertEqual( | ||
view.get_embedhostjs_src, | ||
"https://url-varenv.be/js/embed.host.js", | ||
) | ||
|
||
def test_plausible_view(self): | ||
view = queryMultiAdapter((self.portal, self.request), name="stats") | ||
self.assertNotIn("iframe", view()) | ||
self.assertIn("Plausible analytics is not set", view()) | ||
self.set_registry_records() | ||
self.assertIn("iframe", view()) | ||
self.assertNotIn("Plausible analytics is not set", view()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/imio/smartweb/core/upgrades/profiles/1037_to_1038/registry/plausible.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0"?> | ||
<registry | ||
xmlns:i18n="http://xml.zope.org/namespaces/i18n" | ||
i18n:domain="imio.smartweb"> | ||
|
||
<records interface="imio.smartweb.core.browser.controlpanel.ISmartwebControlPanel" | ||
prefix="smartweb" /> | ||
|
||
</registry> |