Mercurial > kallithea
changeset 7284:8e5450cd4686
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.
author | Thomas De Schampheleire <thomas.de_schampheleire@nokia.com> |
---|---|
date | Sun, 20 May 2018 22:51:13 +0200 |
parents | 40fea9b37a32 |
children | 5fc420b5c49c |
files | kallithea/controllers/admin/settings.py kallithea/tests/functional/test_admin_settings.py |
diffstat | 2 files changed, 7 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/controllers/admin/settings.py Sun May 20 22:29:40 2018 +0200 +++ b/kallithea/controllers/admin/settings.py Sun May 20 22:51:13 2018 +0200 @@ -365,10 +365,12 @@ # 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')
--- a/kallithea/tests/functional/test_admin_settings.py Sun May 20 22:29:40 2018 +0200 +++ b/kallithea/tests/functional/test_admin_settings.py Sun May 20 22:51:13 2018 +0200 @@ -49,6 +49,7 @@ 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()))