Skip to content

Commit

Permalink
Merge 585dbe0 into 598ca6f
Browse files Browse the repository at this point in the history
  • Loading branch information
boulch committed Jun 16, 2023
2 parents 598ca6f + 585dbe0 commit 6f0c37d
Show file tree
Hide file tree
Showing 26 changed files with 315 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ Changelog
[thomlamb]

- Fixed faceted map
- Change some icons : SectionHTML and SectionExternalContent
[boulch]

- MWEBTUBA : Add new section : imio.smartweb.SectionExternalContent (Manage embeded contents)
[boulch]

- WEB-3837 : Can define specific news to get (instead of all news from news folders)
Expand Down
4 changes: 4 additions & 0 deletions src/imio/smartweb/core/contents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
from .sections.collection.content import ISectionCollection, SectionCollection # NOQA
from .sections.contact.content import ISectionContact, SectionContact # NOQA
from .sections.events.content import ISectionEvents, SectionEvents # NOQA
from .sections.external_content.content import (
ISectionExternalContent,
SectionExternalContent,
) # NOQA
from .sections.files.content import ISectionFiles, SectionFiles # NOQA
from .sections.gallery.content import ISectionGallery, SectionGallery # NOQA
from .sections.html.content import ISectionHTML, SectionHTML # NOQA
Expand Down
1 change: 1 addition & 0 deletions src/imio/smartweb/core/contents/sections/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<include package=".collection" />
<include package=".contact" />
<include package=".events" />
<include package=".external_content" />
<include package=".files" />
<include package=".gallery" />
<include package=".html" />
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser">

<browser:page
name="view"
for="imio.smartweb.core.contents.ISectionExternalContent"
class="imio.smartweb.core.contents.sections.external_content.views.ExternalContentView"
template="view.pt"
permission="zope2.View"
layer="imio.smartweb.core.interfaces.IImioSmartwebCoreLayer"
/>

</configure>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-

from imio.smartweb.common.config import DESCRIPTION_MAX_LENGTH
from imio.smartweb.core.contents.sections.base import ISection
from imio.smartweb.core.contents.sections.base import Section
from imio.smartweb.locales import SmartwebMessageFactory as _
from zope.interface import implementer
from zope import schema


class ISectionExternalContent(ISection):
"""Marker interface and Dexterity Python Schema for SectionVideo"""

description = schema.Text(
title=_("Description"),
description=_(
"Use **text** to set text in bold. Limited to ${max} characters.",
mapping={"max": DESCRIPTION_MAX_LENGTH},
),
max_length=DESCRIPTION_MAX_LENGTH,
required=False,
)

external_content_url = schema.URI(
title=_("External content url"),
required=True,
)


@implementer(ISectionExternalContent)
class SectionExternalContent(Section):
"""SectionVideo class"""
31 changes: 31 additions & 0 deletions src/imio/smartweb/core/contents/sections/external_content/view.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<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"
lang="en"
metal:use-macro="context/@@main_template/macros/master"
i18n:domain="plone">
<body>

<metal:main fill-slot="content-core">
<metal:content-core define-macro="content-core">
<metal:macro use-macro="context/@@sections_macros/section_edition" />
<div class="container section-container section-video"
id=""
tal:attributes="id string:container-section-${context/id}">

<metal:macro use-macro="context/@@sections_macros/section_title" />

<p tal:replace="structure context/@@description" />

<div tal:define="collapse_klass python: 'collapse' if context.collapsible_section else ''"
tal:attributes="class string:body-section ratio ratio-16x9 ${collapse_klass};
id string:body-section-${context/id}"
tal:content="structure view/get_embed_external_content" />

</div>
</metal:content-core>
</metal:main>

</body>
</html>
31 changes: 31 additions & 0 deletions src/imio/smartweb/core/contents/sections/external_content/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-

from embeddify import Embedder
from embeddify import Plugin
from imio.smartweb.core.contents.sections.views import SectionView
from imio.smartweb.locales import SmartwebMessageFactory as _


class ExternalContentView(SectionView):
def get_embed_external_content(self, width="100%", height=600):
plugins = [EaglebePlugin(), UnknowServicePlugin()]
plugin_config = {
"eaglebeplugin": {"width": width},
"unknowserviceplugin": {"width": width},
}
embedder = Embedder(plugins=plugins, plugin_config=plugin_config)
url = self.context.external_content_url
return embedder(url, config={"width": width})


class EaglebePlugin(Plugin):
def __call__(self, parts, config={}):
if "app.eaglebe.com" in parts.netloc:
return f'<iframe class="eaglebe" src="{parts.geturl()}" scrolling="no" width="{config["width"]}">'
#
return None


