Skip to content

Commit

Permalink
WEB-4132 : In anonymous mode, use remoteUrl instead of internal link …
Browse files Browse the repository at this point in the history
…url in links sections
  • Loading branch information
boulch committed Aug 5, 2024
1 parent ab58116 commit 21848ee
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Changelog
1.2.65 (unreleased)
-------------------

- Nothing changed yet.
- WEB-4132 : In anonymous mode, use remoteUrl instead of internal link url in links sections
[boulch]


1.2.64 (2024-08-05)
Expand Down
5 changes: 5 additions & 0 deletions src/imio/smartweb/core/contents/sections/links/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from imio.smartweb.core.contents.sections.views import CarouselOrTableSectionView
from imio.smartweb.core.utils import batch_results
from imio.smartweb.core.utils import get_scale_url
from plone import api


class LinksView(CarouselOrTableSectionView):
Expand All @@ -15,6 +16,10 @@ def items(self):
results = []
for item in items:
url = item.absolute_url()
is_anon = api.user.is_anonymous()
if hasattr(item, "remoteUrl") and item.remoteUrl is not None and is_anon:
portal_url = api.portal.get().absolute_url()
url = item.remoteUrl.replace("${portal_url}", portal_url)
has_icon = has_image = False
if getattr(item.aq_base, "svg_icon", None):
has_icon = True
Expand Down
5 changes: 3 additions & 2 deletions src/imio/smartweb/core/tests/test_section_external_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ def test_elloha_plugin(self):
"ConstellationWidgetContainer" : "11111111-1111-1111-1111-111111111111",
"Idoi" : "22222222-2222-2222-2222-222222222222"
}"""
self.maxDiff = None
section_view = queryMultiAdapter((sec, self.request), name="view")
result = '<div class="elloha"><div id="ConstellationWidgetContainer11111111-1111-1111-1111-111111111111" style="width:100%" data-id-projet="11111111111111111111111111111111">...</div></div><script type="text/javascript" src="https://reservation.elloha.com/Scripts/widget-loader.min.js?v=42"></script><script type="text/javascript">var constellationWidgetUrl11111111111111111111111111111111, constellationTypeModule11111111111111111111111111111111;constellationWidgetUrl11111111111111111111111111111111 = "https://reservation.elloha.com/Widget/BookingEngine/11111111-1111-1111-1111-111111111111?idoi=22222222-2222-2222-2222-222222222222&culture=fr-FR";constellationTypeModule11111111111111111111111111111111=1; constellationWidgetLoad("ConstellationWidgetContainer11111111-1111-1111-1111-111111111111");constellationWidgetAddEvent(window, "resize", function () {constellationWidgetSetAppearance("ConstellationWidgetContainer11111111-1111-1111-1111-111111111111");});</script>'
result = '<div class="elloha" style="position:relative;"><div id="ConstellationWidgetContainer11111111-1111-1111-1111-111111111111" style="width:100%" data-id-projet="11111111111111111111111111111111">...</div></div><script type="text/javascript" src="https://reservation.elloha.com/Scripts/widget-loader.min.js?v=42"></script><script type="text/javascript">var constellationWidgetUrl11111111111111111111111111111111, constellationTypeModule11111111111111111111111111111111;constellationWidgetUrl11111111111111111111111111111111 = "https://reservation.elloha.com/Widget/BookingEngine/11111111-1111-1111-1111-111111111111?idoi=22222222-2222-2222-2222-222222222222&culture=fr-FR";constellationTypeModule11111111111111111111111111111111=1; constellationWidgetLoad("ConstellationWidgetContainer11111111-1111-1111-1111-111111111111");constellationWidgetAddEvent(window, "resize", function () {constellationWidgetSetAppearance("ConstellationWidgetContainer11111111-1111-1111-1111-111111111111");});</script>'
self.assertEqual(section_view.contents, result)

# good extra params / dict keys are case insensitive
Expand All @@ -81,7 +82,7 @@ def test_elloha_plugin(self):
"IDOI" : "22222222-2222-2222-2222-222222222222"
}"""
section_view = queryMultiAdapter((sec, self.request), name="view")
result = '<div class="elloha"><div id="ConstellationWidgetContainer11111111-1111-1111-1111-111111111111" style="width:100%" data-id-projet="11111111111111111111111111111111">...</div></div><script type="text/javascript" src="https://reservation.elloha.com/Scripts/widget-loader.min.js?v=42"></script><script type="text/javascript">var constellationWidgetUrl11111111111111111111111111111111, constellationTypeModule11111111111111111111111111111111;constellationWidgetUrl11111111111111111111111111111111 = "https://reservation.elloha.com/Widget/BookingEngine/11111111-1111-1111-1111-111111111111?idoi=22222222-2222-2222-2222-222222222222&culture=fr-FR";constellationTypeModule11111111111111111111111111111111=1; constellationWidgetLoad("ConstellationWidgetContainer11111111-1111-1111-1111-111111111111");constellationWidgetAddEvent(window, "resize", function () {constellationWidgetSetAppearance("ConstellationWidgetContainer11111111-1111-1111-1111-111111111111");});</script>'
result = '<div class="elloha" style="position:relative;"><div id="ConstellationWidgetContainer11111111-1111-1111-1111-111111111111" style="width:100%" data-id-projet="11111111111111111111111111111111">...</div></div><script type="text/javascript" src="https://reservation.elloha.com/Scripts/widget-loader.min.js?v=42"></script><script type="text/javascript">var constellationWidgetUrl11111111111111111111111111111111, constellationTypeModule11111111111111111111111111111111;constellationWidgetUrl11111111111111111111111111111111 = "https://reservation.elloha.com/Widget/BookingEngine/11111111-1111-1111-1111-111111111111?idoi=22222222-2222-2222-2222-222222222222&culture=fr-FR";constellationTypeModule11111111111111111111111111111111=1; constellationWidgetLoad("ConstellationWidgetContainer11111111-1111-1111-1111-111111111111");constellationWidgetAddEvent(window, "resize", function () {constellationWidgetSetAppearance("ConstellationWidgetContainer11111111-1111-1111-1111-111111111111");});</script>'
self.assertEqual(section_view.contents, result)

# with bad params
Expand Down
17 changes: 17 additions & 0 deletions src/imio/smartweb/core/tests/test_sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
class TestSections(ImioSmartwebTestCase):
layer = IMIO_SMARTWEB_CORE_INTEGRATION_TESTING

def _changeUser(self, loginName):
logout()
login(self.portal, loginName)
self.member = api.user.get_current()
self.request["AUTHENTICATED_USER"] = self.member

def setUp(self):
# Number of sections where there is a title if section is empty.
# sectionHTML,...
Expand Down Expand Up @@ -545,6 +551,17 @@ def test_link_section(self):
'<a class="table_image" href="http://nohost/plone/page/section-links/my-link" target="_blank">',
view(),
)
link.remoteUrl = "http://www.perdu.com"
view = getMultiAdapter((self.page, self.request), name="full_view")
self.assertIn("www.perdu.com", view())
self.assertNotIn(
'href="http://nohost/plone/page/section-links/my-link"', view()
)
clear_cache(self.request)
self._changeUser("test")
view = getMultiAdapter((self.page, self.request), name="full_view")
self.assertNotIn("www.perdu.com", view())
self.assertIn('href="http://nohost/plone/page/section-links/my-link"', view())

def test_background_style(self):
section = api.content.create(
Expand Down

0 comments on commit 21848ee

Please sign in to comment.