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 @@ -351,7 +351,9 @@ class SettingsController(BaseController) 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: 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 @@ -56,6 +56,18 @@ class TestAdminSettingsController(TestCo 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'),