Commit 01310e93 authored by Jérome Perrin's avatar Jérome Perrin

Use "portal_status_level" in redirections

In ERP5JS when redirecting we can use `portal_status_level` to control the appearance of the notification.

This updates the cases when user action could not be performed to redirect with an error level, so that notification appears in orange, not in green (in ERP5JS - in erp5_xhtml_style this has no effect).

accounting, base, trade were updated

See merge request nexedi/erp5!1303
parents b3ad06f2 66499d9e
Pipeline #12037 passed with stage
in 0 seconds
...@@ -22,8 +22,11 @@ portal.portal_selections.setSelectionParamsFor('accounting_create_related_paymen ...@@ -22,8 +22,11 @@ portal.portal_selections.setSelectionParamsFor('accounting_create_related_paymen
if len(object_list) >= 1000: if len(object_list) >= 1000:
return context.Base_redirect( return context.Base_redirect(
form_id, form_id,
keep_items={'portal_status_message': translateString( keep_items={
'Refusing to process more than 1000 objects, check your selection.')}) 'portal_status_message': translateString(
'Refusing to process more than 1000 objects, check your selection.'),
'portal_status_level': 'error',
})
tag = 'payment_creation_%s' % random.randint(0, 1000) tag = 'payment_creation_%s' % random.randint(0, 1000)
activated = 0 activated = 0
...@@ -35,8 +38,10 @@ for obj in object_list: ...@@ -35,8 +38,10 @@ for obj in object_list:
return context.Base_redirect( return context.Base_redirect(
form_id, form_id,
abort_transaction=True, abort_transaction=True,
keep_items={'portal_status_message': translateString( keep_items={
'Payment creation already in progress, abandon.')}) 'portal_status_message': translateString('Payment creation already in progress, abandon.'),
'portal_status_level': 'error',
})
obj.activate(tag=tag).Invoice_createRelatedPaymentTransaction( obj.activate(tag=tag).Invoice_createRelatedPaymentTransaction(
node=node, node=node,
payment_mode=payment_mode, payment_mode=payment_mode,
...@@ -47,8 +52,10 @@ for obj in object_list: ...@@ -47,8 +52,10 @@ for obj in object_list:
if not activated: if not activated:
return context.Base_redirect( return context.Base_redirect(
form_id, form_id,
keep_items={'portal_status_message': translateString( keep_items={
'No invoice in your selection.')}) 'portal_status_message': translateString( 'No invoice in your selection.'),
'portal_status_level': 'error',
})
# activate something on the folder # activate something on the folder
context.activate(after_tag=tag).getTitle() context.activate(after_tag=tag).getTitle()
......
...@@ -13,9 +13,10 @@ else: ...@@ -13,9 +13,10 @@ else:
# XXX prevent to call this on the whole module: # XXX prevent to call this on the whole module:
if len(object_list) >= 1000: if len(object_list) >= 1000:
return context.Base_redirect(form_id, return context.Base_redirect(form_id,
keep_items=dict(portal_status_message= keep_items=dict(
translateString( portal_status_message=translateString('Refusing to process more than 1000 objects, check your selection.'),
'Refusing to process more than 1000 objects, check your selection.'))) portal_status_level='error',
))
tag = 'reversal_creation_%s' % random.randint(0, 1000) tag = 'reversal_creation_%s' % random.randint(0, 1000)
activated = 0 activated = 0
...@@ -36,9 +37,12 @@ for obj in object_list: ...@@ -36,9 +37,12 @@ for obj in object_list:
activated += 1 activated += 1
if not activated: if not activated:
return context.Base_redirect(form_id, return context.Base_redirect(
keep_items=dict(portal_status_message= form_id,
translateString('No valid transaction in your selection.'))) keep_items=dict(
portal_status_message=translateString('No valid transaction in your selection.'),
portal_status_level='error',
))
# activate something on the folder # activate something on the folder
context.activate(after_tag=tag).getTitle() context.activate(after_tag=tag).getTitle()
......
...@@ -18,9 +18,12 @@ for line in line_list: ...@@ -18,9 +18,12 @@ for line in line_list:
# redirect to previous page without doing the conversion # redirect to previous page without doing the conversion
if exchange_rate is None: if exchange_rate is None:
return context.Base_redirect(form_id, return context.Base_redirect(
keep_items=dict( form_id,
portal_status_message=context.Base_translateString('No exchange ratio found.'))) keep_items=dict(
portal_status_message=context.Base_translateString('No exchange ratio found.'),
portal_status_level='error',
))
# update the corresponding price and round it according to the precision of # update the corresponding price and round it according to the precision of
# the converted currency # the converted currency
......
...@@ -20,10 +20,12 @@ for line in line_list: ...@@ -20,10 +20,12 @@ for line in line_list:
start_date=line.getStartDate())) start_date=line.getStartDate()))
# redirect to previous page without doing the conversion # redirect to previous page without doing the conversion
if exchange_rate is None: if exchange_rate is None:
return context.Base_redirect(form_id, return context.Base_redirect(
keep_items=dict( form_id,
portal_status_message=context.Base_translateString('No exchange ratio found.'))) keep_items=dict(
portal_status_message=context.Base_translateString('No exchange ratio found.'),
portal_status_level='error',
))
# update the corresponding price and round it according to the precision of # update the corresponding price and round it according to the precision of
# the converted currency # the converted currency
......
...@@ -37,7 +37,10 @@ if sum(total_payable_price_details.values()) == 0: ...@@ -37,7 +37,10 @@ if sum(total_payable_price_details.values()) == 0:
if not batch_mode: if not batch_mode:
return context.Base_redirect( return context.Base_redirect(
form_id, form_id,
keep_items={'portal_status_message': Base_translateString('Nothing more to pay.')}) keep_items={
'portal_status_message': Base_translateString('Nothing more to pay.'),
'portal_status_level': 'error'
})
return None return None
related_payment = portal.accounting_module.newContent( related_payment = portal.accounting_module.newContent(
......
...@@ -19,4 +19,5 @@ return context.Base_redirect(form_id, ...@@ -19,4 +19,5 @@ return context.Base_redirect(form_id,
keep_items=dict(selection_name=selection_name, keep_items=dict(selection_name=selection_name,
selection_index=selection_index, selection_index=selection_index,
cancel_url=cancel_url, cancel_url=cancel_url,
portal_status_message=translateString("Cancelled.")),) portal_status_message=translateString("Cancelled."),
portal_status_level='error'),)
...@@ -3,7 +3,10 @@ ptype = context.getPortalType() ...@@ -3,7 +3,10 @@ ptype = context.getPortalType()
if not description: if not description:
return context.Base_redirect(dialog_id, return context.Base_redirect(dialog_id,
keep_items = dict(portal_status_message = translateString("Question can not be empty.",), cancel_url = cancel_url)) keep_items = dict(
portal_status_message=translateString("Question can not be empty.",),
portal_status_level='error',
cancel_url=cancel_url))
query = context.Base_newQuery(description=description) query = context.Base_newQuery(description=description)
query_id = query.getId() query_id = query.getId()
......
...@@ -13,7 +13,10 @@ if default_career is None: ...@@ -13,7 +13,10 @@ if default_career is None:
return context.Base_redirect(form_id=form_id, return context.Base_redirect(form_id=form_id,
selection_name=selection_name, selection_name=selection_name,
selection_index=selection_index, selection_index=selection_index,
keep_items={'portal_status_message': message}) keep_items={
'portal_status_message': message,
'portal_status_level': 'error',
})
else: else:
# Copy and paste the default career. # Copy and paste the default career.
# Change IDs # Change IDs
...@@ -25,8 +28,10 @@ else: ...@@ -25,8 +28,10 @@ else:
return context.Base_redirect(form_id=form_id, return context.Base_redirect(form_id=form_id,
selection_name=selection_name, selection_name=selection_name,
selection_index=selection_index, selection_index=selection_index,
keep_items={'portal_status_message': message}) keep_items={
'portal_status_message': message,
'portal_status_level': 'error',
})
new_start_date = default_career.getStopDate() new_start_date = default_career.getStopDate()
cb_data = person.manage_copyObjects(ids=(new_id,)) cb_data = person.manage_copyObjects(ids=(new_id,))
......
...@@ -14,4 +14,4 @@ else: ...@@ -14,4 +14,4 @@ else:
context.portal_caches.clearCache(('erp5_content_short',)) context.portal_caches.clearCache(('erp5_content_short',))
context.logout() context.logout()
return context.Base_redirect() return context.Base_redirect()
return context.Base_redirect(dialog_id, keep_items={'portal_status_message': msg}) return context.Base_redirect(dialog_id, keep_items={'portal_status_message': msg, 'portal_status_level': 'error'})
...@@ -28,16 +28,22 @@ elif line_portal_type in portal.getPortalInternalTypeList() + portal.getPortalIn ...@@ -28,16 +28,22 @@ elif line_portal_type in portal.getPortalInternalTypeList() + portal.getPortalIn
else: else:
from Products.ERP5Type.Message import translateString from Products.ERP5Type.Message import translateString
return context.Base_redirect('view', keep_items=dict( return context.Base_redirect('view', keep_items=dict(
portal_status_message=translateString('Type of document not known to retrieve section.'))) portal_status_message=translateString('Type of document not known to retrieve section.'),
portal_status_level='error',
))
if len(use_list) == 0: if len(use_list) == 0:
from Products.ERP5Type.Message import translateString from Products.ERP5Type.Message import translateString
return context.Base_redirect('view', keep_items=dict( return context.Base_redirect('view', keep_items=dict(
portal_status_message=translateString('Use preference must be defined.'))) portal_status_message=translateString('Use preference must be defined.'),
portal_status_level='error',
))
if section_uid is None: if section_uid is None:
from Products.ERP5Type.Message import translateString from Products.ERP5Type.Message import translateString
return context.Base_redirect('view', keep_items=dict( return context.Base_redirect('view', keep_items=dict(
portal_status_message=translateString('Section must be defined.'))) portal_status_message=translateString('Section must be defined.'),
portal_status_level='error',
))
return context.Base_renderForm('Delivery_viewDeliveryFastInputDialog', *args, **kw) return context.Base_renderForm('Delivery_viewDeliveryFastInputDialog', *args, **kw)
...@@ -64,8 +64,10 @@ while count > 0 and len(trade_condition_list) == 0: ...@@ -64,8 +64,10 @@ while count > 0 and len(trade_condition_list) == 0:
tested_base_category_list=tested_base_category_list[:count], tested_base_category_list=tested_base_category_list[:count],
sort_method=sort_method) sort_method=sort_method)
if len(trade_condition_list ) == 0: keep_items = {}
message = Base_translateString('No trade condition.') if len(trade_condition_list ) == 0 :
keep_items['portal_status_message'] = Base_translateString('No trade condition.')
keep_items['portal_status_level'] = 'error'
else : else :
# if more than one trade condition is found, simply apply the first one # if more than one trade condition is found, simply apply the first one
trade_condition=trade_condition_list[0].getObject() trade_condition=trade_condition_list[0].getObject()
...@@ -75,8 +77,7 @@ else : ...@@ -75,8 +77,7 @@ else :
if hasattr(order, 'getReceivedDate') and order.getReceivedDate() is None: if hasattr(order, 'getReceivedDate') and order.getReceivedDate() is None:
context.setReceivedDate(DateTime()) context.setReceivedDate(DateTime())
message = Base_translateString('Order updated.') keep_items['portal_status_message'] = Base_translateString('Order updated.')
if not batch_mode: if not batch_mode:
return context.Base_redirect(form_id, return context.Base_redirect(form_id, keep_items=keep_items)
keep_items=dict(portal_status_message=message))
...@@ -120,7 +120,10 @@ if error is None: ...@@ -120,7 +120,10 @@ if error is None:
if error is not None: if error is not None:
previous_skin_selection = container.REQUEST.get('previous_skin_selection', None) previous_skin_selection = container.REQUEST.get('previous_skin_selection', None)
context.getPortalObject().changeSkin(previous_skin_selection) context.getPortalObject().changeSkin(previous_skin_selection)
return context.Base_redirect('view', keep_items={'portal_status_message': context.Base_translateString(error, mapping=error_kw)}) return context.Base_redirect('view', keep_items={
'portal_status_message': context.Base_translateString(error, mapping=error_kw),
'portal_status_level': 'error',
})
# Add a line for unit titles # Add a line for unit titles
for source_trade in source_trade_dict: for source_trade in source_trade_dict:
......
...@@ -55,16 +55,18 @@ while count > 0 and len(trade_condition_list) == 0: ...@@ -55,16 +55,18 @@ while count > 0 and len(trade_condition_list) == 0:
tested_base_category_list=tested_base_category_list[:count], tested_base_category_list=tested_base_category_list[:count],
sort_method=sort_method) sort_method=sort_method)
keep_items = {}
if len(trade_condition_list ) == 0 : if len(trade_condition_list ) == 0 :
message = Base_translateString('No trade condition.') keep_items['portal_status_message'] = Base_translateString('No trade condition.')
keep_items['portal_status_level'] = 'error'
else : else :
# if more than one trade condition is found, simply apply the first one # if more than one trade condition is found, simply apply the first one
trade_condition=trade_condition_list[0].getObject() trade_condition=trade_condition_list[0].getObject()
order.Order_applyTradeCondition(trade_condition, force=force) order.Order_applyTradeCondition(trade_condition, force=force)
message = Base_translateString('Order updated.') keep_items['portal_status_message'] = Base_translateString('Order updated.')
if not batch_mode: if not batch_mode:
return context.Base_redirect(form_id, return context.Base_redirect(form_id, keep_items=keep_items)
keep_items=dict(portal_status_message=message))
...@@ -55,8 +55,10 @@ while count > 0 and len(trade_condition_list) == 0: ...@@ -55,8 +55,10 @@ while count > 0 and len(trade_condition_list) == 0:
tested_base_category_list=tested_base_category_list[:count], tested_base_category_list=tested_base_category_list[:count],
sort_method=sort_method) sort_method=sort_method)
if len(trade_condition_list ) == 0: keep_items = {}
message = Base_translateString('No trade condition.') if len(trade_condition_list ) == 0 :
keep_items['portal_status_message'] = Base_translateString('No trade condition.')
keep_items['portal_status_level'] = 'error'
else : else :
# if more than one trade condition is found, simply apply the first one # if more than one trade condition is found, simply apply the first one
trade_condition=trade_condition_list[0].getObject() trade_condition=trade_condition_list[0].getObject()
...@@ -66,8 +68,7 @@ else : ...@@ -66,8 +68,7 @@ else :
if hasattr(order, 'getReceivedDate') and order.getReceivedDate() is None: if hasattr(order, 'getReceivedDate') and order.getReceivedDate() is None:
context.setReceivedDate(DateTime()) context.setReceivedDate(DateTime())
message = Base_translateString('Order updated.') keep_items['portal_status_message'] = Base_translateString('Order updated.')
if not batch_mode: if not batch_mode:
return context.Base_redirect(form_id, return context.Base_redirect(form_id, keep_items=keep_items)
keep_items=dict(portal_status_message=message))
...@@ -34,6 +34,7 @@ import mock ...@@ -34,6 +34,7 @@ import mock
import itertools import itertools
import transaction import transaction
import unittest import unittest
import urlparse
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.utils import createZODBPythonScript from Products.ERP5Type.tests.utils import createZODBPythonScript
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
...@@ -584,7 +585,13 @@ class TestPreferences(UserManagementTestCase): ...@@ -584,7 +585,13 @@ class TestPreferences(UserManagementTestCase):
current_password='bad' + password, current_password='bad' + password,
new_password=new_password, new_password=new_password,
) )
self.assertEqual(result, self.portal.absolute_url()+'/portal_preferences/PreferenceTool_viewChangePasswordDialog?portal_status_message=Current%20password%20is%20wrong.') parsed_url = urlparse.urlparse(result)
self.assertEqual(
parsed_url.path.split('/')[-2:],
['portal_preferences', 'PreferenceTool_viewChangePasswordDialog'])
self.assertEqual(
urlparse.parse_qs(parsed_url.query),
{'portal_status_message': ['Current password is wrong.'], 'portal_status_level': ['error']})
self.login() self.login()
self._assertUserExists(login, password) self._assertUserExists(login, password)
......
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