Commit 3bc3edcf authored by Bartek Górny's avatar Bartek Górny

Some cleanup; added base dependency.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@12606 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0eb03bb1
from Products.ERP5Type.Utils import cartesianProduct
def asSecurityGroupIdList(self, category_order=None, **kw):
# category_order : list of base_categories we want to use to generate the group id
# kw : keys should be base categories,
# values should be value of corresponding relative urls (obtained by getBaseCategory())
#
# Example call : self.ERP5TypeSecurity_asGroupId(category_order=('site', 'group', 'function'),
# site='france/lille', group='nexedi', function='accounting/accountant')
# This will generate a string like 'LIL_NXD_ACT' where "LIL", "NXD" and "ACT" are the codification
# of respecively "france/lille", "nexedi" and "accounting/accountant" categories
#
# ERP5Type_asSecurityGroupId can also return a list of users whenever a category points
# to a Person instance. This is useful to implement user based local role assignments
code_list = []
user_list = []
# sort the category list lexicographically
# this prevents us to choose the exact order we want,
# but also prevents some human mistake to break everything by creating site_function instead of function_site
if category_order not in (None, ''):
category_order = list(category_order)
category_order.sort()
else:
category_order = []
code_dict = {}
for base_category in category_order:
code_dict[base_category] = []
category_list = kw[base_category]
if isinstance(category_list, str):
category_list = [category_list]
for category in category_list:
category_path = '%s/%s' % (base_category, category)
category_object = self.portal_categories.getCategoryValue(category_path)
if category_object in (None, ''):
raise RuntimeError, "Category '%s' doesn't exist" % (category_path)
if category_object.getPortalType() == 'Person':
# We define a person here
user_name = category_object.getReference()
if user_name is not None: user_list.append(user_name)
else:
# We define a group item here
try:
category_code = category_object.getCodification()
except AttributeError:
category_code = category_object.getReference()
if category_code not in code_dict[base_category]:
code_dict[base_category].append(category_code)
if base_category=='site':
category_object = category_object.getParentValue()
while category_object.getPortalType()!='Base Category':
# LOG('checking category_object:',0,category_object.getRelativeUrl())
category_code = category_object.getCodification()
if category_code is not None and category_code not in code_dict[base_category]:
code_dict[base_category].append(category_code)
category_object = category_object.getParentValue()
#code_list.append(category_code)
# Return a list of users or a single group
#LOG('asSecurityGroupIdList, user_list',0,user_list)
if user_list: return user_list
# LOG('asSecurityGroupIdList, code_dict',0,code_dict)
def getCombinationList(item_list):
if len(item_list):
result = getCombinationList(item_list[1:])
return [item_list[:1] + x for x in result] + result
return [[]]
code_list_of_list = []
for base_category in category_order:
code_list_of_list.append(code_dict[base_category])
full_code_list = []
for code_list in cartesianProduct(code_list_of_list):
for x in getCombinationList(code_list):
if len(x):
# we have to sort it to match these in object local roles
x.sort()
full_code_list.extend(['_'.join(x) ])
#LOG('asSecurityGroupIdList, result',0,['_'.join(x) for x in getCombinationList(code_list) if len(x)])
#return ['_'.join(x) for x in getCombinationList(code_list) if len(x)]
#LOG('asSecurityGroupIdList', 0, 'return full_code_list = %s' %(full_code_list,))
self.log('full_code_list',full_code_list)
return full_code_list
...@@ -40,14 +40,10 @@ ...@@ -40,14 +40,10 @@
<key> <string>categories</string> </key> <key> <string>categories</string> </key>
<value> <value>
<tuple> <tuple>
<string>function/publication/reviewer</string> <string>function/knowledge</string>
</tuple> </tuple>
</value> </value>
</item> </item>
<item>
<key> <string>codification</string> </key>
<value> <string>REVIEWER</string> </value>
</item>
<item> <item>
<key> <string>description</string> </key> <key> <string>description</string> </key>
<value> <value>
...@@ -56,13 +52,11 @@ ...@@ -56,13 +52,11 @@
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>reviewer</string> </value> <value> <string>knowledge</string> </value>
</item> </item>
<item> <item>
<key> <string>int_index</string> </key> <key> <string>last_id</string> </key>
<value> <value> <string>1</string> </value>
<none/>
</value>
</item> </item>
<item> <item>
<key> <string>portal_type</string> </key> <key> <string>portal_type</string> </key>
...@@ -70,7 +64,7 @@ ...@@ -70,7 +64,7 @@
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
<value> <string>Reviewer</string> </value> <value> <string>Knowledge</string> </value>
</item> </item>
<item> <item>
<key> <string>uid</string> </key> <key> <string>uid</string> </key>
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<pickle> <pickle>
<tuple> <tuple>
<tuple> <tuple>
<string>Products.ERP5.Tool.Category</string> <string>Products.ERP5Type.Document.Category</string>
<string>Category</string> <string>Category</string>
</tuple> </tuple>
<none/> <none/>
...@@ -30,12 +30,6 @@ ...@@ -30,12 +30,6 @@
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value> </value>
</item> </item>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item> <item>
<key> <string>_tree</string> </key> <key> <string>_tree</string> </key>
<value> <value>
...@@ -43,26 +37,30 @@ ...@@ -43,26 +37,30 @@
</value> </value>
</item> </item>
<item> <item>
<key> <string>codification</string> </key> <key> <string>categories</string> </key>
<value> <string>HQ</string> </value> <value>
<tuple>
<string>function/knowledge/contributor</string>
</tuple>
</value>
</item> </item>
<item> <item>
<key> <string>description</string> </key> <key> <string>description</string> </key>
<value> <string></string> </value> <value>
<none/>
</value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>hq</string> </value> <value> <string>contributor</string> </value>
</item> </item>
<item> <item>
<key> <string>int_index</string> </key> <key> <string>portal_type</string> </key>
<value> <value> <string>Category</string> </value>
<none/>
</value>
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
<value> <string>HQ</string> </value> <value> <string>Contributor</string> </value>
</item> </item>
<item> <item>
<key> <string>uid</string> </key> <key> <string>uid</string> </key>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>Products.ERP5Type.Document.Category</string>
<string>Category</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_count</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>_mt_index</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>_tree</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>function/knowledge/manager</string>
<string>function/knowledge/manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>manager</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Category</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Manager</string> </value>
</item>
<item>
<key> <string>uid</string> </key>
<value>
<none/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<tuple>
<tuple>
<string>BTrees.Length</string>
<string>Length</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle> <int>0</int> </pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<tuple>
<tuple>
<string>BTrees.OOBTree</string>
<string>OOBTree</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<none/>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<tuple>
<tuple>
<string>BTrees.OOBTree</string>
<string>OOBTree</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<none/>
</pickle>
</record>
</ZopeData>
erp5_base
\ No newline at end of file
508 510
\ No newline at end of file \ No newline at end of file
asSecurityGroupIdList
searchUtils searchUtils
mailUtils mailUtils
cutFound cutFound
......
portal_categories/function/hq portal_categories/function/knowledge
portal_categories/function/publication portal_categories/function/knowledge/contributor
portal_categories/function/publication/reviewer portal_categories/function/knowledge/manager
\ No newline at end of file \ No newline at end of file
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