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
except KeyError:\n
continue\n
\n
associative_list = []\n associative_list = []\n
if same_type(category_list, \'\'):\n if isinstance(category_list, str):\n
category_list = [category_list]\n category_list = [category_list]\n
for category in category_list:\n for category in category_list:\n
if category.endswith(\'*\'):\n if category[-1] == \'*\':\n
category = category[:-1]\n category = category[:-1]\n
is_child_category = 1\n is_child_category = 1\n
else:\n else:\n
is_child_category = 0\n is_child_category = 0\n
category_path = \'%s/%s\' % (base_category, category)\n category_path = \'%s/%s\' % (base_category, category)\n
category_object = portal.portal_categories.getCategoryValue(category_path)\n category_object = getCategoryValue(category_path)\n
if category_object in (None, \'\'):\n if category_object is None:\n
raise "SecurityRoleDefinitionError", "Category \'%s\' doesn\'t exist" % (category_path)\n raise RuntimeError("Security definition error (category %r not found)" % (category_path,))\n
portal_type = category_object.getPortalType()\n portal_type = category_object.getPortalType()\n
if portal_type == \'Person\':\n if portal_type == \'Person\':\n
# We define a person here\n # We define a person here\n
user_name = category_object.getReference()\n user_name = category_object.getReference()\n
if user_name is not None: user_list.append(user_name)\n if user_name is not None:\n
user_list.append(user_name)\n
else:\n else:\n
category_code = (category_object.getProperty(\'codification\') or\n category_code = (category_object.getProperty(\'codification\') or\n
category_object.getProperty(\'reference\') or\n category_object.getProperty(\'reference\') or\n
category_object.getId())\n category_object.getId())\n
if is_child_category: category_code += \'*\'\n if is_child_category:\n
category_code += \'*\'\n
associative_list.append(category_code)\n associative_list.append(category_code)\n
# Prevent making a cartesian product with an empty set\n # Prevent making a cartesian product with an empty set\n
if associative_list:\n if associative_list:\n
list_of_list.append(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