class UnknowServicePlugin(Plugin):
def __call__(self, parts, config={}):
return _("<p class='unknow_service'>Unknow service</p>")
6 changes: 6 additions & 0 deletions src/imio/smartweb/core/permissions.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
description=""
/>

<permission
id="imio.smartweb.core.CanManageSectionExternalContent"
title="imio.smartweb.core: Can add section External Content"
description=""
/>

<permission
id="imio.smartweb.core.CanEditMinisiteLogo"
title="imio.smartweb.core: Edit Minisite Logo"
Expand Down
6 changes: 6 additions & 0 deletions src/imio/smartweb/core/profiles/default/rolemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@
<role name="Local Manager" />
</permission>

<permission name="imio.smartweb.core: Can add section External Content" acquire="True">
<role name="Manager"/>
<role name="Site Administrator"/>
<role name="Local Manager" />
</permission>

<permission name="imio.smartweb.core: Manage taxonomies on this content" acquire="True">
<role name="Manager"/>
<role name="Site Administrator"/>
Expand Down
1 change: 1 addition & 0 deletions src/imio/smartweb/core/profiles/default/types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<object meta_type="Dexterity FTI" name="imio.smartweb.SectionCollection"/>
<object meta_type="Dexterity FTI" name="imio.smartweb.SectionContact"/>
<object meta_type="Dexterity FTI" name="imio.smartweb.SectionEvents"/>
<object meta_type="Dexterity FTI" name="imio.smartweb.SectionExternalContent"/>
<object meta_type="Dexterity FTI" name="imio.smartweb.SectionFiles"/>
<object meta_type="Dexterity FTI" name="imio.smartweb.SectionGallery"/>
<object meta_type="Dexterity FTI" name="imio.smartweb.SectionHTML"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<property name="filter_content_types">True</property>
<property name="allowed_content_types">
<element value="imio.smartweb.SectionContact" />
<element value="imio.smartweb.SectionExternalContent" />
<element value="imio.smartweb.SectionFiles" />
<element value="imio.smartweb.SectionGallery" />
<element value="imio.smartweb.SectionHTML" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<property name="allowed_content_types">
<element value="imio.smartweb.SectionCollection" />
<element value="imio.smartweb.SectionContact" />
<element value="imio.smartweb.SectionExternalContent" />
<element value="imio.smartweb.SectionGallery" />
<element value="imio.smartweb.SectionHTML" />
<element value="imio.smartweb.SectionEvents" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<property name="filter_content_types">True</property>
<property name="allowed_content_types">
<element value="imio.smartweb.SectionContact" />
<element value="imio.smartweb.SectionExternalContent" />
<element value="imio.smartweb.SectionFiles" />
<element value="imio.smartweb.SectionGallery" />
<element value="imio.smartweb.SectionHTML" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0"?>
<object xmlns:i18n="http://xml.zope.org/namespaces/i18n"
name="imio.smartweb.SectionExternalContent"
meta_type="Dexterity FTI"
i18n:domain="imio.smartweb">

<!-- Basic properties -->
<property
i18n:translate=""
name="title">External content section</property>
<property
i18n:translate=""
name="description">External content section for a page</property>

<property name="icon_expr">string:window-plus</property>

<!-- Hierarchy control -->
<property name="global_allow">False</property>
<property name="filter_content_types">True</property>

<!-- Schema, class and security -->
<!-- if we can add a page, we can add a page section -->
<property name="add_permission">imio.smartweb.core.CanManageSectionExternalContent</property>
<property name="klass">imio.smartweb.core.contents.SectionExternalContent</property>
<property name="schema">imio.smartweb.core.contents.ISectionExternalContent</property>

<!-- Enabled behaviors -->
<property name="behaviors" purge="false">
<element value="plone.namefromtitle"/>
<element value="plone.locking"/>
<element value="plone.shortname"/>
<element value="plone.imagecropping"/>
<element value="imio.smartweb.topics"/>
</property>

</object>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
i18n:translate=""
name="description">HTML section for a page</property>

<property name="icon_expr">string:code-slash</property>
<property name="icon_expr">string:filetype-html</property>

<!-- Hierarchy control -->
<property name="global_allow">False</property>
Expand Down
1 change: 1 addition & 0 deletions src/imio/smartweb/core/profiles/default/workflows.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<type type_id="imio.smartweb.SectionCollection"/>
<type type_id="imio.smartweb.SectionContact"/>
<type type_id="imio.smartweb.SectionEvents"/>
<type type_id="imio.smartweb.SectionExternalContent"/>
<type type_id="imio.smartweb.SectionFiles"/>
<type type_id="imio.smartweb.SectionGallery"/>
<type type_id="imio.smartweb.SectionHTML"/>
Expand Down
34 changes: 34 additions & 0 deletions src/imio/smartweb/core/tests/test_sections.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

