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 3ee5f27
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
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
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 3ee5f27

Please sign in to comment.