##// END OF EJS Templates
app: use simpler way to extract default_user_id, this will be now registered at server...
marcink -
r4332:b6d13602 default
parent child Browse files
Show More
@@ -228,7 +228,7 b' class TestAdminPermissionsController(Tes'
228 self.log_user()
228 self.log_user()
229
229
230 # ADD
230 # ADD
231 default_user_id = User.get_default_user().user_id
231 default_user_id = User.get_default_user_id()
232 self.app.post(
232 self.app.post(
233 route_path('edit_user_ips_add', user_id=default_user_id),
233 route_path('edit_user_ips_add', user_id=default_user_id),
234 params={'new_ip': '0.0.0.0/24', 'csrf_token': self.csrf_token})
234 params={'new_ip': '0.0.0.0/24', 'csrf_token': self.csrf_token})
@@ -238,7 +238,7 b' class TestAdminPermissionsController(Tes'
238 response.mustcontain('0.0.0.0 - 0.0.0.255')
238 response.mustcontain('0.0.0.0 - 0.0.0.255')
239
239
240 # DELETE
240 # DELETE
241 default_user_id = User.get_default_user().user_id
241 default_user_id = User.get_default_user_id()
242 del_ip_id = UserIpMap.query().filter(UserIpMap.user_id ==
242 del_ip_id = UserIpMap.query().filter(UserIpMap.user_id ==
243 default_user_id).first().ip_id
243 default_user_id).first().ip_id
244
244
@@ -142,7 +142,7 b' class AdminPermissionsView(BaseAppView, '
142 h.flash(_('Error occurred during update of permissions'),
142 h.flash(_('Error occurred during update of permissions'),
143 category='error')
143 category='error')
144
144
145 affected_user_ids = [User.get_default_user().user_id]
145 affected_user_ids = [User.get_default_user_id()]
146 PermissionModel().trigger_permission_flush(affected_user_ids)
146 PermissionModel().trigger_permission_flush(affected_user_ids)
147
147
148 raise HTTPFound(h.route_path('admin_permissions_application'))
148 raise HTTPFound(h.route_path('admin_permissions_application'))
@@ -218,7 +218,7 b' class AdminPermissionsView(BaseAppView, '
218 h.flash(_('Error occurred during update of permissions'),
218 h.flash(_('Error occurred during update of permissions'),
219 category='error')
219 category='error')
220
220
221 affected_user_ids = [User.get_default_user().user_id]
221 affected_user_ids = [User.get_default_user_id()]
222 PermissionModel().trigger_permission_flush(affected_user_ids)
222 PermissionModel().trigger_permission_flush(affected_user_ids)
223
223
224 raise HTTPFound(h.route_path('admin_permissions_object'))
224 raise HTTPFound(h.route_path('admin_permissions_object'))
@@ -320,7 +320,7 b' class AdminPermissionsView(BaseAppView, '
320 h.flash(_('Error occurred during update of permissions'),
320 h.flash(_('Error occurred during update of permissions'),
321 category='error')
321 category='error')
322
322
323 affected_user_ids = [User.get_default_user().user_id]
323 affected_user_ids = [User.get_default_user_id()]
324 PermissionModel().trigger_permission_flush(affected_user_ids)
324 PermissionModel().trigger_permission_flush(affected_user_ids)
325
325
326 raise HTTPFound(h.route_path('admin_permissions_global'))
326 raise HTTPFound(h.route_path('admin_permissions_global'))
@@ -65,7 +65,7 b' class RepoSettingsView(RepoAppView):'
65 c = self.load_default_context()
65 c = self.load_default_context()
66 c.active = 'advanced'
66 c.active = 'advanced'
67
67
68 c.default_user_id = User.get_default_user().user_id
68 c.default_user_id = User.get_default_user_id()
69 c.in_public_journal = UserFollowing.query() \
69 c.in_public_journal = UserFollowing.query() \
70 .filter(UserFollowing.user_id == c.default_user_id) \
70 .filter(UserFollowing.user_id == c.default_user_id) \
71 .filter(UserFollowing.follows_repository == self.db_repo).scalar()
71 .filter(UserFollowing.follows_repository == self.db_repo).scalar()
@@ -220,7 +220,7 b' class RepoSettingsView(RepoAppView):'
220 _ = self.request.translate
220 _ = self.request.translate
221
221
222 try:
222 try:
223 user_id = User.get_default_user().user_id
223 user_id = User.get_default_user_id()
224 ScmModel().toggle_following_repo(self.db_repo.repo_id, user_id)
224 ScmModel().toggle_following_repo(self.db_repo.repo_id, user_id)
225 h.flash(_('Updated repository visibility in public journal'),
225 h.flash(_('Updated repository visibility in public journal'),
226 category='success')
226 category='success')
@@ -65,9 +65,9 b' def load_pyramid_environment(global_conf'
65 if alias not in settings['vcs.backends']:
65 if alias not in settings['vcs.backends']:
66 del rhodecode.BACKENDS[alias]
66 del rhodecode.BACKENDS[alias]
67
67
68 def sorter(item):
68 _sorted_backend = sorted(rhodecode.BACKENDS.items(),
69 return settings['vcs.backends'].index(item[0])
69 key=lambda item: settings['vcs.backends'].index(item[0]))
70 rhodecode.BACKENDS = rhodecode.OrderedDict(sorted(rhodecode.BACKENDS.items(), key=sorter))
70 rhodecode.BACKENDS = rhodecode.OrderedDict(_sorted_backend)
71
71
72 log.info('Enabled VCS backends: %s', rhodecode.BACKENDS.keys())
72 log.info('Enabled VCS backends: %s', rhodecode.BACKENDS.keys())
73
73
@@ -81,6 +81,7 b' def load_pyramid_environment(global_conf'
81
81
82 rhodecode.PYRAMID_SETTINGS = settings_merged
82 rhodecode.PYRAMID_SETTINGS = settings_merged
83 rhodecode.CONFIG = settings_merged
83 rhodecode.CONFIG = settings_merged
84 rhodecode.CONFIG['default_user_id'] = utils.get_default_user_id()
84
85
85 if vcs_server_enabled:
86 if vcs_server_enabled:
86 connect_vcs(vcs_server_uri, utils.get_vcs_server_protocol(settings))
87 connect_vcs(vcs_server_uri, utils.get_vcs_server_protocol(settings))
@@ -19,7 +19,6 b''
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21 import os
21 import os
22 import shlex
23 import platform
22 import platform
24
23
25 from rhodecode.model import init_model
24 from rhodecode.model import init_model
@@ -91,3 +90,12 b' def set_instance_id(config):'
91 prefix = instance_id.lstrip('*')
90 prefix = instance_id.lstrip('*')
92 _platform_id = platform.uname()[1] or 'instance'
91 _platform_id = platform.uname()[1] or 'instance'
93 config['instance_id'] = '%s%s-%s' % (prefix, _platform_id, os.getpid())
92 config['instance_id'] = '%s%s-%s' % (prefix, _platform_id, os.getpid())
93
94
95 def get_default_user_id():
96 from rhodecode.model.db import User, Session
97 user_id = Session()\
98 .query(User.user_id)\
99 .filter(User.username == User.DEFAULT_USER)\
100 .scalar()
101 return user_id
@@ -1048,6 +1048,11 b' class User(Base, BaseModel):'
1048 Session().refresh(user)
1048 Session().refresh(user)
1049 return user
1049 return user
1050
1050
1051 @classmethod
1052 def get_default_user_id(cls):
1053 import rhodecode
1054 return rhodecode.CONFIG['default_user_id']
1055
1051 def _get_default_perms(self, user, suffix=''):
1056 def _get_default_perms(self, user, suffix=''):
1052 from rhodecode.model.permission import PermissionModel
1057 from rhodecode.model.permission import PermissionModel
1053 return PermissionModel().get_default_perms(user.user_perms, suffix)
1058 return PermissionModel().get_default_perms(user.user_perms, suffix)
@@ -558,7 +558,7 b' class PermissionModel(BaseModel):'
558
558
559 def get_users_with_repo_write(self, db_repo):
559 def get_users_with_repo_write(self, db_repo):
560 write_plus = ['repository.write', 'repository.admin']
560 write_plus = ['repository.write', 'repository.admin']
561 default_user_id = User.get_default_user().user_id
561 default_user_id = User.get_default_user_id()
562 user_write_permissions = collections.OrderedDict()
562 user_write_permissions = collections.OrderedDict()
563
563
564 # write+ and DEFAULT user for inheritance
564 # write+ and DEFAULT user for inheritance
@@ -791,7 +791,7 b" def ValidPerms(localizer, type_='repo'):"
791
791
792 # get updates of permissions
792 # get updates of permissions
793 # (read the existing radio button states)
793 # (read the existing radio button states)
794 default_user_id = User.get_default_user().user_id
794 default_user_id = User.get_default_user_id()
795
795
796 for k, update_value in value.iteritems():
796 for k, update_value in value.iteritems():
797 if k.startswith('u_perm_') or k.startswith('g_perm_'):
797 if k.startswith('u_perm_') or k.startswith('g_perm_'):
@@ -147,7 +147,7 b' def test_cached_perms_data_repository_pe'
147 assert permissions['repositories'][repo.repo_name] == 'repository.admin'
147 assert permissions['repositories'][repo.repo_name] == 'repository.admin'
148
148
149 # TODO: johbo: Make cleanup in UserUtility smarter, then remove this hack
149 # TODO: johbo: Make cleanup in UserUtility smarter, then remove this hack
150 repo.user_id = User.get_default_user().user_id
150 repo.user_id = User.get_default_user_id()
151
151
152
152
153 def test_cached_perms_data_repository_permissions_not_inheriting_defaults(
153 def test_cached_perms_data_repository_permissions_not_inheriting_defaults(
@@ -49,7 +49,7 b" def permissions_setup_func(group_name='g"
49 user_id = test_u1_id
49 user_id = test_u1_id
50 # called by the @with_setup decorator also reset the default user stuff
50 # called by the @with_setup decorator also reset the default user stuff
51 permissions_setup_func(group_name, perm, recursive,
51 permissions_setup_func(group_name, perm, recursive,
52 user_id=User.get_default_user().user_id)
52 user_id=User.get_default_user_id())
53
53
54 # TODO: DRY, compare test_user_group:permissions_setup_func
54 # TODO: DRY, compare test_user_group:permissions_setup_func
55 repo_group = RepoGroup.get_by_group_name(group_name=group_name)
55 repo_group = RepoGroup.get_by_group_name(group_name=group_name)
@@ -142,7 +142,7 b' def test_user_permissions_on_group_with_'
142 # other repos and groups should have this permission now set !
142 # other repos and groups should have this permission now set !
143 recursive = 'all'
143 recursive = 'all'
144 group = 'g0'
144 group = 'g0'
145 default_user_id = User.get_default_user().user_id
145 default_user_id = User.get_default_user_id()
146 permissions_setup_func(group, 'group.write', recursive=recursive,
146 permissions_setup_func(group, 'group.write', recursive=recursive,
147 user_id=default_user_id)
147 user_id=default_user_id)
148
148
@@ -221,7 +221,7 b' def test_user_permissions_on_group_with_'
221 recursive = 'repos'
221 recursive = 'repos'
222 group = 'g0/g0_1'
222 group = 'g0/g0_1'
223 perm = 'group.none'
223 perm = 'group.none'
224 default_user_id = User.get_default_user().user_id
224 default_user_id = User.get_default_user_id()
225
225
226 # TODO: workaround due to different setup calls, adept to py.test style
226 # TODO: workaround due to different setup calls, adept to py.test style
227 permissions_setup_func()
227 permissions_setup_func()
@@ -281,7 +281,7 b' def test_user_permissions_on_group_with_'
281 # should remain intact as we use groups only mode !
281 # should remain intact as we use groups only mode !
282 recursive = 'groups'
282 recursive = 'groups'
283 group = 'g0/g0_1'
283 group = 'g0/g0_1'
284 default_user_id = User.get_default_user().user_id
284 default_user_id = User.get_default_user_id()
285
285
286 # TODO: workaround due to different setup calls, adept to py.test style
286 # TODO: workaround due to different setup calls, adept to py.test style
287 permissions_setup_func()
287 permissions_setup_func()
General Comments 0
You need to be logged in to leave comments. Login now