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

Only send notification message if the recipient is a user that can view the task report

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@21691 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 31d5e936
......@@ -68,7 +68,12 @@
<value> <string>if related_simulation_movement_path_list is None:\n
raise RuntimeError, \'related_simulation_movement_path_list is missing. Update ERP5 Product.\'\n
\n
if REQUEST is not None:\n
from zExceptions import Unauthorized\n
raise Unauthorized(script.id)\n
\n
task_report = context\n
portal = task_report.getPortalObject()\n
\n
# First, copy Order properties\n
task_report.PackingList_copyOrderProperties()\n
......@@ -94,9 +99,16 @@ source_person = task_report.getSourceValue(portal_type="Person")\n
destination_decision_person = task_report.getDestinationDecisionValue(portal_type="Person")\n
if destination_decision_person is None:\n
destination_decision_person = task_report.getDestinationValue(portal_type="Person")\n
if source_person is not None and destination_decision_person is not None:\n
message = """\n
A new task has been assigned to you by %(assignor)s.\n
\n
# We send a message only if the requester have an email and the assignee \n
# is an user that can view the task report.\n
if source_person is not None \\\n
and destination_decision_person is not None \\\n
and destination_decision_person.getDefaultEmailText() \\\n
and destination_decision_person.getReference():\n
source_user = portal.portal_membership.getMemberById(source_person.getReference())\n
if source_user is not None and source_user.has_permission(\'View\', task_report):\n
message = """A new task has been assigned to you by %(assignor)s.\n
\n
This task is named: %(title)s\n
\n
......@@ -116,11 +128,10 @@ Please wisit ERP5: %(url)s\n
\'start_date\': task_report.getStartDate().Date(),\n
\'stop_date\': task_report.getStopDate().Date(),\n
}\n
portal = task_report.getPortalObject()\n
portal.portal_notifications.sendMessage(sender=destination_decision_person,\n
recipient=source_person, \n
subject="[ERP5 Task] %s" % task_report.getTitle(), \n
message=message)\n
portal.portal_notifications.sendMessage(sender=destination_decision_person,\n
recipient=source_person, \n
subject="[ERP5 Task] %s" % task_report.getTitle(), \n
message=message)\n
\n
# Then, modify state\n
confirm_tag = \'%s_confirm\' % task_report.getPath()\n
......@@ -156,7 +167,7 @@ task_report.activate(after_path_and_method_id=(related_simulation_movement_path_
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>related_simulation_movement_path_list=None</string> </value>
<value> <string>related_simulation_movement_path_list=None, REQUEST=None</string> </value>
</item>
<item>
<key> <string>errors</string> </key>
......@@ -176,23 +187,28 @@ task_report.activate(after_path_and_method_id=(related_simulation_movement_path_
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>1</int> </value>
<value> <int>2</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>related_simulation_movement_path_list</string>
<string>REQUEST</string>
<string>None</string>
<string>RuntimeError</string>
<string>zExceptions</string>
<string>Unauthorized</string>
<string>_getattr_</string>
<string>script</string>
<string>context</string>
<string>task_report</string>
<string>_getattr_</string>
<string>portal</string>
<string>related_order</string>
<string>source_person</string>
<string>destination_decision_person</string>
<string>source_user</string>
<string>message</string>
<string>portal</string>
<string>confirm_tag</string>
</tuple>
</value>
......@@ -207,6 +223,7 @@ task_report.activate(after_path_and_method_id=(related_simulation_movement_path_
<value>
<tuple>
<none/>
<none/>
</tuple>
</value>
</item>
......
......@@ -66,6 +66,7 @@
<item>
<key> <string>_body</string> </key>
<value> <string>task_report = state_change[\'object\']\n
portal = task_report.getPortalObject()\n
\n
# Notify the requester.\n
source_person = task_report.getSourceValue(portal_type="Person")\n
......@@ -73,21 +74,22 @@ destination_decision_person = task_report.getDestinationDecisionValue(portal_typ
if destination_decision_person is None:\n
destination_decision_person = task_report.getDestinationValue(portal_type="Person")\n
\n
# We send a message only if the requester have an email and is a user in the\n
# system.\n
# We send a message only if the requester have an email and \n
# the assignee is a user that can view the task report.\n
if source_person is not None \\\n
and destination_decision_person is not None \\\n
and destination_decision_person.getDefaultEmailText() \\\n
and destination_decision_person.getReference():\n
message = """\n
source_user = portal.portal_membership.getMemberById(source_person.getReference())\n
if source_user is not None and source_user.has_permission(\'View\', task_report):\n
message = """\n
%s has finished the task report titled with %s.\n
Please look at this URL:\n
%s/%s\n
""" % (source_person.getTitle(), task_report.getTitle(),\n
task_report.ERP5Site_getAbsoluteUrl(), task_report.getRelativeUrl())\n
portal = task_report.getPortalObject()\n
portal.portal_notifications.sendMessage(sender=source_person, recipient=destination_decision_person,\n
subject="Task Report Finished", message=message)\n
portal.portal_notifications.sendMessage(sender=source_person, recipient=destination_decision_person,\n
subject="Task Report Finished", message=message)\n
\n
container.PackingList_updateAppliedRule(state_change)\n
</string> </value>
......@@ -108,6 +110,14 @@ container.PackingList_updateAppliedRule(state_change)\n
<key> <string>_params</string> </key>
<value> <string>state_change</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>
......@@ -136,11 +146,12 @@ container.PackingList_updateAppliedRule(state_change)\n
<string>_getitem_</string>
<string>task_report</string>
<string>_getattr_</string>
<string>portal</string>
<string>source_person</string>
<string>destination_decision_person</string>
<string>None</string>
<string>source_user</string>
<string>message</string>
<string>portal</string>
<string>container</string>
</tuple>
</value>
......
......@@ -68,9 +68,10 @@
<value> <string encoding="cdata"><![CDATA[
task_report = state_change[\'object\']\n
portal = task_report.getPortalObject()\n
\n
# get question\n
history = context.portal_workflow.getInfoFor(ob=task_report,\n
history = portal.portal_workflow.getInfoFor(ob=task_report,\n
name=\'history\',\n
wf_id=\'task_report_workflow\',\n
default=())\n
......@@ -87,12 +88,14 @@ destination_decision_person = task_report.getDestinationDecisionValue(portal_typ
if destination_decision_person is None:\n
destination_decision_person = task_report.getDestinationValue(portal_type="Person")\n
\n
# send notification only if the source have a valid email and is a user in the\n
# system\n
# We send a message only if the requester have an email and the assignee \n
# is an user that can view the task report.\n
if source_person is not None \\\n
and destination_decision_person is not None\\\n
and source_person.getDefaultEmailText() \\\n
and source_person.getReference():\n
source_user = portal.portal_membership.getMemberById(source_person.getReference())\n
if source_user is not None and source_user.has_permission(\'View\', task_report):\n
message = """\n
A question from task has been assigned to you by %(assignor)s.\n
\n
......@@ -118,7 +121,6 @@ Please visit ERP5: %(url)s\n
\'stop_date\': task_report.getStopDate().Date(),\n
\'question\' : question,\n
}\n
portal = task_report.getPortalObject()\n
portal.portal_notifications.sendMessage(sender=destination_decision_person, recipient=source_person,\n
subject="[ERP5 Task] Question to You", message=message)\n
......@@ -141,6 +143,14 @@ Please visit ERP5: %(url)s\n
<key> <string>_params</string> </key>
<value> <string>state_change</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>
......@@ -169,7 +179,7 @@ Please visit ERP5: %(url)s\n
<string>_getitem_</string>
<string>task_report</string>
<string>_getattr_</string>
<string>context</string>
<string>portal</string>
<string>history</string>
<string>append</string>
<string>$append0</string>
......@@ -180,8 +190,8 @@ Please visit ERP5: %(url)s\n
<string>source_person</string>
<string>destination_decision_person</string>
<string>None</string>
<string>source_user</string>
<string>message</string>
<string>portal</string>
</tuple>
</value>
</item>
......
......@@ -66,6 +66,7 @@
<item>
<key> <string>_body</string> </key>
<value> <string>task_report = state_change[\'object\']\n
portal = task_report.getPortalObject()\n
\n
# Notify assignee\n
source_person = task_report.getSourceValue(portal_type="Person")\n
......@@ -74,11 +75,13 @@ if destination_decision_person is None:\n
destination_decision_person = task_report.getDestinationValue(portal_type="Person")\n
\n
# send notification only if the source have a valid email and is a user in the\n
# system\n
# system that can view the task report\n
if source_person is not None \\\n
and destination_decision_person is not None\\\n
and source_person.getDefaultEmailText() \\\n
and source_person.getReference():\n
source_user = portal.portal_membership.getMemberById(source_person.getReference())\n
if source_user is not None and source_user.has_permission(\'View\', task_report):\n
message = """\n
Restarted task has been assigned to you by %(assignor)s.\n
\n
......@@ -100,7 +103,6 @@ Please visit ERP5: %(url)s\n
\'start_date\': task_report.getStartDate().Date(),\n
\'stop_date\': task_report.getStopDate().Date(),\n
}\n
portal = task_report.getPortalObject()\n
portal.portal_notifications.sendMessage(sender=destination_decision_person, recipient=source_person,\n
subject="[ERP5 Task] Restarted Task Assigned to You ", message=message)\n
</string> </value>
......@@ -121,6 +123,14 @@ Please visit ERP5: %(url)s\n
<key> <string>_params</string> </key>
<value> <string>state_change</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>
......@@ -149,11 +159,12 @@ Please visit ERP5: %(url)s\n
<string>_getitem_</string>
<string>task_report</string>
<string>_getattr_</string>
<string>portal</string>
<string>source_person</string>
<string>destination_decision_person</string>
<string>None</string>
<string>source_user</string>
<string>message</string>
<string>portal</string>
</tuple>
</value>
</item>
......
529
\ No newline at end of file
530
\ 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