Commit 7917e8a8 authored by Yoshinori Okuji's avatar Yoshinori Okuji

2009-12-05 yo

* Stop raising a string in ERP5Type_asSecurityGroupId.
* Optimize ERP5Type_asSecurityGroupId a little.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@31089 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f3064cd1
...@@ -89,6 +89,7 @@ to a Person instance. This is useful to implement user based local role assignme ...@@ -89,6 +89,7 @@ to a Person instance. This is useful to implement user based local role assignme
instead of abstract security based local roles.\n instead of abstract security based local roles.\n
"""\n """\n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
getCategoryValue = portal.portal_categories.getCategoryValue\n
\n \n
# sort the category list lexicographically\n # sort the category list lexicographically\n
# this prevents us to choose the exact order we want,\n # this prevents us to choose the exact order we want,\n
...@@ -105,38 +106,44 @@ list_of_list = []\n ...@@ -105,38 +106,44 @@ list_of_list = []\n
user_list = []\n user_list = []\n
for base_category in category_order:\n for base_category in category_order:\n
# It is acceptable for a category not to be defined\n # It is acceptable for a category not to be defined\n
if kw.has_key(base_category):\n try:\n
category_list = kw[base_category]\n category_list = kw[base_category]\n
associative_list = []\n except KeyError:\n
if same_type(category_list, \'\'):\n continue\n
category_list = [category_list]\n \n
for category in category_list:\n associative_list = []\n
if category.endswith(\'*\'):\n if isinstance(category_list, str):\n
category = category[:-1]\n category_list = [category_list]\n
is_child_category = 1\n for category in category_list:\n
else:\n if category[-1] == \'*\':\n
is_child_category = 0\n category = category[:-1]\n
category_path = \'%s/%s\' % (base_category, category)\n is_child_category = 1\n
category_object = portal.portal_categories.getCategoryValue(category_path)\n else:\n
if category_object in (None, \'\'):\n is_child_category = 0\n
raise "SecurityRoleDefinitionError", "Category \'%s\' doesn\'t exist" % (category_path)\n category_path = \'%s/%s\' % (base_category, category)\n
portal_type = category_object.getPortalType()\n category_object = getCategoryValue(category_path)\n
if portal_type == \'Person\':\n if category_object is None:\n
# We define a person here\n raise RuntimeError("Security definition error (category %r not found)" % (category_path,))\n
user_name = category_object.getReference()\n portal_type = category_object.getPortalType()\n
if user_name is not None: user_list.append(user_name)\n if portal_type == \'Person\':\n
else:\n # We define a person here\n
category_code = (category_object.getProperty(\'codification\') or\n user_name = category_object.getReference()\n
category_object.getProperty(\'reference\') or\n if user_name is not None:\n
category_object.getId())\n user_list.append(user_name)\n
if is_child_category: category_code += \'*\'\n else:\n
associative_list.append(category_code)\n category_code = (category_object.getProperty(\'codification\') or\n
# Prevent making a cartesian product with an empty set\n category_object.getProperty(\'reference\') or\n
if associative_list:\n category_object.getId())\n
list_of_list.append(associative_list)\n if is_child_category:\n
category_code += \'*\'\n
associative_list.append(category_code)\n
# Prevent making a cartesian product with an empty set\n
if associative_list:\n
list_of_list.append(associative_list)\n
\n \n
# Return a list of users if any was defined\n # Return a list of users if any was defined\n
if user_list: return user_list\n if user_list:\n
return user_list\n
\n \n
# Compute the cartesian product and return the codes\n # Compute the cartesian product and return the codes\n
# return filter(lambda x: x, map(lambda x: \'_\'.join(x), cartesianProduct(list_of_list)))\n # return filter(lambda x: x, map(lambda x: \'_\'.join(x), cartesianProduct(list_of_list)))\n
...@@ -182,6 +189,7 @@ return [\'_\'.join(x) for x in cartesianProduct(list_of_list) if x]\n ...@@ -182,6 +189,7 @@ return [\'_\'.join(x) for x in cartesianProduct(list_of_list) if x]\n
<string>_getattr_</string> <string>_getattr_</string>
<string>context</string> <string>context</string>
<string>portal</string> <string>portal</string>
<string>getCategoryValue</string>
<string>None</string> <string>None</string>
<string>list</string> <string>list</string>
<string>Products.ERP5Type.Utils</string> <string>Products.ERP5Type.Utils</string>
...@@ -192,12 +200,15 @@ return [\'_\'.join(x) for x in cartesianProduct(list_of_list) if x]\n ...@@ -192,12 +200,15 @@ return [\'_\'.join(x) for x in cartesianProduct(list_of_list) if x]\n
<string>base_category</string> <string>base_category</string>
<string>_getitem_</string> <string>_getitem_</string>
<string>category_list</string> <string>category_list</string>
<string>KeyError</string>
<string>associative_list</string> <string>associative_list</string>
<string>same_type</string> <string>isinstance</string>
<string>str</string>
<string>category</string> <string>category</string>
<string>is_child_category</string> <string>is_child_category</string>
<string>category_path</string> <string>category_path</string>
<string>category_object</string> <string>category_object</string>
<string>RuntimeError</string>
<string>portal_type</string> <string>portal_type</string>
<string>user_name</string> <string>user_name</string>
<string>category_code</string> <string>category_code</string>
......
1394 1395
\ 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