Commit 89612fd0 authored by Romain Courteaud's avatar Romain Courteaud

Manage catalog role_keys and local_role_keys.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@19407 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 49df4003
...@@ -3866,6 +3866,192 @@ class CatalogScriptableKeyTemplateItem(BaseTemplateItem): ...@@ -3866,6 +3866,192 @@ class CatalogScriptableKeyTemplateItem(BaseTemplateItem):
xml_data = self.generateXml(path=path) xml_data = self.generateXml(path=path)
bta.addObject(obj=xml_data, name=path, path=None) bta.addObject(obj=xml_data, name=path, path=None)
class CatalogRoleKeyTemplateItem(BaseTemplateItem):
# XXX Copy/paste from CatalogScriptableKeyTemplateItem
def build(self, context, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_catalog_role_keys = list(catalog.sql_catalog_role_keys)
key_list = []
for key in self._archive.keys():
if key in sql_catalog_role_keys:
key_list.append(key)
else:
raise NotFound, 'Role key "%r" not found in catalog' %(key,)
if len(key_list) > 0:
self._objects[self.__class__.__name__+'/'+'role_key_list'] = key_list
def _importFile(self, file_name, file):
list = []
xml = parse(file)
key_list = xml.getElementsByTagName('key')
for key in key_list:
node = key.childNodes[0]
value = node.data
list.append(str(value))
self._objects[file_name[:-4]] = list
def install(self, context, trashbin, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_catalog_role_keys = list(catalog.sql_catalog_role_keys)
if context.getTemplateFormatVersion() == 1:
if len(self._objects.keys()) == 0: # needed because of pop()
return
keys = []
for k in self._objects.values().pop(): # because of list of list
keys.append(k)
else:
keys = self._archive.keys()
update_dict = kw.get('object_to_update')
force = kw.get('force')
# XXX must a find a better way to manage scriptable key
if update_dict.has_key('role_key_list') or force:
if not force:
if update_dict.has_key('role_key_list'):
action = update_dict['role_key_list']
if action == 'nothing':
return
for key in keys:
if key not in sql_catalog_role_keys:
sql_catalog_role_keys.append(key)
catalog.sql_catalog_role_keys = tuple(sql_catalog_role_keys)
def uninstall(self, context, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_catalog_role_keys = list(catalog.sql_catalog_role_keys)
object_path = kw.get('object_path', None)
if object_path is not None:
object_keys = [object_path]
else:
object_keys = self._archive.keys()
for key in object_keys:
if key in sql_catalog_role_keys:
sql_catalog_role_keys.remove(key)
catalog.sql_catalog_role_keys = tuple(sql_catalog_role_keys)
BaseTemplateItem.uninstall(self, context, **kw)
# Function to generate XML Code Manually
def generateXml(self, path=None):
obj = self._objects[path]
xml_data = '<key_list>'
obj.sort()
for key in obj:
xml_data += '\n <key>%s</key>' %(key)
xml_data += '\n</key_list>'
return xml_data
def export(self, context, bta, **kw):
if len(self._objects.keys()) == 0:
return
path = os.path.join(bta.path, self.__class__.__name__)
bta.addFolder(name=path)
for path in self._objects.keys():
xml_data = self.generateXml(path=path)
bta.addObject(obj=xml_data, name=path, path=None)
class CatalogLocalRoleKeyTemplateItem(BaseTemplateItem):
# XXX Copy/paste from CatalogScriptableKeyTemplateItem
def build(self, context, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_catalog_local_role_keys = list(catalog.sql_catalog_local_role_keys)
key_list = []
for key in self._archive.keys():
if key in sql_catalog_local_role_keys:
key_list.append(key)
else:
raise NotFound, 'LocalRole key "%r" not found in catalog' %(key,)
if len(key_list) > 0:
self._objects[self.__class__.__name__+'/'+'local_role_key_list'] = key_list
def _importFile(self, file_name, file):
list = []
xml = parse(file)
key_list = xml.getElementsByTagName('key')
for key in key_list:
node = key.childNodes[0]
value = node.data
list.append(str(value))
self._objects[file_name[:-4]] = list
def install(self, context, trashbin, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_catalog_local_role_keys = list(catalog.sql_catalog_local_role_keys)
if context.getTemplateFormatVersion() == 1:
if len(self._objects.keys()) == 0: # needed because of pop()
return
keys = []
for k in self._objects.values().pop(): # because of list of list
keys.append(k)
else:
keys = self._archive.keys()
update_dict = kw.get('object_to_update')
force = kw.get('force')
# XXX must a find a better way to manage scriptable key
if update_dict.has_key('local_role_key_list') or force:
if not force:
if update_dict.has_key('local_role_key_list'):
action = update_dict['local_role_key_list']
if action == 'nothing':
return
for key in keys:
if key not in sql_catalog_local_role_keys:
sql_catalog_local_role_keys.append(key)
catalog.sql_catalog_local_role_keys = tuple(sql_catalog_local_role_keys)
def uninstall(self, context, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_catalog_local_role_keys = list(catalog.sql_catalog_local_role_keys)
object_path = kw.get('object_path', None)
if object_path is not None:
object_keys = [object_path]
else:
object_keys = self._archive.keys()
for key in object_keys:
if key in sql_catalog_local_role_keys:
sql_catalog_local_role_keys.remove(key)
catalog.sql_catalog_local_role_keys = tuple(sql_catalog_local_role_keys)
BaseTemplateItem.uninstall(self, context, **kw)
# Function to generate XML Code Manually
def generateXml(self, path=None):
obj = self._objects[path]
xml_data = '<key_list>'
obj.sort()
for key in obj:
xml_data += '\n <key>%s</key>' %(key)
xml_data += '\n</key_list>'
return xml_data
def export(self, context, bta, **kw):
if len(self._objects.keys()) == 0:
return
path = os.path.join(bta.path, self.__class__.__name__)
bta.addFolder(name=path)
for path in self._objects.keys():
xml_data = self.generateXml(path=path)
bta.addObject(obj=xml_data, name=path, path=None)
class MessageTranslationTemplateItem(BaseTemplateItem): class MessageTranslationTemplateItem(BaseTemplateItem):
def build(self, context, **kw): def build(self, context, **kw):
...@@ -4209,6 +4395,8 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -4209,6 +4395,8 @@ Business Template is a set of definitions, such as skins, portal types and categ
'_catalog_multivalue_key_item', '_catalog_multivalue_key_item',
'_catalog_topic_key_item', '_catalog_topic_key_item',
'_catalog_scriptable_key_item', '_catalog_scriptable_key_item',
'_catalog_role_key_item',
'_catalog_local_role_key_item',
] ]
def __init__(self, *args, **kw): def __init__(self, *args, **kw):
...@@ -4364,6 +4552,12 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -4364,6 +4552,12 @@ Business Template is a set of definitions, such as skins, portal types and categ
self._catalog_scriptable_key_item = \ self._catalog_scriptable_key_item = \
CatalogScriptableKeyTemplateItem( CatalogScriptableKeyTemplateItem(
self.getTemplateCatalogScriptableKeyList()) self.getTemplateCatalogScriptableKeyList())
self._catalog_role_key_item = \
CatalogRoleKeyTemplateItem(
self.getTemplateCatalogRoleKeyList())
self._catalog_local_role_key_item = \
CatalogLocalRoleKeyTemplateItem(
self.getTemplateCatalogLocalRoleKeyList())
# Build each part # Build each part
for item_name in self._item_name_list: for item_name in self._item_name_list:
...@@ -4971,6 +5165,12 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -4971,6 +5165,12 @@ Business Template is a set of definitions, such as skins, portal types and categ
self._catalog_scriptable_key_item = \ self._catalog_scriptable_key_item = \
CatalogScriptableKeyTemplateItem( CatalogScriptableKeyTemplateItem(
self.getTemplateCatalogScriptableKeyList()) self.getTemplateCatalogScriptableKeyList())
self._catalog_role_key_item = \
CatalogRoleKeyTemplateItem(
self.getTemplateCatalogRoleKeyList())
self._catalog_local_role_key_item = \
CatalogLocalRoleKeyTemplateItem(
self.getTemplateCatalogLocalRoleKeyList())
for item_name in self._item_name_list: for item_name in self._item_name_list:
getattr(self, item_name).importFile(bta) getattr(self, item_name).importFile(bta)
...@@ -5057,6 +5257,8 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -5057,6 +5257,8 @@ Business Template is a set of definitions, such as skins, portal types and categ
'CatalogTopicKey' : '_catalog_topic_key_item', 'CatalogTopicKey' : '_catalog_topic_key_item',
'Tool': '_tool_item', 'Tool': '_tool_item',
'CatalogScriptableKey' : '_catalog_scriptable_key_item', 'CatalogScriptableKey' : '_catalog_scriptable_key_item',
'CatalogRoleKey' : '_catalog_role_key_item',
'CatalogLocalRoleKey' : '_catalog_local_role_key_item',
} }
object_id = REQUEST.object_id object_id = REQUEST.object_id
...@@ -5113,6 +5315,8 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -5113,6 +5315,8 @@ Business Template is a set of definitions, such as skins, portal types and categ
'_catalog_multivalue_key_item', '_catalog_multivalue_key_item',
'_catalog_topic_key_item', '_catalog_topic_key_item',
'_catalog_scriptable_key_item', '_catalog_scriptable_key_item',
'_catalog_role_key_item',
'_catalog_local_role_key_item',
'_portal_type_allowed_content_type_item', '_portal_type_allowed_content_type_item',
'_portal_type_hidden_content_type_item', '_portal_type_hidden_content_type_item',
'_portal_type_property_sheet_item', '_portal_type_property_sheet_item',
......
...@@ -1353,6 +1353,8 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor): ...@@ -1353,6 +1353,8 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
multivalue_key = 'fake_multivalue' multivalue_key = 'fake_multivalue'
topic_key = 'fake_topic' topic_key = 'fake_topic'
scriptable_key = 'fake_search_text | fake_script_query' scriptable_key = 'fake_search_text | fake_script_query'
role_key = 'Foo | catalog.owner'
local_role_key = 'Bar | catalog.owner'
catalog = self.getCatalogTool().getSQLCatalog() catalog = self.getCatalogTool().getSQLCatalog()
self.failUnless(catalog is not None) self.failUnless(catalog is not None)
# result table # result table
...@@ -1418,11 +1420,28 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor): ...@@ -1418,11 +1420,28 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
sql_catalog_scriptable_keys.sort() sql_catalog_scriptable_keys.sort()
catalog.sql_catalog_scriptable_keys = tuple(sql_catalog_scriptable_keys) catalog.sql_catalog_scriptable_keys = tuple(sql_catalog_scriptable_keys)
self.failUnless(scriptable_key in catalog.sql_catalog_scriptable_keys) self.failUnless(scriptable_key in catalog.sql_catalog_scriptable_keys)
# role keys
sequence.edit(related_key=related_key, result_key=result_key, result_table=result_table, \ if role_key not in catalog.sql_catalog_role_keys:
keyword_key=keyword_key, full_text_key=full_text_key, request_key=request_key, \ sql_catalog_role_keys = list(catalog.sql_catalog_role_keys)
sql_catalog_role_keys.append(role_key)
sql_catalog_role_keys.sort()
catalog.sql_catalog_role_keys = tuple(sql_catalog_role_keys)
self.failUnless(role_key in catalog.sql_catalog_role_keys)
# local_role keys
if local_role_key not in catalog.sql_catalog_local_role_keys:
sql_catalog_local_role_keys = list(catalog.sql_catalog_local_role_keys)
sql_catalog_local_role_keys.append(local_role_key)
sql_catalog_local_role_keys.sort()
catalog.sql_catalog_local_role_keys = tuple(sql_catalog_local_role_keys)
self.failUnless(local_role_key in catalog.sql_catalog_local_role_keys)
sequence.edit(related_key=related_key, result_key=result_key,
result_table=result_table,
keyword_key=keyword_key, full_text_key=full_text_key,
request_key=request_key,
multivalue_key=multivalue_key, topic_key=topic_key, \ multivalue_key=multivalue_key, topic_key=topic_key, \
scriptable_key=scriptable_key) scriptable_key=scriptable_key,
role_key=role_key, local_role_key=local_role_key)
def stepModifyCatalogConfiguration(self, sequence, **kw): def stepModifyCatalogConfiguration(self, sequence, **kw):
"""Modify the current configuration of the catalog. """Modify the current configuration of the catalog.
...@@ -1505,6 +1524,10 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor): ...@@ -1505,6 +1524,10 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
self.failUnless(topic_key is not None) self.failUnless(topic_key is not None)
scriptable_key = sequence.get('scriptable_key', None) scriptable_key = sequence.get('scriptable_key', None)
self.failUnless(scriptable_key is not None) self.failUnless(scriptable_key is not None)
role_key = sequence.get('role_key', None)
self.failUnless(role_key is not None)
local_role_key = sequence.get('local_role_key', None)
self.failUnless(local_role_key is not None)
bt.edit(template_catalog_related_key_list=[related_key], bt.edit(template_catalog_related_key_list=[related_key],
template_catalog_result_key_list=[result_key], template_catalog_result_key_list=[result_key],
...@@ -1515,6 +1538,8 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor): ...@@ -1515,6 +1538,8 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
template_catalog_multivalue_key_list=[multivalue_key], template_catalog_multivalue_key_list=[multivalue_key],
template_catalog_topic_key_list=[topic_key], template_catalog_topic_key_list=[topic_key],
template_catalog_scriptable_key_list=[scriptable_key], template_catalog_scriptable_key_list=[scriptable_key],
template_catalog_role_key_list=[role_key],
template_catalog_local_role_key_list=[local_role_key],
) )
def stepRemoveKeysAndTable(self, sequence=list, sequence_list=None, **kw): def stepRemoveKeysAndTable(self, sequence=list, sequence_list=None, **kw):
...@@ -1539,6 +1564,10 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor): ...@@ -1539,6 +1564,10 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
self.failUnless(topic_key is not None) self.failUnless(topic_key is not None)
scriptable_key = sequence.get('scriptable_key', None) scriptable_key = sequence.get('scriptable_key', None)
self.failUnless(scriptable_key is not None) self.failUnless(scriptable_key is not None)
role_key = sequence.get('role_key', None)
self.failUnless(role_key is not None)
local_role_key = sequence.get('local_role_key', None)
self.failUnless(local_role_key is not None)
catalog = self.getCatalogTool().getSQLCatalog() catalog = self.getCatalogTool().getSQLCatalog()
self.failUnless(catalog is not None) self.failUnless(catalog is not None)
...@@ -1596,6 +1625,18 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor): ...@@ -1596,6 +1625,18 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
sql_catalog_scriptable_keys.sort() sql_catalog_scriptable_keys.sort()
catalog.sql_catalog_scriptable_keys = tuple(sql_catalog_scriptable_keys) catalog.sql_catalog_scriptable_keys = tuple(sql_catalog_scriptable_keys)
self.failUnless(scriptable_key not in catalog.sql_catalog_scriptable_keys) self.failUnless(scriptable_key not in catalog.sql_catalog_scriptable_keys)
# role keys
sql_catalog_role_keys = list(catalog.sql_catalog_role_keys)
sql_catalog_role_keys.remove(role_key)
sql_catalog_role_keys.sort()
catalog.sql_catalog_role_keys = tuple(sql_catalog_role_keys)
self.failUnless(role_key not in catalog.sql_catalog_role_keys)
# local_role keys
sql_catalog_local_role_keys = list(catalog.sql_catalog_local_role_keys)
sql_catalog_local_role_keys.remove(local_role_key)
sql_catalog_local_role_keys.sort()
catalog.sql_catalog_local_role_keys = tuple(sql_catalog_local_role_keys)
self.failUnless(local_role_key not in catalog.sql_catalog_local_role_keys)
def stepCheckKeysAndTableExists(self, sequence=list, sequence_list=None, **kw): def stepCheckKeysAndTableExists(self, sequence=list, sequence_list=None, **kw):
...@@ -1620,6 +1661,10 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor): ...@@ -1620,6 +1661,10 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
self.failUnless(topic_key is not None) self.failUnless(topic_key is not None)
scriptable_key = sequence.get('scriptable_key', None) scriptable_key = sequence.get('scriptable_key', None)
self.failUnless(scriptable_key is not None) self.failUnless(scriptable_key is not None)
role_key = sequence.get('role_key', None)
self.failUnless(role_key is not None)
local_role_key = sequence.get('local_role_key', None)
self.failUnless(local_role_key is not None)
catalog = self.getCatalogTool().getSQLCatalog() catalog = self.getCatalogTool().getSQLCatalog()
self.failUnless(catalog is not None) self.failUnless(catalog is not None)
...@@ -1641,6 +1686,10 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor): ...@@ -1641,6 +1686,10 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
self.failUnless(topic_key in catalog.sql_catalog_topic_search_keys) self.failUnless(topic_key in catalog.sql_catalog_topic_search_keys)
# scriptable key # scriptable key
self.failUnless(scriptable_key in catalog.sql_catalog_scriptable_keys) self.failUnless(scriptable_key in catalog.sql_catalog_scriptable_keys)
# role key
self.failUnless(role_key in catalog.sql_catalog_role_keys)
# local_role key
self.failUnless(local_role_key in catalog.sql_catalog_local_role_keys)
def stepCheckKeysAndTableRemoved(self, sequence=list, sequence_list=None, **kw): def stepCheckKeysAndTableRemoved(self, sequence=list, sequence_list=None, **kw):
""" """
...@@ -1664,6 +1713,10 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor): ...@@ -1664,6 +1713,10 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
self.failUnless(topic_key is not None) self.failUnless(topic_key is not None)
scriptable_key = sequence.get('scriptable_key', None) scriptable_key = sequence.get('scriptable_key', None)
self.failUnless(scriptable_key is not None) self.failUnless(scriptable_key is not None)
role_key = sequence.get('role_key', None)
self.failUnless(role_key is not None)
local_role_key = sequence.get('local_role_key', None)
self.failUnless(local_role_key is not None)
catalog = self.getCatalogTool().getSQLCatalog() catalog = self.getCatalogTool().getSQLCatalog()
self.failUnless(catalog is not None) self.failUnless(catalog is not None)
...@@ -1685,6 +1738,10 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor): ...@@ -1685,6 +1738,10 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
self.failUnless(topic_key not in catalog.sql_catalog_topic_search_keys) self.failUnless(topic_key not in catalog.sql_catalog_topic_search_keys)
# scriptable key # scriptable key
self.failUnless(scriptable_key not in catalog.sql_catalog_scriptable_keys) self.failUnless(scriptable_key not in catalog.sql_catalog_scriptable_keys)
# role key
self.failUnless(role_key not in catalog.sql_catalog_role_keys)
# local_role key
self.failUnless(local_role_key not in catalog.sql_catalog_local_role_keys)
# Roles # Roles
def stepCreateRole(self, sequence=None, sequence_list=None, **kw): def stepCreateRole(self, sequence=None, sequence_list=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