Commit 4ead2ac6 authored by Ivan Tyagov's avatar Ivan Tyagov

Add script to get Person Roles on document's context.

Refactor notification script so it will send email to all persons who can modify a document not just owner.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@14787 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8e513024
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>Products.ExternalMethod.ExternalMethod</string>
<string>ExternalMethod</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_function</string> </key>
<value> <string>getPersonRoleList</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>DocumentSecurity</string> </value>
</item>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Document_getPersonRoleList</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -71,29 +71,23 @@ ...@@ -71,29 +71,23 @@
<value> <string encoding="cdata"><![CDATA[ <value> <string encoding="cdata"><![CDATA[
"""\n """\n
This function sends a notification mail to users who have checked the\n This function sends a notification mail to person who is allowed to modify\n
corresponding option in their preference and who have a Role in the\n current document.\n
passed list of Roles in the context of the document.\n
"""\n """\n
\n \n
owner_id = \'\'\n persons_to_inform = []\n
user_ids = []\n
roles_to_inform = (\'Owner\', \'Assignor\', \'Author\',)\n
\n \n
# get list of user_ids from local roles\n # find which persons have needed roles so they can be informed\n
# XXX: find persons having good enough roles in this object\n person_list = context.getPortalObject().person_module.contentValues()\n
local_roles = context.showDict()[\'__ac_local_roles__\']\n person_list = filter(lambda x: x.getReference() is not None, person_list)\n
for user_id, groups in local_roles.items():\n for person in person_list:\n
if \'Owner\' in groups:\n local_roles = context.Document_getPersonRoleList(person, context)\n
owner_id = user_id\n # check if person\'s roles in this document\'s context allow him/her to modify it\n
# check if this local role is interested to be informed\n intersect = [k for k in local_roles if k in roles_to_inform]\n
intersect = [k for k in groups if k in roles_to_inform]\n context.debug(intersect )\n
if len(intersect) > 0:\n if len(intersect) > 0:\n
user_ids.append(user_id)\n persons_to_inform.append(person)\n
\n \n
# find person owner of object\n
owners = context.portal_catalog(portal_type = \'Person\', \n
reference = owner_id)\n
# email templates\n # email templates\n
if event in (\'release\',):\n if event in (\'release\',):\n
subject_template = \'[DMS] Document owned by you was released.\'\n subject_template = \'[DMS] Document owned by you was released.\'\n
...@@ -107,7 +101,7 @@ elif event in (\'publish\',):\n ...@@ -107,7 +101,7 @@ elif event in (\'publish\',):\n
click here: %(url)s/view to check it."""\n click here: %(url)s/view to check it."""\n
\n \n
# send email to owner\n # send email to owner\n
for person in owners:\n for person in persons_to_inform:\n
email_subject = subject_template %dict(name = context.getTitle())\n email_subject = subject_template %dict(name = context.getTitle())\n
email_text = email_template % dict(name = context.getTitle(),\n email_text = email_template % dict(name = context.getTitle(),\n
url = context.absolute_url())\n url = context.absolute_url())\n
...@@ -140,7 +134,7 @@ for person in owners:\n ...@@ -140,7 +134,7 @@ for person in owners:\n
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>event=\'publish\'</string> </value> <value> <string>event=\'publish\', roles_to_inform = (\'Owner\', \'Assignor\',)</string> </value>
</item> </item>
<item> <item>
<key> <string>_proxy_roles</string> </key> <key> <string>_proxy_roles</string> </key>
...@@ -168,32 +162,29 @@ for person in owners:\n ...@@ -168,32 +162,29 @@ for person in owners:\n
<dictionary> <dictionary>
<item> <item>
<key> <string>co_argcount</string> </key> <key> <string>co_argcount</string> </key>
<value> <int>1</int> </value> <value> <int>2</int> </value>
</item> </item>
<item> <item>
<key> <string>co_varnames</string> </key> <key> <string>co_varnames</string> </key>
<value> <value>
<tuple> <tuple>
<string>event</string> <string>event</string>
<string>owner_id</string>
<string>user_ids</string>
<string>roles_to_inform</string> <string>roles_to_inform</string>
<string>_getitem_</string> <string>persons_to_inform</string>
<string>_getattr_</string> <string>_getattr_</string>
<string>context</string> <string>context</string>
<string>local_roles</string> <string>person_list</string>
<string>filter</string>
<string>_getiter_</string> <string>_getiter_</string>
<string>user_id</string> <string>person</string>
<string>groups</string> <string>local_roles</string>
<string>append</string> <string>append</string>
<string>$append0</string> <string>$append0</string>
<string>k</string> <string>k</string>
<string>intersect</string> <string>intersect</string>
<string>len</string> <string>len</string>
<string>owners</string>
<string>subject_template</string> <string>subject_template</string>
<string>email_template</string> <string>email_template</string>
<string>person</string>
<string>dict</string> <string>dict</string>
<string>email_subject</string> <string>email_subject</string>
<string>email_text</string> <string>email_text</string>
...@@ -211,6 +202,10 @@ for person in owners:\n ...@@ -211,6 +202,10 @@ for person in owners:\n
<value> <value>
<tuple> <tuple>
<string>publish</string> <string>publish</string>
<tuple>
<string>Owner</string>
<string>Assignor</string>
</tuple>
</tuple> </tuple>
</value> </value>
</item> </item>
......
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