diff --git a/rhodecode/apps/admin/tests/test_admin_permissions.py b/rhodecode/apps/admin/tests/test_admin_permissions.py --- a/rhodecode/apps/admin/tests/test_admin_permissions.py +++ b/rhodecode/apps/admin/tests/test_admin_permissions.py @@ -228,7 +228,7 @@ class TestAdminPermissionsController(Tes self.log_user() # ADD - default_user_id = User.get_default_user().user_id + default_user_id = User.get_default_user_id() self.app.post( route_path('edit_user_ips_add', user_id=default_user_id), params={'new_ip': '0.0.0.0/24', 'csrf_token': self.csrf_token}) @@ -238,7 +238,7 @@ class TestAdminPermissionsController(Tes response.mustcontain('0.0.0.0 - 0.0.0.255') # DELETE - default_user_id = User.get_default_user().user_id + default_user_id = User.get_default_user_id() del_ip_id = UserIpMap.query().filter(UserIpMap.user_id == default_user_id).first().ip_id diff --git a/rhodecode/apps/admin/views/permissions.py b/rhodecode/apps/admin/views/permissions.py --- a/rhodecode/apps/admin/views/permissions.py +++ b/rhodecode/apps/admin/views/permissions.py @@ -142,7 +142,7 @@ class AdminPermissionsView(BaseAppView, h.flash(_('Error occurred during update of permissions'), category='error') - affected_user_ids = [User.get_default_user().user_id] + affected_user_ids = [User.get_default_user_id()] PermissionModel().trigger_permission_flush(affected_user_ids) raise HTTPFound(h.route_path('admin_permissions_application')) @@ -218,7 +218,7 @@ class AdminPermissionsView(BaseAppView, h.flash(_('Error occurred during update of permissions'), category='error') - affected_user_ids = [User.get_default_user().user_id] + affected_user_ids = [User.get_default_user_id()] PermissionModel().trigger_permission_flush(affected_user_ids) raise HTTPFound(h.route_path('admin_permissions_object')) @@ -320,7 +320,7 @@ class AdminPermissionsView(BaseAppView, h.flash(_('Error occurred during update of permissions'), category='error') - affected_user_ids = [User.get_default_user().user_id] + affected_user_ids = [User.get_default_user_id()] PermissionModel().trigger_permission_flush(affected_user_ids) raise HTTPFound(h.route_path('admin_permissions_global')) diff --git a/rhodecode/apps/repository/views/repo_settings_advanced.py b/rhodecode/apps/repository/views/repo_settings_advanced.py --- a/rhodecode/apps/repository/views/repo_settings_advanced.py +++ b/rhodecode/apps/repository/views/repo_settings_advanced.py @@ -65,7 +65,7 @@ class RepoSettingsView(RepoAppView): c = self.load_default_context() c.active = 'advanced' - c.default_user_id = User.get_default_user().user_id + c.default_user_id = User.get_default_user_id() c.in_public_journal = UserFollowing.query() \ .filter(UserFollowing.user_id == c.default_user_id) \ .filter(UserFollowing.follows_repository == self.db_repo).scalar() @@ -220,7 +220,7 @@ class RepoSettingsView(RepoAppView): _ = self.request.translate try: - user_id = User.get_default_user().user_id + user_id = User.get_default_user_id() ScmModel().toggle_following_repo(self.db_repo.repo_id, user_id) h.flash(_('Updated repository visibility in public journal'), category='success') diff --git a/rhodecode/config/environment.py b/rhodecode/config/environment.py --- a/rhodecode/config/environment.py +++ b/rhodecode/config/environment.py @@ -65,9 +65,9 @@ def load_pyramid_environment(global_conf if alias not in settings['vcs.backends']: del rhodecode.BACKENDS[alias] - def sorter(item): - return settings['vcs.backends'].index(item[0]) - rhodecode.BACKENDS = rhodecode.OrderedDict(sorted(rhodecode.BACKENDS.items(), key=sorter)) + _sorted_backend = sorted(rhodecode.BACKENDS.items(), + key=lambda item: settings['vcs.backends'].index(item[0])) + rhodecode.BACKENDS = rhodecode.OrderedDict(_sorted_backend) log.info('Enabled VCS backends: %s', rhodecode.BACKENDS.keys()) @@ -81,6 +81,7 @@ def load_pyramid_environment(global_conf rhodecode.PYRAMID_SETTINGS = settings_merged rhodecode.CONFIG = settings_merged + rhodecode.CONFIG['default_user_id'] = utils.get_default_user_id() if vcs_server_enabled: connect_vcs(vcs_server_uri, utils.get_vcs_server_protocol(settings)) diff --git a/rhodecode/config/utils.py b/rhodecode/config/utils.py --- a/rhodecode/config/utils.py +++ b/rhodecode/config/utils.py @@ -19,7 +19,6 @@ # and proprietary license terms, please see https://rhodecode.com/licenses/ import os -import shlex import platform from rhodecode.model import init_model @@ -91,3 +90,12 @@ def set_instance_id(config): prefix = instance_id.lstrip('*') _platform_id = platform.uname()[1] or 'instance' config['instance_id'] = '%s%s-%s' % (prefix, _platform_id, os.getpid()) + + +def get_default_user_id(): + from rhodecode.model.db import User, Session + user_id = Session()\ + .query(User.user_id)\ + .filter(User.username == User.DEFAULT_USER)\ + .scalar() + return user_id diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -1048,6 +1048,11 @@ class User(Base, BaseModel): Session().refresh(user) return user + @classmethod + def get_default_user_id(cls): + import rhodecode + return rhodecode.CONFIG['default_user_id'] + def _get_default_perms(self, user, suffix=''): from rhodecode.model.permission import PermissionModel return PermissionModel().get_default_perms(user.user_perms, suffix) diff --git a/rhodecode/model/permission.py b/rhodecode/model/permission.py --- a/rhodecode/model/permission.py +++ b/rhodecode/model/permission.py @@ -558,7 +558,7 @@ class PermissionModel(BaseModel): def get_users_with_repo_write(self, db_repo): write_plus = ['repository.write', 'repository.admin'] - default_user_id = User.get_default_user().user_id + default_user_id = User.get_default_user_id() user_write_permissions = collections.OrderedDict() # write+ and DEFAULT user for inheritance diff --git a/rhodecode/model/validators.py b/rhodecode/model/validators.py --- a/rhodecode/model/validators.py +++ b/rhodecode/model/validators.py @@ -791,7 +791,7 @@ def ValidPerms(localizer, type_='repo'): # get updates of permissions # (read the existing radio button states) - default_user_id = User.get_default_user().user_id + default_user_id = User.get_default_user_id() for k, update_value in value.iteritems(): if k.startswith('u_perm_') or k.startswith('g_perm_'): diff --git a/rhodecode/tests/lib/test_auth.py b/rhodecode/tests/lib/test_auth.py --- a/rhodecode/tests/lib/test_auth.py +++ b/rhodecode/tests/lib/test_auth.py @@ -147,7 +147,7 @@ def test_cached_perms_data_repository_pe assert permissions['repositories'][repo.repo_name] == 'repository.admin' # TODO: johbo: Make cleanup in UserUtility smarter, then remove this hack - repo.user_id = User.get_default_user().user_id + repo.user_id = User.get_default_user_id() def test_cached_perms_data_repository_permissions_not_inheriting_defaults( diff --git a/rhodecode/tests/models/test_user_permissions_on_repo_groups.py b/rhodecode/tests/models/test_user_permissions_on_repo_groups.py --- a/rhodecode/tests/models/test_user_permissions_on_repo_groups.py +++ b/rhodecode/tests/models/test_user_permissions_on_repo_groups.py @@ -49,7 +49,7 @@ def permissions_setup_func(group_name='g user_id = test_u1_id # called by the @with_setup decorator also reset the default user stuff permissions_setup_func(group_name, perm, recursive, - user_id=User.get_default_user().user_id) + user_id=User.get_default_user_id()) # TODO: DRY, compare test_user_group:permissions_setup_func repo_group = RepoGroup.get_by_group_name(group_name=group_name) @@ -142,7 +142,7 @@ def test_user_permissions_on_group_with_ # other repos and groups should have this permission now set ! recursive = 'all' group = 'g0' - default_user_id = User.get_default_user().user_id + default_user_id = User.get_default_user_id() permissions_setup_func(group, 'group.write', recursive=recursive, user_id=default_user_id) @@ -221,7 +221,7 @@ def test_user_permissions_on_group_with_ recursive = 'repos' group = 'g0/g0_1' perm = 'group.none' - default_user_id = User.get_default_user().user_id + default_user_id = User.get_default_user_id() # TODO: workaround due to different setup calls, adept to py.test style permissions_setup_func() @@ -281,7 +281,7 @@ def test_user_permissions_on_group_with_ # should remain intact as we use groups only mode ! recursive = 'groups' group = 'g0/g0_1' - default_user_id = User.get_default_user().user_id + default_user_id = User.get_default_user_id() # TODO: workaround due to different setup calls, adept to py.test style permissions_setup_func()