Commit fd41318b authored by Romain Courteaud's avatar Romain Courteaud

slapos_subscription_request: detect unexpected changes

parent b1725375
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
subscription_change_request = context subscription_change_request = context
assert subscription_change_request.getPortalType() == 'Subscription Change Request'
assert subscription_change_request.getSimulationState() == 'submitted'
def invalidate(document, comment): def invalidate(document, comment):
context.validate() context.validate()
...@@ -9,4 +15,41 @@ open_sale_order = subscription_change_request.getCausalityValue(portal_type='Ope ...@@ -9,4 +15,41 @@ open_sale_order = subscription_change_request.getCausalityValue(portal_type='Ope
if (open_sale_order is None) or (open_sale_order.getValidationState() != 'validated'): if (open_sale_order is None) or (open_sale_order.getValidationState() != 'validated'):
return invalidate(subscription_change_request, 'No Open Sale Order to update') return invalidate(subscription_change_request, 'No Open Sale Order to update')
return invalidate(subscription_change_request, 'Unknowned requested changes') # Search the line/cell
open_order_movement = None
open_order_movement_list = open_sale_order.contentValues(portal_type='Open Sale Order Line')
if len(open_order_movement_list) == 1:
open_order_movement = open_order_movement_list[0]
open_order_movement_list = open_order_movement.contentValues(portal_type='Open Sale Order Cell')
if 1 < len(open_order_movement_list):
open_order_movement = None
elif 1 == len(open_order_movement_list):
open_order_movement = open_order_movement_list[0]
if open_order_movement is None:
return invalidate(subscription_change_request, 'Can not find the open order movement')
identical_order_base_category_list = [
'specialise',
'destination',
'destination_section',
'destination_decisition',
'destination_project',
'source',
'source_section',
'source_project',
'price_currency',
'resource',
'variation_category_list',
'quantity_unit',
'aggregate',
'quantity',
'price'
]
for identical_order_base_category in identical_order_base_category_list:
if open_order_movement.getProperty(identical_order_base_category) != subscription_change_request.getProperty(identical_order_base_category):
return invalidate(subscription_change_request, 'Unhandled requested changes on: %s' % identical_order_base_category)
return invalidate(subscription_change_request, 'Unknown requested changes')
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string>REQUEST=None</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
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