Commit 6742a24d authored by Bartek Górny's avatar Bartek Górny

If we want group, we return all super-groups of the current group; the other...

If we want group, we return all super-groups of the current group; the other script is for using if we want strict membership of the group.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11752 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 2561de86
...@@ -80,6 +80,7 @@ ...@@ -80,6 +80,7 @@
\n \n
# must always return a list of dicts\n # must always return a list of dicts\n
context.log(\'base_category_list\',base_category_list)\n context.log(\'base_category_list\',base_category_list)\n
context.log(\'user\',user_name)\n
category_list = []\n category_list = []\n
\n \n
person_module = context.portal_url.getPortalObject().getDefaultModule(\'Person\')\n person_module = context.portal_url.getPortalObject().getDefaultModule(\'Person\')\n
...@@ -87,7 +88,7 @@ person_module = context.portal_url.getPortalObject().getDefaultModule(\'Person\' ...@@ -87,7 +88,7 @@ person_module = context.portal_url.getPortalObject().getDefaultModule(\'Person\'
# prevent a very strange bug, sometimes without getObject the\n # prevent a very strange bug, sometimes without getObject the\n
# assignment is not found\n # assignment is not found\n
person_object_list = [x.getObject() for x in person_module.searchFolder(portal_type=\'Person\', reference=user_name)]\n person_object_list = [x.getObject() for x in person_module.searchFolder(portal_type=\'Person\', reference=user_name)]\n
\n context.log(len(person_object_list))\n
if len(person_object_list) != 1:\n if len(person_object_list) != 1:\n
if len(person_object_list) > 1:\n if len(person_object_list) > 1:\n
raise ConsistencyError, "Error: There is more than one Person with reference \'%s\'" % user_name\n raise ConsistencyError, "Error: There is more than one Person with reference \'%s\'" % user_name\n
...@@ -99,9 +100,11 @@ if len(person_object_list) != 1:\n ...@@ -99,9 +100,11 @@ if len(person_object_list) != 1:\n
person_object = person_object_list[0]\n person_object = person_object_list[0]\n
\n \n
# We look for valid assignments of this user\n # We look for valid assignments of this user\n
\n
for assignment in person_object.contentValues(filter={\'portal_type\': \'Assignment\'}):\n for assignment in person_object.contentValues(filter={\'portal_type\': \'Assignment\'}):\n
if assignment.getValidationState() == \'open\':\n
category_dict = {}\n category_dict = {}\n
if assignment.getValidationState() == \'open\':\n
try:\n
for base_category in base_category_list:\n for base_category in base_category_list:\n
if base_category==\'source_project\':\n if base_category==\'source_project\':\n
category_value=assignment.getDestinationProject()\n category_value=assignment.getDestinationProject()\n
...@@ -112,6 +115,17 @@ for assignment in person_object.contentValues(filter={\'portal_type\': \'Assignm ...@@ -112,6 +115,17 @@ for assignment in person_object.contentValues(filter={\'portal_type\': \'Assignm
else:\n else:\n
raise RuntimeError, "Error: \'%s\' property is required in order to update person security group" % (base_category)\n raise RuntimeError, "Error: \'%s\' property is required in order to update person security group" % (base_category)\n
category_list.append(category_dict)\n category_list.append(category_dict)\n
# if it is group, we go up the hierarchy (because if you work in group/a/b/c, chances are you \n
# are working in group/a/b, too :)\n
if base_category==\'group\':\n
grouplist=category_value.split(\'/\')\n
for i in range(1,len(grouplist)):\n
cdict=category_dict.copy()\n
cdict[\'group\']=\'/\'.join(grouplist[:-i])\n
category_list.append(cdict)\n
except RuntimeError,e:\n
context.log(str(e))\n
\n
context.log(category_list)\n context.log(category_list)\n
return category_list\n return category_list\n
...@@ -196,6 +210,12 @@ return category_list\n ...@@ -196,6 +210,12 @@ return category_list\n
<string>None</string> <string>None</string>
<string>_write_</string> <string>_write_</string>
<string>RuntimeError</string> <string>RuntimeError</string>
<string>grouplist</string>
<string>range</string>
<string>i</string>
<string>cdict</string>
<string>e</string>
<string>str</string>
</tuple> </tuple>
</value> </value>
</item> </item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>Products.PythonScripts.PythonScript</string>
<string>PythonScript</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Python_magic</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
# the same, but does group only with strict membership\n
# XXX needs refactoring\n
\n
# must always return a list of dicts\n
context.log(\'base_category_list\',base_category_list)\n
context.log(\'user\',user_name)\n
category_list = []\n
\n
person_module = context.portal_url.getPortalObject().getDefaultModule(\'Person\')\n
# It is better to keep getObject(), in this script this\n
# prevent a very strange bug, sometimes without getObject the\n
# assignment is not found\n
person_object_list = [x.getObject() for x in person_module.searchFolder(portal_type=\'Person\', reference=user_name)]\n
context.log(len(person_object_list))\n
if len(person_object_list) != 1:\n
if len(person_object_list) > 1:\n
raise ConsistencyError, "Error: There is more than one Person with reference \'%s\'" % user_name\n
else:\n
# if a person_object was not found in the module, we do nothing more\n
# this happens for example when a manager with no associated person object\n
# creates a person_object for a new user\n
return []\n
person_object = person_object_list[0]\n
\n
# We look for valid assignments of this user\n
\n
for assignment in person_object.contentValues(filter={\'portal_type\': \'Assignment\'}):\n
category_dict = {}\n
if assignment.getValidationState() == \'open\':\n
try:\n
for base_category in base_category_list:\n
if base_category==\'source_project\':\n
category_value=assignment.getDestinationProject()\n
else:\n
category_value = assignment.getProperty(base_category)\n
if category_value not in (None, \'\'):\n
category_dict[base_category] = category_value\n
else:\n
raise RuntimeError, "Error: \'%s\' property is required in order to update person security group" % (base_category)\n
category_list.append(category_dict)\n
\n
except RuntimeError,e:\n
context.log(str(e))\n
\n
context.log(category_list)\n
return category_list\n
]]></string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_filepath</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>base_category_list, user_name, object, portal_type</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>errors</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>func_code</string> </key>
<value>
<object>
<klass>
<global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>4</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>base_category_list</string>
<string>user_name</string>
<string>object</string>
<string>portal_type</string>
<string>_getattr_</string>
<string>context</string>
<string>category_list</string>
<string>person_module</string>
<string>append</string>
<string>$append0</string>
<string>_getiter_</string>
<string>x</string>
<string>person_object_list</string>
<string>len</string>
<string>ConsistencyError</string>
<string>_getitem_</string>
<string>person_object</string>
<string>assignment</string>
<string>category_dict</string>
<string>base_category</string>
<string>category_value</string>
<string>None</string>
<string>_write_</string>
<string>RuntimeError</string>
<string>e</string>
<string>str</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Type_getSecurityCategoryFromAssignmentStrict</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
411 412
\ 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