Mercurial > kallithea
changeset 7282:d612fd653562
admin: hooks: prevent creation of existing custom hook
Trying to add a hook that already exists does not currently give an error
but does not work.
Detect the situation and report via a flash.
author | Thomas De Schampheleire <thomas.de_schampheleire@nokia.com> |
---|---|
date | Sun, 20 May 2018 22:23:52 +0200 |
parents | cefc3010baaf |
children | 40fea9b37a32 |
files | kallithea/controllers/admin/settings.py kallithea/tests/functional/test_admin_settings.py |
diffstat | 2 files changed, 15 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/controllers/admin/settings.py Sun May 20 22:13:05 2018 +0200 +++ b/kallithea/controllers/admin/settings.py Sun May 20 22:23:52 2018 +0200 @@ -351,7 +351,9 @@ try: ui_key = ui_key and ui_key.strip() - if ui_value and ui_key: + if ui_key in (x.ui_key for x in Ui.get_custom_hooks()): + h.flash(_('Hook already exists'), category='error') + elif ui_value and ui_key: Ui.create_or_update_hook(ui_key, ui_value) h.flash(_('Added new hook'), category='success') elif hook_id:
--- a/kallithea/tests/functional/test_admin_settings.py Sun May 20 22:13:05 2018 +0200 +++ b/kallithea/tests/functional/test_admin_settings.py Sun May 20 22:23:52 2018 +0200 @@ -56,6 +56,18 @@ response.mustcontain('test_hooks_1') response.mustcontain('new_value_of_hook_1') + def test_add_existing_custom_hook(self): + self.log_user() + response = self.app.post(url('admin_settings_hooks'), + params=dict(new_hook_ui_key='test_hooks_1', + new_hook_ui_value='attempted_new_value', + _authentication_token=self.authentication_token())) + + self.checkSessionFlash(response, 'Hook already exists') + response = response.follow() + response.mustcontain('test_hooks_1') + response.mustcontain('new_value_of_hook_1') + def test_create_custom_hook_delete(self): self.log_user() response = self.app.post(url('admin_settings_hooks'),