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