--- a/src/pyams_content/shared/site/__init__.py Mon Oct 15 17:22:15 2018 +0200
+++ b/src/pyams_content/shared/site/__init__.py Tue Oct 16 11:18:52 2018 +0200
@@ -20,10 +20,11 @@
from pyams_content.features.preview.interfaces import IPreviewTarget
from pyams_content.features.review.interfaces import IReviewTarget
from pyams_content.shared.common import IWfSharedContentFactory, SharedContent, WfSharedContent, register_content_type
-from pyams_content.shared.site.interfaces import ISiteTopic, IWfSiteTopic, IWfSiteTopicFactory, SITE_TOPIC_CONTENT_NAME, \
- SITE_TOPIC_CONTENT_TYPE
-from pyams_utils.adapter import adapter_config
-from pyams_workflow.interfaces import IWorkflow, IWorkflowState, IWorkflowVersions
+from pyams_content.shared.site.interfaces import ISiteElementNavigation, ISiteTopic, IWfSiteTopic, IWfSiteTopicFactory, \
+ SITE_TOPIC_CONTENT_NAME, SITE_TOPIC_CONTENT_TYPE
+from pyams_skin.layer import IPyAMSLayer
+from pyams_utils.adapter import ContextRequestAdapter, adapter_config
+from pyams_workflow.interfaces import IWorkflow, IWorkflowState, IWorkflowVersions, IWorkflowPublicationInfo
@implementer(IWfSiteTopic, IIllustrationTarget, ILinkIllustrationTarget, IParagraphContainerTarget,
@@ -56,3 +57,16 @@
@adapter_config(context=IWfSiteTopicFactory, provides=IWfSharedContentFactory)
def site_topic_content_factory(context):
return WfSiteTopic
+
+
+@adapter_config(context=(ISiteTopic, IPyAMSLayer), provides=ISiteElementNavigation)
+class SiteTopicNavigationAdapter(ContextRequestAdapter):
+ """Site topic navigation adapter"""
+
+ @property
+ def visible(self):
+ workflow = IWorkflow(self.context)
+ versions = IWorkflowVersions(self.context).get_versions(workflow.published_states, sort=True)
+ if versions:
+ content = versions[-1]
+ return IWorkflowPublicationInfo(content).is_visible(self.request)
--- a/src/pyams_content/shared/site/container.py Mon Oct 15 17:22:15 2018 +0200
+++ b/src/pyams_content/shared/site/container.py Tue Oct 16 11:18:52 2018 +0200
@@ -12,29 +12,36 @@
__docformat__ = 'restructuredtext'
-
-# import standard library
import json
from pyramid.location import lineage
from zope.interface import implementer
from zope.intid.interfaces import IIntIds
-# import interfaces
from pyams_content.shared.common.interfaces import ISharedContentFactory
-# import packages
from pyams_content.shared.site import SiteTopic
-from pyams_content.shared.site.interfaces import ISiteContainer, ISiteFolder
+from pyams_content.shared.site.interfaces import ISiteContainer, ISiteElementNavigation, ISiteFolder
from pyams_i18n.interfaces import II18n
from pyams_utils.adapter import adapter_config
-from pyams_utils.registry import get_utility
-from pyams_utils.request import query_request
+from pyams_utils.registry import get_global_registry, get_utility
+from pyams_utils.request import check_request, query_request
@implementer(ISiteContainer)
class SiteContainerMixin(object):
"""Site container mixin class"""
+ def get_visible_items(self, request=None):
+
+ def check_item(item):
+ navigation = registry.queryMultiAdapter((item, request), ISiteElementNavigation)
+ return (navigation is not None) and navigation.visible
+
+ if request is None:
+ request = check_request()
+ registry = get_global_registry()
+ yield from filter(check_item, self.values())
+
def get_folders_tree(self, selected=None, permission=None):
request = query_request()
--- a/src/pyams_content/shared/site/folder.py Mon Oct 15 17:22:15 2018 +0200
+++ b/src/pyams_content/shared/site/folder.py Tue Oct 16 11:18:52 2018 +0200
@@ -16,24 +16,26 @@
from zope.interface import implementer
from zope.intid.interfaces import IIntIds
from zope.schema.fieldproperty import FieldProperty
-from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
+from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
from pyams_content.component.illustration import IIllustrationTarget, ILinkIllustrationTarget
from pyams_content.features.preview.interfaces import IPreviewTarget
from pyams_content.interfaces import MANAGE_SITE_PERMISSION
from pyams_content.shared.common.manager import BaseSharedTool
from pyams_content.shared.site.container import SiteContainerMixin
-from pyams_content.shared.site.interfaces import ISiteFolder, ISiteManager, ISiteFolderRoles
+from pyams_content.shared.site.interfaces import ISiteElementNavigation, ISiteFolder, ISiteFolderRoles, ISiteManager
from pyams_form.interfaces.form import IFormContextPermissionChecker
from pyams_i18n.interfaces import II18n
from pyams_portal.interfaces import IPortalContext
from pyams_security.interfaces import IDefaultProtectionPolicy
-from pyams_utils.adapter import adapter_config, ContextAdapter
+from pyams_skin.layer import IPyAMSLayer
+from pyams_utils.adapter import ContextAdapter, ContextRequestAdapter, adapter_config
from pyams_utils.container import find_objects_providing
from pyams_utils.registry import get_local_registry
from pyams_utils.request import query_request
from pyams_utils.traversing import get_parent
from pyams_utils.vocabulary import vocabulary_config
+from pyams_workflow.interfaces import IWorkflowPublicationInfo
from pyams_content import _
@@ -65,6 +67,17 @@
return True
+@adapter_config(context=(ISiteFolder, IPyAMSLayer), provides=ISiteElementNavigation)
+class SiteFolderNavigationAdapter(ContextRequestAdapter):
+ """Site folder navigation adapter"""
+
+ @property
+ def visible(self):
+ if not self.context.visible_in_list:
+ return False
+ return IWorkflowPublicationInfo(self.context).is_visible(self.request)
+
+
@adapter_config(context=ISiteFolder, provides=IFormContextPermissionChecker)
class SiteFolderPermissionChecker(ContextAdapter):
"""Site folder edit permission checker"""
--- a/src/pyams_content/shared/site/interfaces/__init__.py Mon Oct 15 17:22:15 2018 +0200
+++ b/src/pyams_content/shared/site/interfaces/__init__.py Tue Oct 16 11:18:52 2018 +0200
@@ -50,11 +50,20 @@
content_name = Attribute("Content name")
+class ISiteElementNavigation(Interface):
+ """Site element navigation interface"""
+
+ visible = Attribute("Visible element?")
+
+
class ISiteContainer(IContainer, IContained, IWorkflowPublicationSupport):
"""Base site container interface"""
contains(ISiteElement)
+ def get_visible_items(self, request=None):
+ """Iterator over container visible items"""
+
def get_folders_tree(self, selected=None):
"""Get site tree in JSON format"""
--- a/src/pyams_content/shared/site/link.py Mon Oct 15 17:22:15 2018 +0200
+++ b/src/pyams_content/shared/site/link.py Tue Oct 16 11:18:52 2018 +0200
@@ -17,15 +17,16 @@
from zope.interface import implementer
from zope.schema.fieldproperty import FieldProperty
-from pyams_content import _
-from pyams_content.shared.site.interfaces import IContentLink
+from pyams_content.shared.site.interfaces import IContentLink, ISiteElementNavigation
from pyams_sequence.reference import get_reference_target
-from pyams_skin.layer import IPyAMSUserLayer
-from pyams_utils.adapter import adapter_config
+from pyams_skin.layer import IPyAMSLayer, IPyAMSUserLayer
+from pyams_utils.adapter import ContextRequestAdapter, adapter_config
from pyams_utils.interfaces.url import IRelativeURL
from pyams_utils.zodb import volatile_property
-from pyams_workflow.interfaces import IWorkflow, IWorkflowVersion, IWorkflowVersions, IWorkflowPublicationInfo, \
- IWorkflowState
+from pyams_workflow.interfaces import IWorkflow, IWorkflowPublicationInfo, IWorkflowState, IWorkflowVersion, \
+ IWorkflowVersions
+
+from pyams_content import _
@implementer(IContentLink)
@@ -63,6 +64,16 @@
return self.target
+@adapter_config(context=(IContentLink, IPyAMSLayer), provides=ISiteElementNavigation)
+class ContentLinkNavigationAdapter(ContextRequestAdapter):
+ """Content link navigation adapter"""
+
+ @property
+ def visible(self):
+ target = self.context.target
+ return (target is not None) and IWorkflowPublicationInfo(target).is_visible(self.request)
+
+
@adapter_config(context=IContentLink, provides=IWorkflow)
def content_link_workflow_info(context):
"""Content link workflow info"""