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): ...@@ -333,7 +333,7 @@ class OrderBuilder(XMLObject, Amount, Predicate):
delivery = delivery_module.newContent( delivery = delivery_module.newContent(
portal_type=self.getDeliveryPortalType(), portal_type=self.getDeliveryPortalType(),
id=new_delivery_id, id=new_delivery_id,
bypass_init_script=1, created_by_builder=1,
activate_kw=activate_kw,**kw) activate_kw=activate_kw,**kw)
# Put properties on delivery # Put properties on delivery
delivery.edit(**property_dict) delivery.edit(**property_dict)
......
...@@ -291,7 +291,7 @@ class TestAccounting(ERP5TypeTestCase): ...@@ -291,7 +291,7 @@ class TestAccounting(ERP5TypeTestCase):
portal_type = self.accounting_transaction_portal_type, portal_type = self.accounting_transaction_portal_type,
source_section_value = sequence.get('client'), source_section_value = sequence.get('client'),
resource_value = sequence.get('EUR'), resource_value = sequence.get('EUR'),
bypass_init_script = 1, created_by_builder = 1,
) )
# setting both source and destination shouldn't use mirror accounts # setting both source and destination shouldn't use mirror accounts
...@@ -399,7 +399,7 @@ class TestAccounting(ERP5TypeTestCase): ...@@ -399,7 +399,7 @@ class TestAccounting(ERP5TypeTestCase):
destination_value = sequence.get('client'), destination_value = sequence.get('client'),
resource = invoice_prop['currency'], resource = invoice_prop['currency'],
start_date = date, stop_date = date, start_date = date, stop_date = date,
bypass_init_script = 0, created_by_builder = 0,
) )
for line_type in ['income', 'receivable', 'collected_vat'] : for line_type in ['income', 'receivable', 'collected_vat'] :
...@@ -440,7 +440,7 @@ class TestAccounting(ERP5TypeTestCase): ...@@ -440,7 +440,7 @@ class TestAccounting(ERP5TypeTestCase):
resource_value = sequence.get('EUR'), resource_value = sequence.get('EUR'),
start_date = self.start_date, start_date = self.start_date,
stop_date = self.start_date, stop_date = self.start_date,
bypass_init_script = 0, created_by_builder = 0,
) )
line = invoice.newContent( line = invoice.newContent(
......
...@@ -535,7 +535,7 @@ class TestAccountingRules(ERP5TypeTestCase): ...@@ -535,7 +535,7 @@ class TestAccountingRules(ERP5TypeTestCase):
start_date = DateTime(2004, 01, 01), start_date = DateTime(2004, 01, 01),
source_section = vendor.getRelativeUrl(), source_section = vendor.getRelativeUrl(),
destination_section = client.getRelativeUrl(), destination_section = client.getRelativeUrl(),
bypass_init_script = 1, created_by_builder = 1,
) )
sequence.edit( sequence.edit(
...@@ -563,7 +563,7 @@ class TestAccountingRules(ERP5TypeTestCase): ...@@ -563,7 +563,7 @@ class TestAccountingRules(ERP5TypeTestCase):
start_date = DateTime(2004, 01, 01), start_date = DateTime(2004, 01, 01),
source_section = vendor.getRelativeUrl(), source_section = vendor.getRelativeUrl(),
destination_section = client.getRelativeUrl(), destination_section = client.getRelativeUrl(),
bypass_init_script = 1, created_by_builder = 1,
) )
invoice_line = simple_invoice.newContent( invoice_line = simple_invoice.newContent(
...@@ -599,7 +599,7 @@ class TestAccountingRules(ERP5TypeTestCase): ...@@ -599,7 +599,7 @@ class TestAccountingRules(ERP5TypeTestCase):
start_date = DateTime(2004, 01, 01), start_date = DateTime(2004, 01, 01),
source_section = vendor.getRelativeUrl(), source_section = vendor.getRelativeUrl(),
destination_section = client.getRelativeUrl(), destination_section = client.getRelativeUrl(),
bypass_init_script = 1, created_by_builder = 1,
) )
invoice_line = simple_invoice.newContent( invoice_line = simple_invoice.newContent(
...@@ -689,7 +689,7 @@ class TestAccountingRules(ERP5TypeTestCase): ...@@ -689,7 +689,7 @@ class TestAccountingRules(ERP5TypeTestCase):
start_date = DateTime(2004, 01, 01), start_date = DateTime(2004, 01, 01),
source_section = vendor.getRelativeUrl(), source_section = vendor.getRelativeUrl(),
destination_section = client.getRelativeUrl(), destination_section = client.getRelativeUrl(),
bypass_init_script = 1, created_by_builder = 1,
) )
invoice_line1 = simple_invoice.newContent( invoice_line1 = simple_invoice.newContent(
...@@ -732,7 +732,7 @@ class TestAccountingRules(ERP5TypeTestCase): ...@@ -732,7 +732,7 @@ class TestAccountingRules(ERP5TypeTestCase):
start_date = DateTime(2004, 01, 01), start_date = DateTime(2004, 01, 01),
source_section = vendor.getRelativeUrl(), source_section = vendor.getRelativeUrl(),
destination_section = client.getRelativeUrl(), destination_section = client.getRelativeUrl(),
bypass_init_script = 1, created_by_builder = 1,
) )
invoice_line = simple_invoice.newContent( invoice_line = simple_invoice.newContent(
...@@ -807,7 +807,7 @@ class TestAccountingRules(ERP5TypeTestCase): ...@@ -807,7 +807,7 @@ class TestAccountingRules(ERP5TypeTestCase):
start_date = DateTime(2004, 01, 01), start_date = DateTime(2004, 01, 01),
source_section = vendor.getRelativeUrl(), source_section = vendor.getRelativeUrl(),
destination_section = client.getRelativeUrl(), destination_section = client.getRelativeUrl(),
bypass_init_script = 1, created_by_builder = 1,
) )
notebook_line = multi_line_invoice.newContent( notebook_line = multi_line_invoice.newContent(
......
...@@ -66,14 +66,16 @@ class FolderMixIn(ExtensionClass.Base, CopyContainer): ...@@ -66,14 +66,16 @@ class FolderMixIn(ExtensionClass.Base, CopyContainer):
security.declareProtected(Permissions.AddPortalContent, 'newContent') security.declareProtected(Permissions.AddPortalContent, 'newContent')
def newContent(self, id=None, portal_type=None, id_group=None, def newContent(self, id=None, portal_type=None, id_group=None,
default=None, method=None, immediate_reindex=0, 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 Creates a new content
""" """
if container is None: if container is None:
container = self container = self
if id is None: 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: else:
new_id = str(id) new_id = str(id)
if portal_type is None: if portal_type is None:
...@@ -83,10 +85,14 @@ class FolderMixIn(ExtensionClass.Base, CopyContainer): ...@@ -83,10 +85,14 @@ class FolderMixIn(ExtensionClass.Base, CopyContainer):
self.portal_types.constructContent(type_name=portal_type, self.portal_types.constructContent(type_name=portal_type,
container=container, container=container,
id=new_id, id=new_id,
bypass_init_script=bypass_init_script, created_by_builder=created_by_builder,
activate_kw=activate_kw, activate_kw=activate_kw,
is_indexable=is_indexable is_indexable=is_indexable
) # **kw) removed due to CMF bug ) # **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] new_instance = container[new_id]
if kw != {} : new_instance._edit(force_update=1, **kw) if kw != {} : new_instance._edit(force_update=1, **kw)
if immediate_reindex: new_instance.immediateReindexObject() if immediate_reindex: new_instance.immediateReindexObject()
......
...@@ -169,13 +169,11 @@ class ERP5TypeInformation( FactoryTypeInformation, RoleProviderBase ): ...@@ -169,13 +169,11 @@ class ERP5TypeInformation( FactoryTypeInformation, RoleProviderBase ):
# Agent methods # Agent methods
# #
security.declarePublic('constructInstance') security.declarePublic('constructInstance')
def constructInstance( self, container, id, bypass_init_script=0, def constructInstance( self, container, id, *args, **kw ):
*args, **kw ):
""" """
Build a "bare" instance of the appropriate type in Build a "bare" instance of the appropriate type in
'container', using 'id' as its id. 'container', using 'id' as its id.
Call the init_script for the portal_type, unless the Call the init_script for the portal_type.
keyword arg __bypass_init_script is set to True.
Returns the object. Returns the object.
""" """
# This is part is copied from CMFCore/TypesTool # This is part is copied from CMFCore/TypesTool
...@@ -190,18 +188,15 @@ class ERP5TypeInformation( FactoryTypeInformation, RoleProviderBase ): ...@@ -190,18 +188,15 @@ class ERP5TypeInformation( FactoryTypeInformation, RoleProviderBase ):
if len(self._roles): if len(self._roles):
self.assignRoleToSecurityGroup(ob) self.assignRoleToSecurityGroup(ob)
# TODO: bypass_init_script must be passed as an argument if self.init_script :
# 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:
# Acquire the init script in the context of this object # Acquire the init script in the context of this object
init_script = getattr(ob, self.init_script) init_script = getattr(ob, self.init_script)
init_script(*args, **kw) init_script(*args, **kw)
return ob return ob
security.declareProtected(ERP5Permissions.AccessContentsInformation, 'getPropertySheetList') security.declareProtected(ERP5Permissions.AccessContentsInformation,
'getPropertySheetList')
def getPropertySheetList( self ): def getPropertySheetList( self ):
""" """
Return list of content types. Return list of content types.
...@@ -212,57 +207,69 @@ class ERP5TypeInformation( FactoryTypeInformation, RoleProviderBase ): ...@@ -212,57 +207,69 @@ class ERP5TypeInformation( FactoryTypeInformation, RoleProviderBase ):
result.sort() result.sort()
return result return result
security.declareProtected(ERP5Permissions.AccessContentsInformation, 'getHiddenContentTypeList') security.declareProtected(ERP5Permissions.AccessContentsInformation,
'getHiddenContentTypeList')
def getHiddenContentTypeList( self ): def getHiddenContentTypeList( self ):
""" """
Return list of content types. Return list of content types.
""" """
return self.hidden_content_type_list return self.hidden_content_type_list
security.declareProtected(ERP5Permissions.AccessContentsInformation, 'getBaseCategoryList') security.declareProtected(ERP5Permissions.AccessContentsInformation,
'getBaseCategoryList')
def getBaseCategoryList( self ): def getBaseCategoryList( self ):
result = self.portal_categories.getBaseCategoryList() result = self.portal_categories.getBaseCategoryList()
result.sort() result.sort()
return result return result
security.declareProtected(ERP5Permissions.AccessContentsInformation, 'getConstraintList') security.declareProtected(ERP5Permissions.AccessContentsInformation,
'getConstraintList')
def getConstraintList( self ): def getConstraintList( self ):
from Products.ERP5Type import Constraint from Products.ERP5Type import Constraint
result = Constraint.__dict__.keys() 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() result.sort()
return result return result
security.declareProtected(ERP5Permissions.AccessContentsInformation, 'getGroupList') security.declareProtected(ERP5Permissions.AccessContentsInformation,
'getGroupList')
def getGroupList( self ): def getGroupList( self ):
return self.defined_group_list return self.defined_group_list
security.declareProtected(ERP5Permissions.ModifyPortalContent, 'assignRoleToSecurityGroup') security.declareProtected(ERP5Permissions.ModifyPortalContent,
'assignRoleToSecurityGroup')
def assignRoleToSecurityGroup(self, object): 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 #FIXME We should check the type of the acl_users folder instead of
# checking which product is installed. # checking which product is installed.
if ERP5UserManager is not None: 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: elif NuxUserGroups is not None:
user_name = getSecurityManager().getUser().getUserName() user_name = getSecurityManager().getUser().getUserName()
else: 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' 'Please install it to benefit from group-based security'
# Retrieve applicable roles # 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 = {} role_category_list = {}
for role, definition_list in role_mapping.items(): for role, definition_list in role_mapping.items():
if not role_category_list.has_key(role): if not role_category_list.has_key(role):
role_category_list[role] = [] role_category_list[role] = []
# For each role definition, we look for the base_category_script # 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: for definition in definition_list:
# get the list of base_categories that are statically defined # 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 # 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] 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 # 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