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