Changeset - 644b7a16d29c
[Not reviewed]
default
0 2 0
Mads Kiilerich (mads) - 5 years ago 2021-01-11 00:06:52
mads@kiilerich.com
hooks: reserve .kallithea_ hooks namespace for internal use
2 files changed with 3 insertions and 3 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/admin/settings.py
Show inline comments
 
@@ -323,26 +323,26 @@ class SettingsController(base.BaseContro
 
        c.active = 'hooks'
 
        if request.POST:
 
            if c.visual.allow_custom_hooks_settings:
 
                ui_key = request.POST.get('new_hook_ui_key')
 
                ui_value = request.POST.get('new_hook_ui_value')
 

	
 
                hook_id = request.POST.get('hook_id')
 

	
 
                try:
 
                    ui_key = ui_key and ui_key.strip()
 
                    if ui_key in (x.ui_key for x in db.Ui.get_custom_hooks()):
 
                        webutils.flash(_('Hook already exists'), category='error')
 
                    elif ui_key in (x.ui_key for x in db.Ui.get_builtin_hooks()):
 
                        webutils.flash(_('Builtin hooks are read-only. Please use another hook name.'), category='error')
 
                    elif ui_key and '.kallithea_' in ui_key:
 
                        webutils.flash(_('Hook names with ".kallithea_" are reserved for internal use. Please use another hook name.'), category='error')
 
                    elif ui_value and ui_key:
 
                        db.Ui.create_or_update_hook(ui_key, ui_value)
 
                        webutils.flash(_('Added new hook'), category='success')
 
                    elif hook_id:
 
                        db.Ui.delete(hook_id)
 
                        meta.Session().commit()
 

	
 
                    # check for edits
 
                    update = False
 
                    _d = request.POST.dict_of_lists()
 
                    for k, v, ov in zip(_d.get('hook_ui_key', []),
 
                                        _d.get('hook_ui_value_new', []),
kallithea/tests/functional/test_admin_settings.py
Show inline comments
 
@@ -86,25 +86,25 @@ class TestAdminSettingsController(base.T
 
                        params=dict(hook_id=hook_id, _session_csrf_secret_token=self.session_csrf_secret_token()))
 
        response = self.app.get(base.url('admin_settings_hooks'))
 
        response.mustcontain(no=['test_hooks_2'])
 
        response.mustcontain(no=['cd %s2' % base.TESTS_TMP_PATH])
 

	
 
    def test_add_existing_builtin_hook(self):
 
        self.log_user()
 
        response = self.app.post(base.url('admin_settings_hooks'),
 
                                params=dict(new_hook_ui_key='changegroup.kallithea_update',
 
                                            new_hook_ui_value='attempted_new_value',
 
                                            _session_csrf_secret_token=self.session_csrf_secret_token()))
 

	
 
        self.checkSessionFlash(response, 'Builtin hooks are read-only')
 
        self.checkSessionFlash(response, 'reserved for internal use')
 
        response = response.follow()
 
        response.mustcontain('changegroup.kallithea_update')
 

	
 
    def test_index_search(self):
 
        self.log_user()
 
        response = self.app.get(base.url('admin_settings_search'))
 

	
 
    def test_index_system(self):
 
        self.log_user()
 
        response = self.app.get(base.url('admin_settings_system'))
 

	
 
    def test_ga_code_active(self):
0 comments (0 inline, 0 general)