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

business template: do not export owner role in LocalRoleTemplateItem

parent af648d3f
......@@ -4569,11 +4569,14 @@ class LocalRolesTemplateItem(BaseTemplateItem):
xml_data = '<local_roles_item>'
# local roles
xml_data += '\n <local_roles>'
for key in sorted(local_roles_dict):
xml_data += "\n <role id='%s'>" %(key,)
tuple = local_roles_dict[key]
for item in tuple:
xml_data += "\n <item>%s</item>" %(item,)
for user_id, role_list in sorted(local_roles_dict.items()):
if 'Owner' in role_list:
# We don't export Owner role as it set automatically when installing business template.
role_list.remove('Owner')
if role_list:
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>'
......@@ -4643,6 +4646,16 @@ class LocalRolesTemplateItem(BaseTemplateItem):
else:
local_roles_group_id_dict = None
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
if local_roles_group_id_dict:
obj.__ac_local_roles_group_id_dict__ = local_roles_group_id_dict
......
......@@ -31,6 +31,7 @@ import unittest
import logging
from unittest import expectedFailure, skip
from AccessControl import getSecurityManager
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Acquisition import aq_base
from OFS.SimpleItem import SimpleItem
......@@ -2328,15 +2329,25 @@ class BusinessTemplateMixin(ERP5TypeTestCase, LogInterceptor):
"""
Create local roles
"""
new_local_roles = {'ac':['Owner', 'Manager'],
'group_function': ['Auditor']}
# We'll export an owner in local roles ...
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()
module_id = sequence.get('module_id')
module = p._getOb(module_id, None)
self.assertTrue(module is not None)
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):
"""
......
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