from AccessControl.unauthorized import Unauthorized
from bs4 import BeautifulSoup
from collective.geolocationbehavior.geolocation import IGeolocatable
from functools import reduce
Expand Down Expand Up @@ -110,6 +111,39 @@ def test_video_section(self):
"https://www.youtube.com/embed/_dOAthafoGQ?feature=oembed", embedded_video
)

def test_external_content_section(self):
setRoles(self.portal, TEST_USER_ID, ["Contributor"])
with self.assertRaises(Unauthorized):
api.content.create(
container=self.page,
type="imio.smartweb.SectionExternalContent",
title="Section External Content",
)
setRoles(self.portal, TEST_USER_ID, ["Manager"])
section = api.content.create(
container=self.page,
type="imio.smartweb.SectionExternalContent",
title="Section External Content",
)
section.external_content_url = (
"https://app.eaglebe.com/fr-be/map/la%20louvi%C3%A8re"
)
view = queryMultiAdapter((section, self.request), name="view")
embedded_content = view.get_embed_external_content()
self.assertIn("iframe", embedded_content)
self.assertIn('class="eaglebe"', embedded_content)
self.assertIn('scrolling="no"', embedded_content)
self.assertIn(
"https://app.eaglebe.com/fr-be/map/la%20louvi%C3%A8re", embedded_content
)

section.external_content_url = "http://www.perdu.com"
view = queryMultiAdapter((section, self.request), name="view")
embedded_content = view.get_embed_external_content()
self.assertNotIn("iframe", embedded_content)
self.assertNotIn("class='eaglebe'", embedded_content)
self.assertIn("<p class='unknow_service'>Unknow service</p>", embedded_content)

def test_map_section(self):
section = api.content.create(
container=self.page,
Expand Down
21 changes: 19 additions & 2 deletions src/imio/smartweb/core/upgrades/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@
provides="Products.GenericSetup.interfaces.EXTENSION"
/>

<genericsetup:registerProfile
name="upgrade_1038_to_1039"
title="Upgrade core from 1038 to 1039"
directory="profiles/1038_to_1039"
description="Add new content type : imio.smartweb.SectionExternalContent"
provides="Products.GenericSetup.interfaces.EXTENSION"
/>

<genericsetup:upgradeStep
title="Configure first official release"
description="Run needed profiles steps and reindex catalog"
Expand Down Expand Up @@ -532,6 +540,15 @@
import_profile="imio.smartweb.core.upgrades:upgrade_1037_to_1038"
/>
</genericsetup:upgradeSteps>



<genericsetup:upgradeSteps
source="1038"
destination="1039"
profile="imio.smartweb.core:default">
<genericsetup:upgradeDepends
title="Add new content type : imio.smartweb.SectionExternalContent"
import_profile="imio.smartweb.core.upgrades:upgrade_1038_to_1039"
/>
</genericsetup:upgradeSteps>

</configure>
12 changes: 12 additions & 0 deletions src/imio/smartweb/core/upgrades/profiles/1037_to_1038/rolemap.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<rolemap>

<permissions>
<permission name="imio.smartweb.core: Can add section External Content" acquire="True">
<role name="Manager"/>
<role name="Site Administrator"/>
<role name="Local Manager" />
</permission>
</permissions>

</rolemap>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version='1.0' encoding='UTF-8'?>
<object name="portal_types" meta_type="Plone Types Tool">
<object meta_type="Dexterity FTI" name="imio.smartweb.SectionExternalContent"/>
</object>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<object xmlns:i18n="http://xml.zope.org/namespaces/i18n"
name="imio.smartweb.Page"
meta_type="Dexterity FTI"
i18n:domain="imio.smartweb">

<property name="allowed_content_types" purge="false">
<element value="imio.smartweb.SectionExternalContent" />
</property>

</object>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<object xmlns:i18n="http://xml.zope.org/namespaces/i18n"
name="imio.smartweb.PortalPage"
meta_type="Dexterity FTI"
i18n:domain="imio.smartweb">

<property name="allowed_content_types" purge="false">
<element value="imio.smartweb.SectionExternalContent" />
</property>

</object>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<object xmlns:i18n="http://xml.zope.org/namespaces/i18n"
name="imio.smartweb.Procedure"
meta_type="Dexterity FTI"
i18n:domain="imio.smartweb">

<property name="allowed_content_types" purge="false">
<element value="imio.smartweb.SectionExternalContent" />
</property>

</object>

0 comments on commit 6f0c37d

Please sign in to comment.