Updated content's is_visible/is_published tests
authorThierry Florac <tflorac@ulthar.net>
Sun, 26 Nov 2017 10:17:30 +0100
changeset 47 31cbce6cb864
parent 46 1250be42cfbf
child 48 caa4dfcc51ee
Updated content's is_visible/is_published tests
src/pyams_workflow/content.py
--- a/src/pyams_workflow/content.py	Fri Oct 13 10:02:40 2017 +0200
+++ b/src/pyams_workflow/content.py	Sun Nov 26 10:17:30 2017 +0100
@@ -18,6 +18,7 @@
 
 # import interfaces
 from pyams_security.interfaces import ISecurityManager
+from pyams_utils.interfaces import VIEW_PERMISSION
 from pyams_workflow.interfaces import IWorkflowManagedContent, IWorkflowPublicationInfo, IWorkflow, IWorkflowVersions, \
     IWorkflowPublicationSupport, IObjectClonedEvent, IWorkflowState, VersionError, VERSION_DISPLAY, \
     DISPLAY_FIRST_VERSION, DISPLAY_CURRENT_VERSION
@@ -28,7 +29,7 @@
 from persistent import Persistent
 from pyams_utils.adapter import adapter_config
 from pyams_utils.date import format_datetime, format_date, SH_DATE_FORMAT
-from pyams_utils.registry import get_utility, query_utility
+from pyams_utils.registry import get_utility
 from pyams_utils.request import check_request
 from pyams_utils.timezone import gmtime, tztime, GMT
 from pyams_utils.traversing import get_parent
@@ -160,11 +161,11 @@
             return False
         # associated workflow?
         workflow = IWorkflow(self.__parent__, None)
-        if (workflow is None) or not workflow.published_states:
+        if (workflow is not None) and not workflow.published_states:
             return False
         # check content versions
-        versions = IWorkflowVersions(self.__parent__)
-        if not (versions or versions.get_versions(workflow.published_states)):
+        versions = IWorkflowVersions(self.__parent__, None)
+        if (versions is not None) and not versions.get_versions(workflow.published_states):
             return False
         now = tztime(datetime.utcnow())
         return (self.publication_effective_date is not None) and \
@@ -174,15 +175,19 @@
 
     def is_visible(self, request=None):
         # associated workflow?
-        content = IWorkflowManagedContent(self.__parent__)
-        wf_name = content.workflow_name
-        if not wf_name:
-            return True
-        # check workflow?
-        if content.view_permission:
-            if request is None:
-                request = check_request()
-            if not request.has_permission(content.view_permission, context=self.__parent__):
+        content = IWorkflowManagedContent(self.__parent__, None)
+        if content is not None:
+            wf_name = content.workflow_name
+            if not wf_name:
+                return True
+            # check workflow?
+            if content.view_permission:
+                if request is None:
+                    request = check_request()
+                if not request.has_permission(content.view_permission, context=self.__parent__):
+                    return False
+        else:
+            if not request.has_permission(VIEW_PERMISSION, context=self.__parent__):
                 return False
         return self.is_published()