Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sebastien Robin
erp5
Commits
b0e0396c
Commit
b0e0396c
authored
Jul 15, 2020
by
Rafael Monnerat
Browse files
Options
Browse Files
Download
Plain Diff
CMFActivity: Allow to disable/enable mail notification
See merge request
nexedi/erp5!1197
parents
2e8c2ad1
a9e8afb3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
124 additions
and
0 deletions
+124
-0
product/CMFActivity/ActivityTool.py
product/CMFActivity/ActivityTool.py
+30
-0
product/CMFActivity/dtml/manageActivitiesAdvanced.dtml
product/CMFActivity/dtml/manageActivitiesAdvanced.dtml
+22
-0
product/CMFActivity/tests/testCMFActivity.py
product/CMFActivity/tests/testCMFActivity.py
+72
-0
No files found.
product/CMFActivity/ActivityTool.py
View file @
b0e0396c
...
@@ -372,6 +372,9 @@ class Message(BaseMessage):
...
@@ -372,6 +372,9 @@ class Message(BaseMessage):
def
notifyUser
(
self
,
activity_tool
,
retry
=
False
):
def
notifyUser
(
self
,
activity_tool
,
retry
=
False
):
"""Notify the user that the activity failed."""
"""Notify the user that the activity failed."""
if
not
activity_tool
.
activity_failure_mail_notification
:
return
portal
=
activity_tool
.
getPortalObject
()
portal
=
activity_tool
.
getPortalObject
()
user_email
=
portal
.
getProperty
(
'email_to_address'
,
user_email
=
portal
.
getProperty
(
'email_to_address'
,
portal
.
getProperty
(
'email_from_address'
))
portal
.
getProperty
(
'email_from_address'
))
...
@@ -662,6 +665,7 @@ class ActivityTool (BaseTool):
...
@@ -662,6 +665,7 @@ class ActivityTool (BaseTool):
activity_creation_trace
=
False
activity_creation_trace
=
False
activity_tracking
=
False
activity_tracking
=
False
activity_timing_log
=
False
activity_timing_log
=
False
activity_failure_mail_notification
=
True
cancel_and_invoke_links_hidden
=
False
cancel_and_invoke_links_hidden
=
False
# Filter content (ZMI))
# Filter content (ZMI))
...
@@ -781,6 +785,32 @@ class ActivityTool (BaseTool):
...
@@ -781,6 +785,32 @@ class ActivityTool (BaseTool):
url
+=
urllib
.
quote
(
'Tracking log disabled'
)
url
+=
urllib
.
quote
(
'Tracking log disabled'
)
RESPONSE
.
redirect
(
url
)
RESPONSE
.
redirect
(
url
)
security
.
declareProtected
(
Permissions
.
manage_properties
,
'isActivityMailNotificationEnabled'
)
def
isActivityMailNotificationEnabled
(
self
):
return
self
.
activity_failure_mail_notification
security
.
declareProtected
(
Permissions
.
manage_properties
,
'manage_enableMailNotification'
)
def
manage_enableMailNotification
(
self
,
REQUEST
=
None
,
RESPONSE
=
None
):
"""
Enable mail notification when activity fails.
"""
self
.
activity_failure_mail_notification
=
True
if
RESPONSE
is
not
None
:
url
=
'%s/manageActivitiesAdvanced?manage_tabs_message='
%
self
.
absolute_url
()
url
+=
urllib
.
quote
(
'Mail notification enabled'
)
RESPONSE
.
redirect
(
url
)
security
.
declareProtected
(
Permissions
.
manage_properties
,
'manage_disableMailNotification'
)
def
manage_disableMailNotification
(
self
,
REQUEST
=
None
,
RESPONSE
=
None
):
"""
Disable mail notification when activity fails.
"""
self
.
activity_failure_mail_notification
=
False
if
RESPONSE
is
not
None
:
url
=
'%s/manageActivitiesAdvanced?manage_tabs_message='
%
self
.
absolute_url
()
url
+=
urllib
.
quote
(
'Mail notification disabled'
)
RESPONSE
.
redirect
(
url
)
security
.
declareProtected
(
Permissions
.
manage_properties
,
'isActivityTimingLoggingEnabled'
)
security
.
declareProtected
(
Permissions
.
manage_properties
,
'isActivityTimingLoggingEnabled'
)
def
isActivityTimingLoggingEnabled
(
self
):
def
isActivityTimingLoggingEnabled
(
self
):
return
self
.
activity_timing_log
return
self
.
activity_timing_log
...
...
product/CMFActivity/dtml/manageActivitiesAdvanced.dtml
View file @
b0e0396c
...
@@ -65,6 +65,28 @@
...
@@ -65,6 +65,28 @@
Those traces are logged and mailed when an activity fails (as part of regular activity failure mails).</p>
Those traces are logged and mailed when an activity fails (as part of regular activity failure mails).</p>
</td>
</td>
</tr>
</tr>
<tr class="section-bar">
<td colspan="3" align="left">
<div class="form-label">
Notification options
</div>
</td>
</tr>
<tr>
<td align="left" valign="top">
Mail Notification
</td>
<td>
<dtml-if isActivityMailNotificationEnabled>
<input class="form-element" type="submit" name="manage_disableMailNotification:method" value=" Disable ">
<dtml-else>
<input class="form-element" type="submit" name="manage_enableMailNotification:method" value=" Enable ">
</dtml-if>
</td>
<td>
<p class="form-help">Notify by mail whenever an activity fails.</p>
</td>
</tr>
</table>
</table>
</form>
</form>
<table width="100%" cellspacing="0" cellpadding="2" border="0">
<table width="100%" cellspacing="0" cellpadding="2" border="0">
...
...
product/CMFActivity/tests/testCMFActivity.py
View file @
b0e0396c
...
@@ -1132,6 +1132,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
...
@@ -1132,6 +1132,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
def
failingMethod
(
self
):
raise
ValueError
(
'This method always fails'
)
def
failingMethod
(
self
):
raise
ValueError
(
'This method always fails'
)
Organisation
.
failingMethod
=
failingMethod
Organisation
.
failingMethod
=
failingMethod
try
:
try
:
portal_activities
.
activity_failure_mail_notification
=
True
# MESSAGE_NOT_EXECUTED
# MESSAGE_NOT_EXECUTED
obj
.
activate
(
activity
=
activity
).
failingMethod
()
obj
.
activate
(
activity
=
activity
).
failingMethod
()
self
.
commit
()
self
.
commit
()
...
@@ -1154,6 +1155,41 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
...
@@ -1154,6 +1155,41 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
self
.
assertEqual
(
countMessage
(
path
=
obj_path
),
0
)
self
.
assertEqual
(
countMessage
(
path
=
obj_path
),
0
)
self
.
assertFalse
(
message_list
)
self
.
assertFalse
(
message_list
)
finally
:
finally
:
self
.
portal
.
portal_activities
.
activity_failure_mail_notification
=
True
del
Organisation
.
failingMethod
@
for_each_activity
def
testTryUserNotificationDisabledOnActivityFailure
(
self
,
activity
):
message_list
=
self
.
portal
.
MailHost
.
_message_list
del
message_list
[:]
portal_activities
=
self
.
portal
.
portal_activities
countMessage
=
portal_activities
.
countMessage
obj
=
self
.
portal
.
organisation_module
.
newContent
(
portal_type
=
'Organisation'
)
self
.
tic
()
def
failingMethod
(
self
):
raise
ValueError
(
'This method always fails'
)
Organisation
.
failingMethod
=
failingMethod
try
:
portal_activities
.
activity_failure_mail_notification
=
False
# MESSAGE_NOT_EXECUTED
obj
.
activate
(
activity
=
activity
).
failingMethod
()
self
.
commit
()
self
.
assertFalse
(
message_list
)
self
.
flushAllActivities
(
silent
=
1
,
loop_size
=
100
)
# Check there is a traceback in the email notification
self
.
assertFalse
(
message_list
)
portal_activities
.
manageClearActivities
()
# MESSAGE_NOT_EXECUTABLE
obj_path
=
obj
.
getPath
()
obj
.
activate
(
activity
=
activity
).
failingMethod
()
self
.
commit
()
obj
.
getParentValue
().
_delObject
(
obj
.
getId
())
self
.
commit
()
self
.
assertGreater
(
countMessage
(
path
=
obj_path
),
0
)
self
.
tic
()
self
.
assertEqual
(
countMessage
(
path
=
obj_path
),
0
)
self
.
assertFalse
(
message_list
)
finally
:
portal_activities
.
activity_failure_mail_notification
=
True
del
Organisation
.
failingMethod
del
Organisation
.
failingMethod
def
test_93_tryUserNotificationRaise
(
self
):
def
test_93_tryUserNotificationRaise
(
self
):
...
@@ -1996,6 +2032,40 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
...
@@ -1996,6 +2032,40 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
del
Organisation
.
failingMethod
del
Organisation
.
failingMethod
self
.
_ignore_log_errors
()
self
.
_ignore_log_errors
()
@
for_each_activity
def
testNotificationFailureIsNotSavedOnEventLogWhenMailNotificationIsDisabled
(
self
,
activity
):
obj
=
self
.
portal
.
organisation_module
.
newContent
(
portal_type
=
'Organisation'
)
self
.
tic
()
original_notifyUser
=
Message
.
notifyUser
.
im_func
def
failSendingEmail
(
self
,
*
args
,
**
kw
):
raise
MailHostError
(
'Mail is not sent'
)
activity_unit_test_error
=
Exception
()
def
failingMethod
(
self
):
raise
activity_unit_test_error
try
:
self
.
portal
.
portal_activities
.
activity_failure_mail_notification
=
False
Message
.
notifyUser
=
failSendingEmail
Organisation
.
failingMethod
=
failingMethod
self
.
_catch_log_errors
()
obj
.
activate
(
activity
=
activity
,
priority
=
6
).
failingMethod
()
self
.
commit
()
self
.
flushAllActivities
(
silent
=
1
,
loop_size
=
100
)
message
,
=
self
.
getMessageList
(
activity
)
self
.
commit
()
for
log_record
in
self
.
logged
:
if
log_record
.
name
==
'ActivityTool'
and
log_record
.
levelname
==
'WARNING'
:
type
,
value
,
trace
=
log_record
.
exc_info
self
.
commit
()
self
.
assertIs
(
activity_unit_test_error
,
value
)
self
.
deleteMessageList
(
activity
,
[
message
])
finally
:
self
.
portal
.
portal_activities
.
activity_failure_mail_notification
=
True
Message
.
notifyUser
=
original_notifyUser
del
Organisation
.
failingMethod
self
.
_ignore_log_errors
()
@
for_each_activity
@
for_each_activity
def
testTryUserMessageContainingNoTracebackIsStillSent
(
self
,
activity
):
def
testTryUserMessageContainingNoTracebackIsStillSent
(
self
,
activity
):
# With Message.__call__
# With Message.__call__
...
@@ -2332,9 +2402,11 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
...
@@ -2332,9 +2402,11 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
message_list
=
self
.
portal
.
MailHost
.
_message_list
message_list
=
self
.
portal
.
MailHost
.
_message_list
del
message_list
[:]
del
message_list
[:]
activity_tool
=
self
.
portal
.
portal_activities
activity_tool
=
self
.
portal
.
portal_activities
kw
=
{}
kw
=
{}
self
.
_catch_log_errors
(
subsystem
=
'CMFActivity'
)
self
.
_catch_log_errors
(
subsystem
=
'CMFActivity'
)
try
:
try
:
activity_tool
.
activity_failure_mail_notification
=
True
for
kw
[
'activity'
]
in
ActivityTool
.
activity_dict
:
for
kw
[
'activity'
]
in
ActivityTool
.
activity_dict
:
for
kw
[
'group_method_id'
]
in
''
,
None
:
for
kw
[
'group_method_id'
]
in
''
,
None
:
obj
=
activity_tool
.
newActiveProcess
()
obj
=
activity_tool
.
newActiveProcess
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment