Commit e58bf7a3 authored by Jérome Perrin's avatar Jérome Perrin

refactor the bypass_init_script argument, rather propagate arguments

from OrderBuilder to init script and let init script handle it.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5775 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 766e2473
......@@ -333,7 +333,7 @@ class OrderBuilder(XMLObject, Amount, Predicate):
delivery = delivery_module.newContent(
portal_type=self.getDeliveryPortalType(),
id=new_delivery_id,
bypass_init_script=1,
created_by_builder=1,
activate_kw=activate_kw,**kw)
# Put properties on delivery
delivery.edit(**property_dict)
......
......@@ -291,7 +291,7 @@ class TestAccounting(ERP5TypeTestCase):
portal_type = self.accounting_transaction_portal_type,
source_section_value = sequence.get('client'),
resource_value = sequence.get('EUR'),
bypass_init_script = 1,
created_by_builder = 1,
)
# setting both source and destination shouldn't use mirror accounts
......@@ -399,7 +399,7 @@ class TestAccounting(ERP5TypeTestCase):
destination_value = sequence.get('client'),
resource = invoice_prop['currency'],
start_date = date, stop_date = date,
bypass_init_script = 0,
created_by_builder = 0,
)
for line_type in ['income', 'receivable', 'collected_vat'] :
......@@ -440,7 +440,7 @@ class TestAccounting(ERP5TypeTestCase):
resource_value = sequence.get('EUR'),
start_date = self.start_date,
stop_date = self.start_date,
bypass_init_script = 0,
created_by_builder = 0,
)
line = invoice.newContent(
......
......@@ -535,7 +535,7 @@ class TestAccountingRules(ERP5TypeTestCase):
start_date = DateTime(2004, 01, 01),
source_section = vendor.getRelativeUrl(),
destination_section = client.getRelativeUrl(),
bypass_init_script = 1,
created_by_builder = 1,
)
sequence.edit(
......@@ -563,7 +563,7 @@ class TestAccountingRules(ERP5TypeTestCase):
start_date = DateTime(2004, 01, 01),
source_section = vendor.getRelativeUrl(),
destination_section = client.getRelativeUrl(),
bypass_init_script = 1,
created_by_builder = 1,
)
invoice_line = simple_invoice.newContent(
......@@ -599,7 +599,7 @@ class TestAccountingRules(ERP5TypeTestCase):
start_date = DateTime(2004, 01, 01),
source_section = vendor.getRelativeUrl(),
destination_section = client.getRelativeUrl(),
bypass_init_script = 1,
created_by_builder = 1,
)
invoice_line = simple_invoice.newContent(
......@@ -689,7 +689,7 @@ class TestAccountingRules(ERP5TypeTestCase):
start_date = DateTime(2004, 01, 01),
source_section = vendor.getRelativeUrl(),
destination_section = client.getRelativeUrl(),
bypass_init_script = 1,
created_by_builder = 1,
)
invoice_line1 = simple_invoice.newContent(
......@@ -732,7 +732,7 @@ class TestAccountingRules(ERP5TypeTestCase):
start_date = DateTime(2004, 01, 01),
source_section = vendor.getRelativeUrl(),
destination_section = client.getRelativeUrl(),
bypass_init_script = 1,
created_by_builder = 1,
)
invoice_line = simple_invoice.newContent(
......@@ -807,7 +807,7 @@ class TestAccountingRules(ERP5TypeTestCase):
start_date = DateTime(2004, 01, 01),
source_section = vendor.getRelativeUrl(),
destination_section = client.getRelativeUrl(),
bypass_init_script = 1,
created_by_builder = 1,
)
notebook_line = multi_line_invoice.newContent(
......
......@@ -66,14 +66,16 @@ class FolderMixIn(ExtensionClass.Base, CopyContainer):
security.declareProtected(Permissions.AddPortalContent, 'newContent')
def newContent(self, id=None, portal_type=None, id_group=None,
default=None, method=None, immediate_reindex=0,
container=None, bypass_init_script=0, activate_kw=None, is_indexable=None, **kw):
container=None, created_by_builder=0, activate_kw=None,
is_indexable=None, **kw):
"""
Creates a new content
"""
if container is None:
container = self
if id is None:
new_id = str(container.generateNewId(id_group = id_group, default=default, method=method))
new_id = str(container.generateNewId(id_group = id_group,
default=default, method=method))
else:
new_id = str(id)
if portal_type is None:
......@@ -83,10 +85,14 @@ class FolderMixIn(ExtensionClass.Base, CopyContainer):
self.portal_types.constructContent(type_name=portal_type,
container=container,
id=new_id,
bypass_init_script=bypass_init_script,
created_by_builder=created_by_builder,
activate_kw=activate_kw,
is_indexable=is_indexable
) # **kw) removed due to CMF bug
# TODO :the **kw makes it impossible to create content not based on
# ERP5TypeInformation, because factory method often to not support
# keywords arguments.
new_instance = container[new_id]
if kw != {} : new_instance._edit(force_update=1, **kw)
if immediate_reindex: new_instance.immediateReindexObject()
......
......@@ -169,13 +169,11 @@ class ERP5TypeInformation( FactoryTypeInformation, RoleProviderBase ):
# Agent methods
#
security.declarePublic('constructInstance')
def constructInstance( self, container, id, bypass_init_script=0,
*args, **kw ):
def constructInstance( self, container, id, *args, **kw ):
"""
Build a "bare" instance of the appropriate type in
'container', using 'id' as its id.
Call the init_script for the portal_type, unless the
keyword arg __bypass_init_script is set to True.
Call the init_script for the portal_type.
Returns the object.
"""
# This is part is copied from CMFCore/TypesTool
......@@ -190,18 +188,15 @@ class ERP5TypeInformation( FactoryTypeInformation, RoleProviderBase ):
if len(self._roles):
self.assignRoleToSecurityGroup(ob)
# TODO: bypass_init_script must be passed as an argument
# to the init_script, and the init_script must always be called;
# so that user can decide what init should be done when this is
# created by DeliveryBuilder.
if self.init_script and not bypass_init_script:
if self.init_script :
# Acquire the init script in the context of this object
init_script = getattr(ob, self.init_script)
init_script(*args, **kw)
return ob
security.declareProtected(ERP5Permissions.AccessContentsInformation, 'getPropertySheetList')
security.declareProtected(ERP5Permissions.AccessContentsInformation,
'getPropertySheetList')
def getPropertySheetList( self ):
"""
Return list of content types.
......@@ -212,57 +207,69 @@ class ERP5TypeInformation( FactoryTypeInformation, RoleProviderBase ):
result.sort()
return result
security.declareProtected(ERP5Permissions.AccessContentsInformation, 'getHiddenContentTypeList')
security.declareProtected(ERP5Permissions.AccessContentsInformation,
'getHiddenContentTypeList')
def getHiddenContentTypeList( self ):
"""
Return list of content types.
"""
return self.hidden_content_type_list
security.declareProtected(ERP5Permissions.AccessContentsInformation, 'getBaseCategoryList')
security.declareProtected(ERP5Permissions.AccessContentsInformation,
'getBaseCategoryList')
def getBaseCategoryList( self ):
result = self.portal_categories.getBaseCategoryList()
result.sort()
return result
security.declareProtected(ERP5Permissions.AccessContentsInformation, 'getConstraintList')
security.declareProtected(ERP5Permissions.AccessContentsInformation,
'getConstraintList')
def getConstraintList( self ):
from Products.ERP5Type import Constraint
result = Constraint.__dict__.keys()
result = filter(lambda k: k != 'Constraint' and not k.startswith('__'), result)
result = filter(lambda k: k != 'Constraint' and not k.startswith('__'),
result)
result.sort()
return result
security.declareProtected(ERP5Permissions.AccessContentsInformation, 'getGroupList')
security.declareProtected(ERP5Permissions.AccessContentsInformation,
'getGroupList')
def getGroupList( self ):
return self.defined_group_list
security.declareProtected(ERP5Permissions.ModifyPortalContent, 'assignRoleToSecurityGroup')
security.declareProtected(ERP5Permissions.ModifyPortalContent,
'assignRoleToSecurityGroup')
def assignRoleToSecurityGroup(self, object):
"""
Assign Local Roles to Groups on object, based on Portal Type Role Definitions
Assign Local Roles to Groups on object, based on Portal Type
Role Definitions
"""
#FIXME We should check the type of the acl_users folder instead of
# checking which product is installed.
if ERP5UserManager is not None:
user_name = getSecurityManager().getUser().getId() # We use id for roles in ERP5Security
# We use id for roles in ERP5Security
user_name = getSecurityManager().getUser().getId()
elif NuxUserGroups is not None:
user_name = getSecurityManager().getUser().getUserName()
else:
raise RuntimeError, 'Product "NuxUserGroups" was not found on your setup. '\
raise RuntimeError, 'Product "ERP5Security" was not found on'\
'your setup. '\
'Please install it to benefit from group-based security'
# Retrieve applicable roles
role_mapping = self.getFilteredRoleListFor(object=object) # kw provided in order to take any appropriate action
# kw provided in order to take any appropriate action
role_mapping = self.getFilteredRoleListFor(object=object)
role_category_list = {}
for role, definition_list in role_mapping.items():
if not role_category_list.has_key(role):
role_category_list[role] = []
# For each role definition, we look for the base_category_script
# and try to use it to retrieve the values for the base_category list
# and try to use it to retrieve the values for
# the base_category list
for definition in definition_list:
# get the list of base_categories that are statically defined
category_base_list = [x.split('/')[0] for x in definition['category']]
category_base_list = [x.split('/')[0]
for x in definition['category']]
# get the list of base_categories that are to be fetched through the script
actual_base_category_list = [x for x in definition['base_category'] if x not in category_base_list]
# get the aggregated list of base categories, to preserve the order
......
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