Commit f56b26eb authored by Jérome Perrin's avatar Jérome Perrin

Person_getPrimaryGroup: if multiple groups are defined on open assignments,...

Person_getPrimaryGroup: if multiple groups are defined on open assignments, this script should not try to guess. Also add a proxy role to make sure this code can be used by any users, and use a hack to prevent users from calling the script arbitrarily.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@21068 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 5b73cd2a
...@@ -81,17 +81,28 @@ ...@@ -81,17 +81,28 @@
(to be implemented).\n (to be implemented).\n
"""\n """\n
\n \n
if REQUEST is not None:\n
# This script has proxy roles, so we don\'t allow users to call it directly\n
from AccessControl import getSecurityManager\n
from zExceptions import Unauthorized\n
if not \'Manager\' in getSecurityManager().getUser().getRoles():\n
raise Unauthorized(script)\n
\n
from DateTime import DateTime\n from DateTime import DateTime\n
now = DateTime()\n now = DateTime()\n
\n \n
for assignment in context.contentValues(portal_type=\'Assignment\',\n existing_group_set = dict()\n
checked_permission=\'Access contents information\'):\n for assignment in context.contentValues(portal_type=\'Assignment\'):\n
\n
if assignment.getGroup() \\\n if assignment.getGroup() \\\n
and assignment.getValidationState() == \'open\' \\\n and assignment.getValidationState() == \'open\' \\\n
and ( assignment.getStartDate() is None or\n and ( assignment.getStartDate() is None or\n
assignment.getStartDate() <= now <= assignment.getStopDate()):\n assignment.getStartDate() <= now <= assignment.getStopDate()):\n
return assignment.getGroup()\n existing_group_set[assignment.getGroup()] = 1\n
\n
# If we have multiple groups defined on assignments, this scripts does not\n
# try to guess, and fallback to the default career\'s group\n
if len(existing_group_set.keys()) == 1:\n
return existing_group_set.keys()[0]\n
\n \n
# no group found on open assignments, returns the default group\n # no group found on open assignments, returns the default group\n
# (on a person document this is acquired on the default career\'s subordination)\n # (on a person document this is acquired on the default career\'s subordination)\n
...@@ -120,7 +131,15 @@ return context.getGroup()\n ...@@ -120,7 +131,15 @@ return context.getGroup()\n
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string>REQUEST=None</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item> </item>
<item> <item>
<key> <string>errors</string> </key> <key> <string>errors</string> </key>
...@@ -140,19 +159,30 @@ return context.getGroup()\n ...@@ -140,19 +159,30 @@ return context.getGroup()\n
<dictionary> <dictionary>
<item> <item>
<key> <string>co_argcount</string> </key> <key> <string>co_argcount</string> </key>
<value> <int>0</int> </value> <value> <int>1</int> </value>
</item> </item>
<item> <item>
<key> <string>co_varnames</string> </key> <key> <string>co_varnames</string> </key>
<value> <value>
<tuple> <tuple>
<string>REQUEST</string>
<string>None</string>
<string>AccessControl</string>
<string>getSecurityManager</string>
<string>zExceptions</string>
<string>Unauthorized</string>
<string>_getattr_</string>
<string>script</string>
<string>DateTime</string> <string>DateTime</string>
<string>now</string> <string>now</string>
<string>dict</string>
<string>existing_group_set</string>
<string>_getiter_</string> <string>_getiter_</string>
<string>_getattr_</string>
<string>context</string> <string>context</string>
<string>assignment</string> <string>assignment</string>
<string>None</string> <string>_write_</string>
<string>len</string>
<string>_getitem_</string>
</tuple> </tuple>
</value> </value>
</item> </item>
...@@ -164,7 +194,9 @@ return context.getGroup()\n ...@@ -164,7 +194,9 @@ return context.getGroup()\n
<item> <item>
<key> <string>func_defaults</string> </key> <key> <string>func_defaults</string> </key>
<value> <value>
<none/> <tuple>
<none/>
</tuple>
</value> </value>
</item> </item>
<item> <item>
......
300 303
\ 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