# HG changeset patch # User Thomas De Schampheleire # Date 2018-05-20 22:51:13 # Node ID 8e5450cd4686944bd33573407be689fe85529782 # Parent 40fea9b37a3254da7ec32ae04044a70cacbf775b admin: hooks: only flash 'Updated hooks' if there are changes Clicking 'Save' on the hook administration page currently always renders the flash message 'Updated hooks' even if nothing was changed. This may be particularly confusing when the action you intended to do got an error, e.g. adding a hook that already exists, adding a builtin hook, ... Instead, compare the old and new value when editing a hook, and only save and create the flash if they are different. For this to be work correctly in test, the old value needs to be passed as well like in the real situation, otherwise the 'zip' operation will return an empty list. diff --git a/kallithea/controllers/admin/settings.py b/kallithea/controllers/admin/settings.py --- a/kallithea/controllers/admin/settings.py +++ b/kallithea/controllers/admin/settings.py @@ -365,10 +365,12 @@ class SettingsController(BaseController) # check for edits update = False _d = request.POST.dict_of_lists() - for k, v in zip(_d.get('hook_ui_key', []), - _d.get('hook_ui_value_new', [])): - Ui.create_or_update_hook(k, v) - update = True + for k, v, ov in zip(_d.get('hook_ui_key', []), + _d.get('hook_ui_value_new', []), + _d.get('hook_ui_value', [])): + if v != ov: + Ui.create_or_update_hook(k, v) + update = True if update: h.flash(_('Updated hooks'), category='success') diff --git a/kallithea/tests/functional/test_admin_settings.py b/kallithea/tests/functional/test_admin_settings.py --- a/kallithea/tests/functional/test_admin_settings.py +++ b/kallithea/tests/functional/test_admin_settings.py @@ -49,6 +49,7 @@ class TestAdminSettingsController(TestCo self.log_user() response = self.app.post(url('admin_settings_hooks'), params=dict(hook_ui_key='test_hooks_1', + hook_ui_value='old_value_of_hook_1', hook_ui_value_new='new_value_of_hook_1', _authentication_token=self.authentication_token()))