##// END OF EJS Templates
added test for setting repo as private which should set perm => None for default user
marcink -
r3219:42d7ca49 beta
parent child Browse files
Show More
@@ -538,6 +538,9 b" def ValidPerms(type_='repo'):"
538 # private repo
538 # private repo
539 v = EMPTY_PERM
539 v = EMPTY_PERM
540 perms_update.add((member, v, t))
540 perms_update.add((member, v, t))
541 #always set NONE when private flag is set
542 if value.get('repo_private'):
543 perms_update.add(('default', EMPTY_PERM, 'user'))
541
544
542 value['perms_updates'] = list(perms_update)
545 value['perms_updates'] = list(perms_update)
543 value['perms_new'] = list(perms_new)
546 value['perms_new'] = list(perms_new)
@@ -157,7 +157,8 b' class TestController(TestCase):'
157 return User.get_by_username(self._logged_username)
157 return User.get_by_username(self._logged_username)
158
158
159 def checkSessionFlash(self, response, msg):
159 def checkSessionFlash(self, response, msg):
160 self.assertTrue('flash' in response.session)
160 self.assertTrue('flash' in response.session,
161 msg='Response session:%r have no flash' % response.session)
161 if not msg in response.session['flash'][0][1]:
162 if not msg in response.session['flash'][0][1]:
162 self.fail(
163 self.fail(
163 'msg `%s` not found in session flash: got `%s` instead' % (
164 'msg `%s` not found in session flash: got `%s` instead' % (
@@ -213,7 +213,6 b' class TestAdminReposController(TestContr'
213 self.log_user()
213 self.log_user()
214 repo_name = 'vcs_test_new_to_delete'
214 repo_name = 'vcs_test_new_to_delete'
215 description = 'description for newly created repo'
215 description = 'description for newly created repo'
216 private = False
217 response = self.app.post(url('repos'),
216 response = self.app.post(url('repos'),
218 _get_repo_create_params(repo_private=False,
217 _get_repo_create_params(repo_private=False,
219 repo_type='hg',
218 repo_type='hg',
@@ -1,5 +1,16 b''
1 from rhodecode.model.db import Repository
2 from rhodecode.tests import *
1 from rhodecode.tests import *
2 from rhodecode.model.db import UserRepoToPerm, Repository, User, Permission
3 from rhodecode.model.meta import Session
4
5
6 def _get_permission_for_user(user, repo):
7 perm = UserRepoToPerm.query()\
8 .filter(UserRepoToPerm.repository ==
9 Repository.get_by_repo_name(repo))\
10 .filter(UserRepoToPerm.user == User.get_by_username(user))\
11 .all()
12 return perm
13
3
14
4 class TestSettingsController(TestController):
15 class TestSettingsController(TestController):
5
16
@@ -8,3 +19,43 b' class TestSettingsController(TestControl'
8 response = self.app.get(url(controller='settings', action='index',
19 response = self.app.get(url(controller='settings', action='index',
9 repo_name=HG_REPO))
20 repo_name=HG_REPO))
10 # Test response...
21 # Test response...
22
23 def test_set_private_flag_sets_default_to_none(self):
24 self.log_user()
25 #initially repository perm should be read
26 perm = _get_permission_for_user(user='default', repo=HG_REPO)
27 self.assertTrue(len(perm), 1)
28 self.assertEqual(perm[0].permission.permission_name, 'repository.read')
29 self.assertEqual(Repository.get_by_repo_name(HG_REPO).private, False)
30
31 response = self.app.put(url('repo', repo_name=HG_REPO),
32 _get_repo_create_params(repo_private=1,
33 repo_name=HG_REPO,
34 user=TEST_USER_ADMIN_LOGIN))
35 self.checkSessionFlash(response,
36 msg='Repository %s updated successfully' % (HG_REPO))
37 self.assertEqual(Repository.get_by_repo_name(HG_REPO).private, True)
38
39 #now the repo default permission should be None
40 perm = _get_permission_for_user(user='default', repo=HG_REPO)
41 self.assertTrue(len(perm), 1)
42 self.assertEqual(perm[0].permission.permission_name, 'repository.none')
43
44 response = self.app.put(url('repo', repo_name=HG_REPO),
45 _get_repo_create_params(repo_private=False,
46 repo_name=HG_REPO,
47 user=TEST_USER_ADMIN_LOGIN))
48 self.checkSessionFlash(response,
49 msg='Repository %s updated successfully' % (HG_REPO))
50 self.assertEqual(Repository.get_by_repo_name(HG_REPO).private, False)
51
52 #we turn off private now the repo default permission should stay None
53 perm = _get_permission_for_user(user='default', repo=HG_REPO)
54 self.assertTrue(len(perm), 1)
55 self.assertEqual(perm[0].permission.permission_name, 'repository.none')
56
57 #update this permission back
58 perm[0].permission = Permission.get_by_key('repository.read')
59 Session().add(perm[0])
60 Session().commit()
61 No newline at end of file
@@ -117,6 +117,11 b' def test_user_permissions_on_group_with_'
117
117
118
118
119 @with_setup(permissions_setup_func)
119 @with_setup(permissions_setup_func)
120 def test_user_permissions_on_group_with_recursive_mode_and_private_repos():
121 assert 0
122
123
124 @with_setup(permissions_setup_func)
120 def test_user_permissions_on_group_with_recursive_mode_inner_group():
125 def test_user_permissions_on_group_with_recursive_mode_inner_group():
121 ## set permission to g0_3 group to none
126 ## set permission to g0_3 group to none
122 recursive = True
127 recursive = True
General Comments 0
You need to be logged in to leave comments. Login now