Commit 972ef2ef authored by Jérome Perrin's avatar Jérome Perrin

business template: do not export owner role in LocalRoleTemplateItem

parent af648d3f
...@@ -4569,12 +4569,15 @@ class LocalRolesTemplateItem(BaseTemplateItem): ...@@ -4569,12 +4569,15 @@ class LocalRolesTemplateItem(BaseTemplateItem):
xml_data = '<local_roles_item>' xml_data = '<local_roles_item>'
# local roles # local roles
xml_data += '\n <local_roles>' xml_data += '\n <local_roles>'
for key in sorted(local_roles_dict): for user_id, role_list in sorted(local_roles_dict.items()):
xml_data += "\n <role id='%s'>" %(key,) if 'Owner' in role_list:
tuple = local_roles_dict[key] # We don't export Owner role as it set automatically when installing business template.
for item in tuple: role_list.remove('Owner')
xml_data += "\n <item>%s</item>" %(item,) if role_list:
xml_data += '\n </role>' xml_data += "\n <role id='%s'>" %(user_id,)
for role in role_list:
xml_data += "\n <item>%s</item>" %(role,)
xml_data += '\n </role>'
xml_data += '\n </local_roles>' xml_data += '\n </local_roles>'
if local_roles_group_id_dict: if local_roles_group_id_dict:
...@@ -4643,6 +4646,16 @@ class LocalRolesTemplateItem(BaseTemplateItem): ...@@ -4643,6 +4646,16 @@ class LocalRolesTemplateItem(BaseTemplateItem):
else: else:
local_roles_group_id_dict = None local_roles_group_id_dict = None
local_roles_dict, = self._objects[roles_path] local_roles_dict, = self._objects[roles_path]
# We ignore the owner defined in local_roles_dict and set it to the user installing that business template.
local_roles_dict = deepcopy(local_roles_dict)
for user_id, group_list in list(local_roles_dict.items()):
if group_list == ["Owner"]:
del local_roles_dict[user_id]
user = getSecurityManager().getUser()
if user is not None:
local_roles_dict.setdefault(user.getId(), []).append('Owner')
obj.__ac_local_roles__ = local_roles_dict obj.__ac_local_roles__ = local_roles_dict
if local_roles_group_id_dict: if local_roles_group_id_dict:
obj.__ac_local_roles_group_id_dict__ = local_roles_group_id_dict obj.__ac_local_roles_group_id_dict__ = local_roles_group_id_dict
......
...@@ -31,6 +31,7 @@ import unittest ...@@ -31,6 +31,7 @@ import unittest
import logging import logging
from unittest import expectedFailure, skip from unittest import expectedFailure, skip
from AccessControl import getSecurityManager
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Acquisition import aq_base from Acquisition import aq_base
from OFS.SimpleItem import SimpleItem from OFS.SimpleItem import SimpleItem
...@@ -2328,15 +2329,25 @@ class BusinessTemplateMixin(ERP5TypeTestCase, LogInterceptor): ...@@ -2328,15 +2329,25 @@ class BusinessTemplateMixin(ERP5TypeTestCase, LogInterceptor):
""" """
Create local roles Create local roles
""" """
new_local_roles = {'ac':['Owner', 'Manager'], # We'll export an owner in local roles ...
'group_function': ['Auditor']} new_local_roles = {
'ac': ['Owner', 'Manager'],
'group_function': ['Auditor']
}
# ... but after installing this business template, the owner
# will be reset:
expected_local_roles = {
'ac': ['Manager'],
getSecurityManager().getUser().getId(): ['Owner'],
'group_function': ['Auditor']
}
p = self.getPortal() p = self.getPortal()
module_id = sequence.get('module_id') module_id = sequence.get('module_id')
module = p._getOb(module_id, None) module = p._getOb(module_id, None)
self.assertTrue(module is not None) self.assertTrue(module is not None)
module.__ac_local_roles__ = new_local_roles module.__ac_local_roles__ = new_local_roles
self.assertEqual(module.__ac_local_roles__, new_local_roles) self.assertEqual(module.__ac_local_roles__, new_local_roles)
sequence.edit(local_roles=new_local_roles) sequence.edit(local_roles=expected_local_roles)
def stepRemoveLocalRoles(self, sequence=None, **kw): def stepRemoveLocalRoles(self, sequence=None, **kw):
""" """
......
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