diff --git a/product/ERP5/Document/Document.py b/product/ERP5/Document/Document.py index a43b497c000a91ab0b0f24032cf8767dd030bc4e..ae57f8f8f868666e4ecd4b9d75a0e3353bf197de 100644 --- a/product/ERP5/Document/Document.py +++ b/product/ERP5/Document/Document.py @@ -103,6 +103,8 @@ class SnapshotMixin: class ConversionError(Exception):pass +class DocumentProxyError(Exception):pass + class NotConvertedError(Exception):pass class ConversionCacheMixin: @@ -397,7 +399,7 @@ class DocumentProxyMixin: """ proxied_document = self.getDocumentProxyValue() if proxied_document is None: - raise ValueError("Unable to find a proxied document") + raise DocumentProxyError("Unable to find a proxied document") return proxied_document class UpdateMixIn: diff --git a/product/ERP5/Document/EmailDocument.py b/product/ERP5/Document/EmailDocument.py index 14fbde81495df0fd3a6672bea1532b4c13ef6523..21ce2a9ab26784280e5ef7b3fa31fe69fd7deb94 100644 --- a/product/ERP5/Document/EmailDocument.py +++ b/product/ERP5/Document/EmailDocument.py @@ -38,7 +38,8 @@ from Products.CMFDefault.utils import isHTMLSafe from Products.ERP5Type import Permissions, PropertySheet, Constraint, interfaces from Products.ERP5.Document.TextDocument import TextDocument from Products.ERP5.Document.File import File -from Products.ERP5.Document.Document import ConversionError, DocumentProxyMixin +from Products.ERP5.Document.Document import ConversionError, \ + DocumentProxyMixin, DocumentProxyError from Products.ERP5.Tool.NotificationTool import buildEmailMessage from MethodObject import Method @@ -72,6 +73,33 @@ class EmailDocumentProxyMixin(DocumentProxyMixin): security = ClassSecurityInfo() security.declareObjectProtected(Permissions.AccessContentsInformation) + security.declareProtected(Permissions.AccessContentsInformation, 'hasFile') + def hasFile(self): + """ + hasFile is used in many parts of EmailDocument in order to know + if there is some document content to manage. We define it here + in order to say that there is no document if we are not able to + get the proxy + """ + has_file = False + try: + proxied_document = self.getProxiedDocument() + has_file = proxied_document.hasFile() + except DocumentProxyError: + pass + return has_file + + security.declareProtected(Permissions.AccessContentsInformation, 'getTextContent') + def getTextContent(self, default=_MARKER): + result = None + try: + proxied_document = self.getProxiedDocument() + result = proxied_document.getTextContent(default=default) + except DocumentProxyError: + pass + if default is _MARKER: + return result + return result or default class ProxiedMethod(Method): """ @@ -87,7 +115,7 @@ class ProxiedMethod(Method): return method(*args, **kw) # generate all proxy method on EmailDocumentProxyMixin -for method_id in ('getTextContent', 'getTextFormat', 'hasFile', +for method_id in ('getTextFormat', 'getContentInformation', 'getAttachmentData', 'getAttachmentInformationList'): EmailDocumentProxyMixin.security.declareProtected(