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 ):
isDelivery = 0 #
isIndexable = 1 # If set to 0, reindexing will not happen (useful for optimization)
isPredicate = 0 #
isTemplate = 0 #
# Dynamic method acquisition system (code generation)
aq_method_generated = {}
......@@ -2175,6 +2176,15 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
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')
def getDocumentTemplateList(self) :
"""
......@@ -2183,13 +2193,35 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
"""
return []
security.declareProtected(Permissions.ModifyPortalContent,'assignRoleToSecurityGroup')
def assignRoleToSecurityGroup(self):
security.declareProtected(Permissions.ModifyPortalContent,'makeTemplate')
def makeTemplate(self):
"""
Set or reset local roles assignments based on local roles
definition in portal type.
Make document behave as a template.
A template is no longer indexable
TODO:
- stronger security model
- prevent from changing templates or invoking workflows
"""
self._getTypesTool()[self.getPortalType()].assignRoleToSecurityGroup(self)
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)
......
......@@ -205,7 +205,6 @@ class FolderMixIn(ExtensionClass.Base, CopyContainer):
method = self.portal_catalog.countResults
return method(**kw2)
# Count objects in the folder
security.declarePrivate('_count')
def _count(self, **kw):
......@@ -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.AddPortalContent, 'manage_pasteObjects' ) # XXX Why this one doesn't work in CopySupport ?
# Template Management
security.declareProtected(Permissions.View, 'getDocumentTemplateList')
def getDocumentTemplateList(self) :
"""
......@@ -738,6 +738,29 @@ be a problem)."""
by calling the preference tool
"""
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()
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