Commit 8217bffe authored by Jérome Perrin's avatar Jérome Perrin

business template: do not export owner role in LocalRoleTemplateItem

parent a84d5aed
...@@ -4755,12 +4755,15 @@ class LocalRolesTemplateItem(BaseTemplateItem): ...@@ -4755,12 +4755,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:
...@@ -4829,6 +4832,18 @@ class LocalRolesTemplateItem(BaseTemplateItem): ...@@ -4829,6 +4832,18 @@ 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]
current_user = getSecurityManager().getUser()
if current_user is not None:
current_user_id = current_user.getId()
if current_user_id is not None:
local_roles_dict.setdefault(current_user_id, []).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
...@@ -2329,15 +2330,25 @@ class BusinessTemplateMixin(ERP5TypeTestCase, LogInterceptor): ...@@ -2329,15 +2330,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