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

Rework LocalRolesTemplateItem with local role group ids.

We were not able to export and import back roles of a document when more than
one local role group id was used.
parent 8a5dbcf3
...@@ -4568,15 +4568,14 @@ class LocalRolesTemplateItem(BaseTemplateItem): ...@@ -4568,15 +4568,14 @@ class LocalRolesTemplateItem(BaseTemplateItem):
if local_roles_group_id_dict: if local_roles_group_id_dict:
# local roles group id dict (not included by default to be stable with # local roles group id dict (not included by default to be stable with
# old bts) # old bts)
xml_data += '\n <local_roles_group_id>' xml_data += '\n <local_role_group_ids>'
for principal, local_roles_group_id_list in sorted(local_roles_group_id_dict.items()): for local_role_group_id, local_roles_group_id_list in sorted(local_roles_group_id_dict.items()):
xml_data += "\n <principal id='%s'>" % escape(principal) xml_data += "\n <local_role_group_id id='%s'>" % escape(local_role_group_id)
for local_roles_group_id in local_roles_group_id_list: for principal, role in sorted(local_roles_group_id_list):
for item in local_roles_group_id: xml_data += "\n <principal id='%s'>%s</principal>" % \
xml_data += "\n <local_roles_group_id>%s</local_roles_group_id>" % \ (escape(principal), escape(role))
escape(item) xml_data += "\n </local_role_group_id>"
xml_data += "\n </principal>" xml_data += '\n </local_role_group_ids>'
xml_data += '\n </local_roles_group_id>'
xml_data += '\n</local_roles_item>' xml_data += '\n</local_roles_item>'
if isinstance(xml_data, unicode): if isinstance(xml_data, unicode):
...@@ -4605,10 +4604,11 @@ class LocalRolesTemplateItem(BaseTemplateItem): ...@@ -4605,10 +4604,11 @@ class LocalRolesTemplateItem(BaseTemplateItem):
# local roles group id # local roles group id
local_roles_group_id_dict = {} local_roles_group_id_dict = {}
for principal in xml.findall('//principal'): for local_role_group_id in xml.findall('//local_role_group_id'):
local_roles_group_id_dict[principal.get('id')] = set([tuple( role_set = set()
[group_id.text for group_id in for principal in local_role_group_id.findall('./principal'):
principal.findall('./local_roles_group_id')])]) role_set.add((principal.get('id'), principal.text))
local_roles_group_id_dict[local_role_group_id.get('id')] = role_set
self._objects['local_roles/%s' % (file_name[:-4],)] = ( self._objects['local_roles/%s' % (file_name[:-4],)] = (
local_roles_dict, local_roles_group_id_dict) local_roles_dict, local_roles_group_id_dict)
...@@ -4655,6 +4655,9 @@ class LocalRolesTemplateItem(BaseTemplateItem): ...@@ -4655,6 +4655,9 @@ class LocalRolesTemplateItem(BaseTemplateItem):
obj = p.unrestrictedTraverse(path, None) obj = p.unrestrictedTraverse(path, None)
if obj is not None: if obj is not None:
setattr(obj, '__ac_local_roles__', {}) setattr(obj, '__ac_local_roles__', {})
if getattr(aq_base(obj), '__ac_local_roles_group_id_dict__',
None) is not None:
delattr(obj, '__ac_local_roles_group_id_dict__')
obj.reindexObject() obj.reindexObject()
class BusinessTemplate(XMLObject): class BusinessTemplate(XMLObject):
......
...@@ -6609,12 +6609,17 @@ class TestBusinessTemplate(BusinessTemplateMixin): ...@@ -6609,12 +6609,17 @@ class TestBusinessTemplate(BusinessTemplateMixin):
sql_catalog.sql_catalog_security_uid_columns = ( sql_catalog.sql_catalog_security_uid_columns = (
' | security_uid', ' | security_uid',
'Alternate | alternate_security_uid', 'Alternate | alternate_security_uid',
'Another | another_security_uid',
) )
# add category # add categories
self.portal.portal_categories.local_role_group.newContent( self.portal.portal_categories.local_role_group.newContent(
portal_type='Category', portal_type='Category',
reference = 'Alternate', reference='Alternate',
id = 'Alternate') id='Alternate')
self.portal.portal_categories.local_role_group.newContent(
portal_type='Category',
reference='Another',
id='Another')
types_tool = self.portal.portal_types types_tool = self.portal.portal_types
object_type = types_tool.newContent('Geek Object', 'Base Type', object_type = types_tool.newContent('Geek Object', 'Base Type',
...@@ -6630,11 +6635,18 @@ class TestBusinessTemplate(BusinessTemplateMixin): ...@@ -6630,11 +6635,18 @@ class TestBusinessTemplate(BusinessTemplateMixin):
portal_type='Geek Object', id='1') portal_type='Geek Object', id='1')
# simulate role assignment # simulate role assignment
new_object.__ac_local_roles__ = dict(group=['Assignee']) new_object.__ac_local_roles__ = dict(group=['Assignee', 'Assignor'],
initial___ac_local_roles_group_id_dict__ = dict(Alternate=set([('group', 'Assignee')])) another_group=['Assignee'])
initial___ac_local_roles_group_id_dict__ = dict(
Alternate=set([('group', 'Assignee')]),
Another=set([('group', 'Assignor'),
('another_group', 'Assignee')])).copy()
new_object.__ac_local_roles_group_id_dict__ = initial___ac_local_roles_group_id_dict__ new_object.__ac_local_roles_group_id_dict__ = initial___ac_local_roles_group_id_dict__
self.tic() self.tic()
# the role information defined here does not match the assigned roles that
# we simulated above, but we just want to test that an exported role
# information can be imported back
object_type.newContent(portal_type='Role Information', object_type.newContent(portal_type='Role Information',
local_role_group_value=self.portal.portal_categories.local_role_group.Alternate.getRelativeUrl(), local_role_group_value=self.portal.portal_categories.local_role_group.Alternate.getRelativeUrl(),
role_name_list=('Assignee', )) role_name_list=('Assignee', ))
...@@ -6666,13 +6678,19 @@ class TestBusinessTemplate(BusinessTemplateMixin): ...@@ -6666,13 +6678,19 @@ class TestBusinessTemplate(BusinessTemplateMixin):
new_bt.install() new_bt.install()
try: try:
role, = object_type.getRoleInformationList() role, = object_type.getRoleInformationList()
self.assertEquals(self.portal.portal_categories.local_role_group.Alternate, self.assertEquals(self.portal.portal_categories.local_role_group.Alternate,
role.getLocalRoleGroupValue()) role.getLocalRoleGroupValue())
path = self.portal.geek_module['1'] path = self.portal.geek_module['1']
self.assertEquals([('group', ['Assignee'],)], [item for item in self.assertEquals(sorted([
path.__ac_local_roles__.items() if item[1] != ['Owner']]) ('another_group', ['Assignee']),
('group', ['Assignee', 'Assignor']),
]), sorted([item for item in
path.__ac_local_roles__.items() if item[1] != ['Owner']]))
self.assertEquals(initial___ac_local_roles_group_id_dict__, self.assertEquals(initial___ac_local_roles_group_id_dict__,
path.__ac_local_roles_group_id_dict__) path.__ac_local_roles_group_id_dict__)
# make sure we can reindexing the object works
path.recursiveImmediateReindexObject()
self.tic()
finally: finally:
# restore state # restore state
sql_catalog.sql_catalog_security_uid_columns = \ sql_catalog.sql_catalog_security_uid_columns = \
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
import unittest import unittest
from Testing import ZopeTestCase from Testing import ZopeTestCase
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.backportUnittest import expectedFailure
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
......
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