Commit 1736fab1 authored by Jean-Paul Smets's avatar Jean-Paul Smets

Improved template management support


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5230 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 39708140
...@@ -339,6 +339,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -339,6 +339,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
isDelivery = 0 # isDelivery = 0 #
isIndexable = 1 # If set to 0, reindexing will not happen (useful for optimization) isIndexable = 1 # If set to 0, reindexing will not happen (useful for optimization)
isPredicate = 0 # isPredicate = 0 #
isTemplate = 0 #
# Dynamic method acquisition system (code generation) # Dynamic method acquisition system (code generation)
aq_method_generated = {} aq_method_generated = {}
...@@ -2175,6 +2176,15 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -2175,6 +2176,15 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
return None return None
return None return None
security.declareProtected(Permissions.ModifyPortalContent,'assignRoleToSecurityGroup')
def assignRoleToSecurityGroup(self):
"""
Set or reset local roles assignments based on local roles
definition in portal type.
"""
self._getTypesTool()[self.getPortalType()].assignRoleToSecurityGroup(self)
# Template Management
security.declareProtected(Permissions.View, 'getDocumentTemplateList') security.declareProtected(Permissions.View, 'getDocumentTemplateList')
def getDocumentTemplateList(self) : def getDocumentTemplateList(self) :
""" """
...@@ -2183,13 +2193,35 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -2183,13 +2193,35 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
""" """
return [] return []
security.declareProtected(Permissions.ModifyPortalContent,'assignRoleToSecurityGroup') security.declareProtected(Permissions.ModifyPortalContent,'makeTemplate')
def assignRoleToSecurityGroup(self): def makeTemplate(self):
"""
Set or reset local roles assignments based on local roles
definition in portal type.
""" """
self._getTypesTool()[self.getPortalType()].assignRoleToSecurityGroup(self) Make document behave as a template.
A template is no longer indexable
TODO:
- stronger security model
- prevent from changing templates or invoking workflows
"""
parent = self.getParentValue()
if parent.getPortalType() != "Preference" and not parent.isTemplate:
raise ValueError, "Template documents can not be created outside Preferences"
# Make sure this object is not in the catalog
catalog = getToolByName(self, 'portal_catalog', None)
if catalog is not None:
catalog.unindexObject(self)
self.isIndexable = 0
self.isTemplate = 1
security.declareProtected(Permissions.ModifyPortalContent,'makeTemplateInstance')
def makeTemplateInstance(self):
"""
Make document behave as standard document (indexable)
"""
if self.getParentValue().getPortalType() == "Preference":
raise ValueError, "Template instances can not be created within Preferences"
if hasattr(aq_base(self), 'isIndexable'): delattr(self, 'isIndexable')
if hasattr(aq_base(self), 'isTemplate'): delattr(self, 'isTemplate')
InitializeClass(Base) InitializeClass(Base)
......
...@@ -205,7 +205,6 @@ class FolderMixIn(ExtensionClass.Base, CopyContainer): ...@@ -205,7 +205,6 @@ class FolderMixIn(ExtensionClass.Base, CopyContainer):
method = self.portal_catalog.countResults method = self.portal_catalog.countResults
return method(**kw2) return method(**kw2)
# Count objects in the folder # Count objects in the folder
security.declarePrivate('_count') security.declarePrivate('_count')
def _count(self, **kw): def _count(self, **kw):
...@@ -731,6 +730,7 @@ be a problem).""" ...@@ -731,6 +730,7 @@ be a problem)."""
security.declareProtected( Permissions.AccessContentsInformation, 'manage_copyObjects' ) # XXX Why this one doesn't work in CopySupport ? security.declareProtected( Permissions.AccessContentsInformation, 'manage_copyObjects' ) # XXX Why this one doesn't work in CopySupport ?
security.declareProtected( Permissions.AddPortalContent, 'manage_pasteObjects' ) # XXX Why this one doesn't work in CopySupport ? security.declareProtected( Permissions.AddPortalContent, 'manage_pasteObjects' ) # XXX Why this one doesn't work in CopySupport ?
# Template Management
security.declareProtected(Permissions.View, 'getDocumentTemplateList') security.declareProtected(Permissions.View, 'getDocumentTemplateList')
def getDocumentTemplateList(self) : def getDocumentTemplateList(self) :
""" """
...@@ -739,5 +739,28 @@ be a problem).""" ...@@ -739,5 +739,28 @@ be a problem)."""
""" """
return self.getPortalObject().portal_preferences.getDocumentTemplateList(self) return self.getPortalObject().portal_preferences.getDocumentTemplateList(self)
security.declareProtected(Permissions.ModifyPortalContent,'makeTemplate')
def makeTemplate(self):
"""
Make document behave as a template.
A template is no longer indexable
TODO:
- prevent from changing templates or invoking workflows
"""
Base.makeTemplate(self)
for o in self.objectValues():
if hasattr(aq_base(o), 'makeTemplate'): o.makeTemplate()
security.declareProtected(Permissions.ModifyPortalContent,'makeTemplateInstance')
def makeTemplateInstance(self):
"""
Make document behave as standard document (indexable)
"""
Base.makeTemplateInstance(self)
for o in self.objectValues():
if hasattr(aq_base(o), 'makeTemplateInstance'): o.makeTemplateInstance()
# Overwrite Zope setTitle() # Overwrite Zope setTitle()
Folder.setTitle = Base.setTitle Folder.setTitle = Base.setTitle
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment