Changeset - 8e5450cd4686
[Not reviewed]
default
0 2 0
Thomas De Schampheleire - 8 years ago 2018-05-20 22:51:13
thomas.de_schampheleire@nokia.com
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.
2 files changed with 7 insertions and 4 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/admin/settings.py
Show inline comments
 
@@ -362,16 +362,18 @@ class SettingsController(BaseController)
 
                        Ui.delete(hook_id)
 
                        Session().commit()
 

	
 
                    # 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')
 
                    Session().commit()
 
                except Exception:
 
                    log.error(traceback.format_exc())
kallithea/tests/functional/test_admin_settings.py
Show inline comments
 
@@ -46,12 +46,13 @@ class TestAdminSettingsController(TestCo
 
        response.mustcontain('cd %s' % TESTS_TMP_PATH)
 

	
 
    def test_edit_custom_hook(self):
 
        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()))
 

	
 
        response = response.follow()
 
        response.mustcontain('test_hooks_1')
 
        response.mustcontain('new_value_of_hook_1')
0 comments (0 inline, 0 general)