Commit d7829bda authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_administration: add alarm to check site modification

parent 3770c698
Pipeline #39005 failed with stage
in 0 seconds
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Alarm" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>active_sense_method_id</string> </key>
<value> <string>Alarm_checkSiteDailyModification</string> </value>
</item>
<item>
<key> <string>alarm_notification_mode</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>automatic_solve</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>check_site_daily_modification</string> </value>
</item>
<item>
<key> <string>periodicity_hour</string> </key>
<value>
<tuple>
<int>0</int>
</tuple>
</value>
</item>
<item>
<key> <string>periodicity_minute</string> </key>
<value>
<tuple>
<int>1</int>
</tuple>
</value>
</item>
<item>
<key> <string>periodicity_month</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_month_day</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_start_date</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="DateTime" module="DateTime.DateTime"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<tuple>
<float>1603152000.0</float>
<string>GMT</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>periodicity_week</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Alarm</string> </value>
</item>
<item>
<key> <string>report_method_id</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Check Site Daily Modification</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
active_process = context.newActiveProcess().getRelativeUrl()
context.activate(tag=tag).Base_checkSiteDailyModification(active_process=active_process)
context.activate(after_tag=tag).getId()
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>tag, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Alarm_checkSiteDailyModification</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from DateTime import DateTime
from Products.CMFActivity.ActiveResult import ActiveResult
portal = context.getPortalObject()
if not check_date:
check_date = DateTime().earliestTime() - 1
active_process = context.restrictedTraverse(active_process)
for sub_path, sub_obj in portal.portal_skins.ZopeFind(portal.portal_skins, search_sub=1):
modified_date = DateTime(container.last_modified(sub_obj))
if modified_date >= check_date:
active_process.postResult(ActiveResult(
severity=100,
detail='%s is modified' % sub_path))
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>active_process, check_date = None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_checkSiteDailyModification</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
import unittest import unittest
import time import time
from Products.ERP5.tests.testInventoryAPI import InventoryAPITestCase from Products.ERP5.tests.testInventoryAPI import InventoryAPITestCase
from DateTime import DateTime
class TestERP5Administration(InventoryAPITestCase): class TestERP5Administration(InventoryAPITestCase):
"""Test for erp5_administration business template. """Test for erp5_administration business template.
...@@ -231,6 +232,32 @@ component_error() ...@@ -231,6 +232,32 @@ component_error()
location_and_message_list) location_and_message_list)
def test_check_site_modification(self):
# remove second, obj's modification in erp5 don't have seconds
check_date = DateTime(DateTime().strftime('%Y-%m-%d %H:%M'))
active_process = self.portal.portal_activities.newActiveProcess()
self.portal.Base_checkSiteDailyModification(
active_process=active_process.getRelativeUrl(),
check_date = check_date
)
self.assertEquals(len(active_process.ActiveProcess_getResultList()), 0)
self.portal.portal_skins.erp5_administration.Base_checkSiteDailyModification.ZPythonScript_setTitle('%s' % check_date)
self.portal.portal_skins.erp5_administration.Base_checkSiteDailyModification.ZPythonScript_setTitle('')
self.portal.portal_skins.erp5_administration.BusinessTemplate_viewCheckPythonCodeDialog.manage_addProduct['Formulator'].manage_addField('my_title', 'Title', 'StringField')
self.portal.portal_skins.erp5_administration.BusinessTemplate_viewCheckPythonCodeDialog.manage_delObjects('my_title')
self.tic()
self.portal.Base_checkSiteDailyModification(
active_process=active_process.getRelativeUrl(),
check_date = check_date
)
result_list = sorted([x.detail for x in active_process.getResultList()])
expected_result_list = [
'erp5_administration/Base_checkSiteDailyModification is modified',
'erp5_administration/BusinessTemplate_viewCheckPythonCodeDialog is modified'
]
self.assertEquals(result_list, expected_result_list, result_list)
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestERP5Administration)) suite.addTest(unittest.makeSuite(TestERP5Administration))
......
...@@ -4,5 +4,6 @@ portal_alarms/check_conversion_tool_availability ...@@ -4,5 +4,6 @@ portal_alarms/check_conversion_tool_availability
portal_alarms/check_folder_handler portal_alarms/check_folder_handler
portal_alarms/check_item_tracking portal_alarms/check_item_tracking
portal_alarms/check_localizer portal_alarms/check_localizer
portal_alarms/check_site_daily_modification
portal_alarms/check_skin_cache portal_alarms/check_skin_cache
portal_alarms/check_stock portal_alarms/check_stock
\ 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