Commit af67738b authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_crm: Limit ticket creations per project

  Under refactoring...
parent 82df59dc
Pipeline #37140 failed with stage
in 0 seconds
portal = context.getPortalObject() portal = context.getPortalObject()
if portal.ERP5Site_isSupportRequestCreationClosed():
# Stop process alarm if there are too many tickets
return
monitor_enabled_category = portal.restrictedTraverse( monitor_enabled_category = portal.restrictedTraverse(
"portal_categories/monitor_scope/enabled", None) "portal_categories/monitor_scope/enabled", None)
......
portal = context.getPortalObject() portal = context.getPortalObject()
if portal.ERP5Site_isSupportRequestCreationClosed():
# Stop verification if there are too much tickets
return
portal.portal_catalog.searchAndActivate( portal.portal_catalog.searchAndActivate(
portal_type='Instance Tree', portal_type='Instance Tree',
validation_state='validated', validation_state='validated',
......
portal = context.getPortalObject() portal = context.getPortalObject()
if portal.ERP5Site_isSupportRequestCreationClosed():
# Stop process alarm if there are too many tickets
return
monitor_enabled_category = portal.restrictedTraverse( monitor_enabled_category = portal.restrictedTraverse(
"portal_categories/monitor_scope/enabled", None) "portal_categories/monitor_scope/enabled", None)
......
from DateTime import DateTime from DateTime import DateTime
portal = context.getPortalObject() portal = context.getPortalObject()
if (context.getMonitorScope() == "disabled") or \ if (context.getMonitorScope() == "disabled"):
portal.ERP5Site_isSupportRequestCreationClosed(): return
project = context.getFollowUpValue()
if project.Project_isSupportRequestCreationClosed():
return return
software_installation_list = portal.portal_catalog( software_installation_list = portal.portal_catalog(
......
from DateTime import DateTime from DateTime import DateTime
portal = context.getPortalObject() portal = context.getPortalObject()
if (context.getMonitorScope() == "disabled") or \ if (context.getMonitorScope() == "disabled"):
portal.ERP5Site_isSupportRequestCreationClosed(): return
project = context.getFollowUpValue()
if project.Project_isSupportRequestCreationClosed():
return return
reference = context.getReference() reference = context.getReference()
...@@ -76,8 +79,6 @@ if not should_notify: ...@@ -76,8 +79,6 @@ if not should_notify:
context.getTitle(), context.getReference(), last_contact) context.getTitle(), context.getReference(), last_contact)
if should_notify: if should_notify:
project = context.getFollowUpValue()
support_request = project.Project_createSupportRequestWithCausality( support_request = project.Project_createSupportRequestWithCausality(
ticket_title, ticket_title,
description, description,
......
...@@ -4,8 +4,8 @@ from erp5.component.module.DateUtils import addToDate ...@@ -4,8 +4,8 @@ from erp5.component.module.DateUtils import addToDate
instance_tree = context instance_tree = context
portal = context.getPortalObject() portal = context.getPortalObject()
if portal.ERP5Site_isSupportRequestCreationClosed(): project = context.getFollowUpValue()
# Stop ticket creation if project.Project_isSupportRequestCreationClosed():
return return
date_check_limit = addToDate(DateTime(), to_add={'hour': -1}) date_check_limit = addToDate(DateTime(), to_add={'hour': -1})
...@@ -49,7 +49,6 @@ for instance in software_instance_list: ...@@ -49,7 +49,6 @@ for instance in software_instance_list:
else: else:
error_message = "No message!" error_message = "No message!"
project = context.getFollowUpValue()
support_request = project.Project_createSupportRequestWithCausality( support_request = project.Project_createSupportRequestWithCausality(
ticket_title, ticket_title,
description, description,
......
from Products.ERP5Type.Cache import CachingMethod from Products.ERP5Type.Cache import CachingMethod
portal = context.getPortalObject() portal = context.getPortalObject()
def isSupportRequestCreationClosed(destination_decision=None): assert context.getPortalType() == 'Project', "Wrong context, please update"
def isSupportRequestCreationClosed(project_uid):
limit = int(portal.portal_preferences.getPreferredSupportRequestCreationLimit(5)) limit = int(portal.portal_preferences.getPreferredSupportRequestCreationLimit(5))
kw = { kw = {
'limit': limit, 'limit': limit,
'portal_type': 'Support Request', 'portal_type': 'Support Request',
'simulation_state': ["validated", "submitted"], 'simulation_state': ["validated", "submitted"],
'follow_up__uid': project_uid,
'resource__uid': portal.service_module.slapos_crm_monitoring.getUid() 'resource__uid': portal.service_module.slapos_crm_monitoring.getUid()
} }
if destination_decision:
kw['destination_decision__uid'] = context.restrictedTraverse(
destination_decision).getUid()
support_request_amount_list = context.portal_catalog(**kw) support_request_amount_list = context.portal_catalog(**kw)
return limit <= len(support_request_amount_list) return limit <= len(support_request_amount_list)
...@@ -20,4 +20,4 @@ def isSupportRequestCreationClosed(destination_decision=None): ...@@ -20,4 +20,4 @@ def isSupportRequestCreationClosed(destination_decision=None):
return CachingMethod(isSupportRequestCreationClosed, return CachingMethod(isSupportRequestCreationClosed,
"isSupportRequestCreationClosed", "isSupportRequestCreationClosed",
cache_factory="erp5_content_short")(destination_decision=destination_decision) cache_factory="erp5_content_short")(project_uid=project_uid)
...@@ -50,11 +50,11 @@ ...@@ -50,11 +50,11 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>destination_decision=None, **kw</string> </value> <value> <string>**kw</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>ERP5Site_isSupportRequestCreationClosed</string> </value> <value> <string>Project_isSupportRequestCreationClosed</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
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