##// END OF EJS Templates
fix(backend): fixed broken backends function after python3 migration...
fix(backend): fixed broken backends function after python3 migration (grafted from 112c3403e5ce3301bd7e910fb76d49aeaa9d49a4)

File last commit:

r5522:33fc2e7c default
r5524:fb58a2b4 default
Show More
security.py
72 lines | 2.7 KiB | text/x-python | PythonLexer
# Copyright (C) 2010-2024 RhodeCode GmbH
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
import logging
import formencode
from rhodecode import BACKENDS
from rhodecode.apps._base import BaseAppView
from rhodecode.model.meta import Session
from rhodecode.model.settings import SettingsModel
from rhodecode.model.forms import WhitelistedVcsClientsForm
from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
log = logging.getLogger(__name__)
class AdminSecurityView(BaseAppView):
def load_default_context(self):
c = self._get_local_tmpl_context()
return c
@LoginRequired()
@HasPermissionAllDecorator('hg.admin')
def security(self):
c = self.load_default_context()
c.active = 'security'
return self._get_template_context(c)
@LoginRequired()
@HasPermissionAllDecorator('hg.admin')
def vcs_whitelisted_client_versions_edit(self):
_ = self.request.translate
c = self.load_default_context()
render_ctx = {}
settings = SettingsModel()
form = WhitelistedVcsClientsForm(_, )()
if self.request.method == 'POST':
try:
result = form.to_python(self.request.POST)
for k, v in result.items():
if v:
setting = settings.create_or_update_setting(name=f'{k}_allowed_clients', val=v)
Session().add(setting)
Session().commit()
except formencode.Invalid as errors:
render_ctx.update({
'errors': errors.error_dict
})
for key in BACKENDS.keys():
verbose_name = f"initial_{key}"
if existing := settings.get_setting_by_name(name=f'{key}_allowed_clients'):
render_ctx[verbose_name] = existing.app_settings_value
else:
render_ctx[verbose_name] = '*'
return self._get_template_context(c, **render_ctx)