annotate rhodecode/tests/models/test_permissions.py @ 3714:7e3d89d9d3a2 beta

- Manage User’s Groups: create, delete, rename, add/remove users inside. by user group admin. In this case, a user's group can be owned by several people thru an owner user's group. Some refactoring of naming, permission handling logic. - remove some code duplicity as well as inconsistent naming
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 08 Apr 2013 22:47:35 +0200
parents 8a86836fad64
children af049a957506
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 import os
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2 import unittest
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3 from rhodecode.tests import *
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
4 from rhodecode.tests.fixture import Fixture
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5 from rhodecode.model.repos_group import ReposGroupModel
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 from rhodecode.model.repo import RepoModel
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
7 from rhodecode.model.db import RepoGroup, User, UserGroupRepoGroupToPerm
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8 from rhodecode.model.user import UserModel
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
10 from rhodecode.model.meta import Session
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
11 from rhodecode.model.users_group import UserGroupModel
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12 from rhodecode.lib.auth import AuthUser
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
13
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
14
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
15 fixture = Fixture()
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
16
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18 class TestPermissions(unittest.TestCase):
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 def __init__(self, methodName='runTest'):
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 super(TestPermissions, self).__init__(methodName=methodName)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
22 def setUp(self):
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23 self.u1 = UserModel().create_or_update(
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 username=u'u1', password=u'qweqwe',
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25 email=u'u1@rhodecode.org', firstname=u'u1', lastname=u'u1'
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 )
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27 self.u2 = UserModel().create_or_update(
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
28 username=u'u2', password=u'qweqwe',
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29 email=u'u2@rhodecode.org', firstname=u'u2', lastname=u'u2'
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30 )
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
31 self.u3 = UserModel().create_or_update(
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
32 username=u'u3', password=u'qweqwe',
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
33 email=u'u3@rhodecode.org', firstname=u'u3', lastname=u'u3'
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
34 )
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
35 self.anon = User.get_by_username('default')
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36 self.a1 = UserModel().create_or_update(
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 username=u'a1', password=u'qweqwe',
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38 email=u'a1@rhodecode.org', firstname=u'a1', lastname=u'a1', admin=True
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
39 )
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
40 Session().commit()
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
41
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42 def tearDown(self):
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43 if hasattr(self, 'test_repo'):
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44 RepoModel().delete(repo=self.test_repo)
2864
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
45
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46 UserModel().delete(self.u1)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47 UserModel().delete(self.u2)
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
48 UserModel().delete(self.u3)
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49 UserModel().delete(self.a1)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50 if hasattr(self, 'g1'):
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51 ReposGroupModel().delete(self.g1.group_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52 if hasattr(self, 'g2'):
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53 ReposGroupModel().delete(self.g2.group_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
54
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
55 if hasattr(self, 'ug1'):
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
56 UserGroupModel().delete(self.ug1, force=True)
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
57
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
58 Session().commit()
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
59
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
60 def test_default_perms_set(self):
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61 u1_auth = AuthUser(user_id=self.u1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62 perms = {
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
63 'repositories_groups': {},
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64 'global': set([u'hg.create.repository', u'repository.read',
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
65 u'hg.register.manual_activate']),
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
66 'repositories': {u'vcs_test_hg': u'repository.read'}
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
67 }
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
68 self.assertEqual(u1_auth.permissions['repositories'][HG_REPO],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
69 perms['repositories'][HG_REPO])
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
70 new_perm = 'repository.write'
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
71 RepoModel().grant_user_permission(repo=HG_REPO, user=self.u1,
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
72 perm=new_perm)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
73 Session().commit()
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
74
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75 u1_auth = AuthUser(user_id=self.u1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
76 self.assertEqual(u1_auth.permissions['repositories'][HG_REPO],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
77 new_perm)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
78
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
79 def test_default_admin_perms_set(self):
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80 a1_auth = AuthUser(user_id=self.a1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
81 perms = {
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
82 'repositories_groups': {},
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
83 'global': set([u'hg.admin']),
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
84 'repositories': {u'vcs_test_hg': u'repository.admin'}
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
85 }
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
86 self.assertEqual(a1_auth.permissions['repositories'][HG_REPO],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
87 perms['repositories'][HG_REPO])
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
88 new_perm = 'repository.write'
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
89 RepoModel().grant_user_permission(repo=HG_REPO, user=self.a1,
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
90 perm=new_perm)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
91 Session().commit()
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
92 # cannot really downgrade admins permissions !? they still get's set as
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
93 # admin !
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
94 u1_auth = AuthUser(user_id=self.a1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
95 self.assertEqual(u1_auth.permissions['repositories'][HG_REPO],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
96 perms['repositories'][HG_REPO])
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
97
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
98 def test_default_group_perms(self):
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
99 self.g1 = fixture.create_group('test1', skip_if_exists=True)
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
100 self.g2 = fixture.create_group('test2', skip_if_exists=True)
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
101 u1_auth = AuthUser(user_id=self.u1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
102 perms = {
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
103 'repositories_groups': {u'test1': 'group.read', u'test2': 'group.read'},
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
104 'global': set([u'hg.create.repository', u'repository.read', u'hg.register.manual_activate']),
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
105 'repositories': {u'vcs_test_hg': u'repository.read'}
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
106 }
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
107 self.assertEqual(u1_auth.permissions['repositories'][HG_REPO],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
108 perms['repositories'][HG_REPO])
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
109 self.assertEqual(u1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
110 perms['repositories_groups'])
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
111
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
112 def test_default_admin_group_perms(self):
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
113 self.g1 = fixture.create_group('test1', skip_if_exists=True)
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
114 self.g2 = fixture.create_group('test2', skip_if_exists=True)
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
115 a1_auth = AuthUser(user_id=self.a1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
116 perms = {
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
117 'repositories_groups': {u'test1': 'group.admin', u'test2': 'group.admin'},
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
118 'global': set(['hg.admin']),
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
119 'repositories': {u'vcs_test_hg': 'repository.admin'}
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
120 }
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
121
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
122 self.assertEqual(a1_auth.permissions['repositories'][HG_REPO],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
123 perms['repositories'][HG_REPO])
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
124 self.assertEqual(a1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
125 perms['repositories_groups'])
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
126
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
127 def test_propagated_permission_from_users_group_by_explicit_perms_exist(self):
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
128 # make group
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
129 self.ug1 = fixture.create_user_group('G1')
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
130 UserGroupModel().add_user_to_group(self.ug1, self.u1)
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
131
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
132 # set permission to lower
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
133 new_perm = 'repository.none'
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
134 RepoModel().grant_user_permission(repo=HG_REPO, user=self.u1, perm=new_perm)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
135 Session().commit()
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
136 u1_auth = AuthUser(user_id=self.u1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
137 self.assertEqual(u1_auth.permissions['repositories'][HG_REPO],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
138 new_perm)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
139
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
140 # grant perm for group this should not override permission from user
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
141 # since it has explicitly set
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
142 new_perm_gr = 'repository.write'
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
143 RepoModel().grant_users_group_permission(repo=HG_REPO,
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
144 group_name=self.ug1,
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
145 perm=new_perm_gr)
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
146 # check perms
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
147 u1_auth = AuthUser(user_id=self.u1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
148 perms = {
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
149 'repositories_groups': {},
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
150 'global': set([u'hg.create.repository', u'repository.read',
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
151 u'hg.register.manual_activate']),
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
152 'repositories': {u'vcs_test_hg': u'repository.read'}
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
153 }
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
154 self.assertEqual(u1_auth.permissions['repositories'][HG_REPO],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
155 new_perm)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
156 self.assertEqual(u1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
157 perms['repositories_groups'])
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
158
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
159 def test_propagated_permission_from_users_group(self):
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
160 # make group
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
161 self.ug1 = fixture.create_user_group('G1')
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
162 UserGroupModel().add_user_to_group(self.ug1, self.u3)
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
163
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
164 # grant perm for group this should override default permission from user
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
165 new_perm_gr = 'repository.write'
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
166 RepoModel().grant_users_group_permission(repo=HG_REPO,
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
167 group_name=self.ug1,
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
168 perm=new_perm_gr)
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
169 # check perms
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
170 u3_auth = AuthUser(user_id=self.u3.user_id)
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
171 perms = {
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
172 'repositories_groups': {},
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
173 'global': set([u'hg.create.repository', u'repository.read',
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
174 u'hg.register.manual_activate']),
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
175 'repositories': {u'vcs_test_hg': u'repository.read'}
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
176 }
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
177 self.assertEqual(u3_auth.permissions['repositories'][HG_REPO],
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
178 new_perm_gr)
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
179 self.assertEqual(u3_auth.permissions['repositories_groups'],
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
180 perms['repositories_groups'])
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
181
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
182 def test_propagated_permission_from_users_group_lower_weight(self):
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
183 # make group
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
184 self.ug1 = fixture.create_user_group('G1')
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
185 # add user to group
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
186 UserGroupModel().add_user_to_group(self.ug1, self.u1)
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
187
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
188 # set permission to lower
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
189 new_perm_h = 'repository.write'
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
190 RepoModel().grant_user_permission(repo=HG_REPO, user=self.u1,
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
191 perm=new_perm_h)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
192 Session().commit()
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
193 u1_auth = AuthUser(user_id=self.u1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
194 self.assertEqual(u1_auth.permissions['repositories'][HG_REPO],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
195 new_perm_h)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
196
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
197 # grant perm for group this should NOT override permission from user
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
198 # since it's lower than granted
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
199 new_perm_l = 'repository.read'
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
200 RepoModel().grant_users_group_permission(repo=HG_REPO,
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
201 group_name=self.ug1,
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
202 perm=new_perm_l)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
203 # check perms
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
204 u1_auth = AuthUser(user_id=self.u1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
205 perms = {
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
206 'repositories_groups': {},
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
207 'global': set([u'hg.create.repository', u'repository.read',
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
208 u'hg.register.manual_activate']),
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
209 'repositories': {u'vcs_test_hg': u'repository.write'}
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
210 }
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
211 self.assertEqual(u1_auth.permissions['repositories'][HG_REPO],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
212 new_perm_h)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
213 self.assertEqual(u1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
214 perms['repositories_groups'])
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
215
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
216 def test_repo_in_group_permissions(self):
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
217 self.g1 = fixture.create_group('group1', skip_if_exists=True)
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
218 self.g2 = fixture.create_group('group2', skip_if_exists=True)
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
219 # both perms should be read !
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
220 u1_auth = AuthUser(user_id=self.u1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
221 self.assertEqual(u1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
222 {u'group1': u'group.read', u'group2': u'group.read'})
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
223
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
224 a1_auth = AuthUser(user_id=self.anon.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
225 self.assertEqual(a1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
226 {u'group1': u'group.read', u'group2': u'group.read'})
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
227
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
228 #Change perms to none for both groups
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
229 ReposGroupModel().grant_user_permission(repos_group=self.g1,
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
230 user=self.anon,
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
231 perm='group.none')
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
232 ReposGroupModel().grant_user_permission(repos_group=self.g2,
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
233 user=self.anon,
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
234 perm='group.none')
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
235
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
236 u1_auth = AuthUser(user_id=self.u1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
237 self.assertEqual(u1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
238 {u'group1': u'group.none', u'group2': u'group.none'})
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
239
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
240 a1_auth = AuthUser(user_id=self.anon.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
241 self.assertEqual(a1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
242 {u'group1': u'group.none', u'group2': u'group.none'})
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
243
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
244 # add repo to group
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
245 name = RepoGroup.url_sep().join([self.g1.group_name, 'test_perm'])
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
246 self.test_repo = fixture.create_repo(name=name,
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
247 repo_type='hg',
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
248 repos_group=self.g1,
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
249 cur_user=self.u1,)
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
250
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
251 u1_auth = AuthUser(user_id=self.u1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
252 self.assertEqual(u1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
253 {u'group1': u'group.none', u'group2': u'group.none'})
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
254
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
255 a1_auth = AuthUser(user_id=self.anon.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
256 self.assertEqual(a1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
257 {u'group1': u'group.none', u'group2': u'group.none'})
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
258
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
259 #grant permission for u2 !
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
260 ReposGroupModel().grant_user_permission(repos_group=self.g1,
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
261 user=self.u2,
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
262 perm='group.read')
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
263 ReposGroupModel().grant_user_permission(repos_group=self.g2,
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
264 user=self.u2,
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
265 perm='group.read')
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
266 Session().commit()
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
267 self.assertNotEqual(self.u1, self.u2)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
268 #u1 and anon should have not change perms while u2 should !
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
269 u1_auth = AuthUser(user_id=self.u1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
270 self.assertEqual(u1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
271 {u'group1': u'group.none', u'group2': u'group.none'})
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
272
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
273 u2_auth = AuthUser(user_id=self.u2.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
274 self.assertEqual(u2_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
275 {u'group1': u'group.read', u'group2': u'group.read'})
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
276
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
277 a1_auth = AuthUser(user_id=self.anon.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
278 self.assertEqual(a1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
279 {u'group1': u'group.none', u'group2': u'group.none'})
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
280
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
281 def test_repo_group_user_as_user_group_member(self):
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
282 # create Group1
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
283 self.g1 = fixture.create_group('group1', skip_if_exists=True)
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
284 a1_auth = AuthUser(user_id=self.anon.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
285
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
286 self.assertEqual(a1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
287 {u'group1': u'group.read'})
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
288
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
289 # set default permission to none
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
290 ReposGroupModel().grant_user_permission(repos_group=self.g1,
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
291 user=self.anon,
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
292 perm='group.none')
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
293 # make group
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
294 self.ug1 = fixture.create_user_group('G1')
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
295 # add user to group
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
296 UserGroupModel().add_user_to_group(self.ug1, self.u1)
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
297 Session().commit()
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
298
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
299 # check if user is in the group
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
300 membrs = [x.user_id for x in UserGroupModel().get(self.ug1.users_group_id).members]
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
301 self.assertEqual(membrs, [self.u1.user_id])
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
302 # add some user to that group
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
303
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
304 # check his permissions
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
305 a1_auth = AuthUser(user_id=self.anon.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
306 self.assertEqual(a1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
307 {u'group1': u'group.none'})
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
308
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
309 u1_auth = AuthUser(user_id=self.u1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
310 self.assertEqual(u1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
311 {u'group1': u'group.none'})
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
312
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
313 # grant ug1 read permissions for
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
314 ReposGroupModel().grant_users_group_permission(repos_group=self.g1,
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
315 group_name=self.ug1,
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
316 perm='group.read')
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
317 Session().commit()
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
318 # check if the
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
319 obj = Session().query(UserGroupRepoGroupToPerm)\
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
320 .filter(UserGroupRepoGroupToPerm.group == self.g1)\
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
321 .filter(UserGroupRepoGroupToPerm.users_group == self.ug1)\
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
322 .scalar()
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
323 self.assertEqual(obj.permission.permission_name, 'group.read')
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
324
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
325 a1_auth = AuthUser(user_id=self.anon.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
326
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
327 self.assertEqual(a1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
328 {u'group1': u'group.none'})
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
329
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
330 u1_auth = AuthUser(user_id=self.u1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
331 self.assertEqual(u1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
332 {u'group1': u'group.read'})
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
333
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
334 def test_inherited_permissions_from_default_on_user_enabled(self):
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
335 user_model = UserModel()
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
336 # enable fork and create on default user
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
337 usr = 'default'
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
338 user_model.revoke_perm(usr, 'hg.create.none')
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
339 user_model.grant_perm(usr, 'hg.create.repository')
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
340 user_model.revoke_perm(usr, 'hg.fork.none')
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
341 user_model.grant_perm(usr, 'hg.fork.repository')
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
342 # make sure inherit flag is turned on
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
343 self.u1.inherit_default_permissions = True
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
344 Session().commit()
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
345 u1_auth = AuthUser(user_id=self.u1.user_id)
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
346 # this user will have inherited permissions from default user
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
347 self.assertEqual(u1_auth.permissions['global'],
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
348 set(['hg.create.repository', 'hg.fork.repository',
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
349 'hg.register.manual_activate',
3053
d7e10699513b fixed some tests after recent changes on default group permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2864
diff changeset
350 'repository.read', 'group.read']))
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
351
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
352 def test_inherited_permissions_from_default_on_user_disabled(self):
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
353 user_model = UserModel()
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
354 # disable fork and create on default user
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
355 usr = 'default'
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
356 user_model.revoke_perm(usr, 'hg.create.repository')
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
357 user_model.grant_perm(usr, 'hg.create.none')
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
358 user_model.revoke_perm(usr, 'hg.fork.repository')
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
359 user_model.grant_perm(usr, 'hg.fork.none')
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
360 # make sure inherit flag is turned on
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
361 self.u1.inherit_default_permissions = True
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
362 Session().commit()
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
363 u1_auth = AuthUser(user_id=self.u1.user_id)
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
364 # this user will have inherited permissions from default user
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
365 self.assertEqual(u1_auth.permissions['global'],
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
366 set(['hg.create.none', 'hg.fork.none',
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
367 'hg.register.manual_activate',
3053
d7e10699513b fixed some tests after recent changes on default group permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2864
diff changeset
368 'repository.read', 'group.read']))
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
369
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
370 def test_non_inherited_permissions_from_default_on_user_enabled(self):
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
371 user_model = UserModel()
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
372 # enable fork and create on default user
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
373 usr = 'default'
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
374 user_model.revoke_perm(usr, 'hg.create.none')
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
375 user_model.grant_perm(usr, 'hg.create.repository')
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
376 user_model.revoke_perm(usr, 'hg.fork.none')
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
377 user_model.grant_perm(usr, 'hg.fork.repository')
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
378
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
379 #disable global perms on specific user
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
380 user_model.revoke_perm(self.u1, 'hg.create.repository')
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
381 user_model.grant_perm(self.u1, 'hg.create.none')
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
382 user_model.revoke_perm(self.u1, 'hg.fork.repository')
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
383 user_model.grant_perm(self.u1, 'hg.fork.none')
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
384
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
385 # make sure inherit flag is turned off
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
386 self.u1.inherit_default_permissions = False
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
387 Session().commit()
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
388 u1_auth = AuthUser(user_id=self.u1.user_id)
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
389 # this user will have non inherited permissions from he's
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
390 # explicitly set permissions
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
391 self.assertEqual(u1_auth.permissions['global'],
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
392 set(['hg.create.none', 'hg.fork.none',
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
393 'hg.register.manual_activate',
3053
d7e10699513b fixed some tests after recent changes on default group permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2864
diff changeset
394 'repository.read', 'group.read']))
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
395
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
396 def test_non_inherited_permissions_from_default_on_user_disabled(self):
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
397 user_model = UserModel()
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
398 # disable fork and create on default user
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
399 usr = 'default'
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
400 user_model.revoke_perm(usr, 'hg.create.repository')
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
401 user_model.grant_perm(usr, 'hg.create.none')
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
402 user_model.revoke_perm(usr, 'hg.fork.repository')
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
403 user_model.grant_perm(usr, 'hg.fork.none')
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
404
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
405 #enable global perms on specific user
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
406 user_model.revoke_perm(self.u1, 'hg.create.none')
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
407 user_model.grant_perm(self.u1, 'hg.create.repository')
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
408 user_model.revoke_perm(self.u1, 'hg.fork.none')
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
409 user_model.grant_perm(self.u1, 'hg.fork.repository')
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
410
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
411 # make sure inherit flag is turned off
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
412 self.u1.inherit_default_permissions = False
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
413 Session().commit()
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
414 u1_auth = AuthUser(user_id=self.u1.user_id)
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
415 # this user will have non inherited permissions from he's
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
416 # explicitly set permissions
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
417 self.assertEqual(u1_auth.permissions['global'],
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
418 set(['hg.create.repository', 'hg.fork.repository',
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
419 'hg.register.manual_activate',
3053
d7e10699513b fixed some tests after recent changes on default group permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2864
diff changeset
420 'repository.read', 'group.read']))
2864
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
421
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
422 def test_owner_permissions_doesnot_get_overwritten_by_group(self):
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
423 #create repo as USER,
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
424 self.test_repo = fixture.create_repo(name='myownrepo',
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
425 repo_type='hg',
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
426 cur_user=self.u1)
2864
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
427
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
428 #he has permissions of admin as owner
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
429 u1_auth = AuthUser(user_id=self.u1.user_id)
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
430 self.assertEqual(u1_auth.permissions['repositories']['myownrepo'],
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
431 'repository.admin')
3415
b8f929bff7e3 fixed tests and missing replacements from 5f1850e4712a
Marcin Kuzminski <marcin@python-works.com>
parents: 3053
diff changeset
432 #set his permission as user group, he should still be admin
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
433 self.ug1 = fixture.create_user_group('G1')
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
434 UserGroupModel().add_user_to_group(self.ug1, self.u1)
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
435 RepoModel().grant_users_group_permission(self.test_repo,
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
436 group_name=self.ug1,
2864
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
437 perm='repository.none')
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
438
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
439 Session().commit()
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
440 u1_auth = AuthUser(user_id=self.u1.user_id)
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
441 self.assertEqual(u1_auth.permissions['repositories']['myownrepo'],
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
442 'repository.admin')
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
443
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
444 def test_owner_permissions_doesnot_get_overwritten_by_others(self):
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
445 #create repo as USER,
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
446 self.test_repo = fixture.create_repo(name='myownrepo',
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
447 repo_type='hg',
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
448 cur_user=self.u1)
2864
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
449
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
450 #he has permissions of admin as owner
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
451 u1_auth = AuthUser(user_id=self.u1.user_id)
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
452 self.assertEqual(u1_auth.permissions['repositories']['myownrepo'],
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
453 'repository.admin')
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
454 #set his permission as user, he should still be admin
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
455 RepoModel().grant_user_permission(self.test_repo, user=self.u1,
2864
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
456 perm='repository.none')
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
457 Session().commit()
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
458 u1_auth = AuthUser(user_id=self.u1.user_id)
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
459 self.assertEqual(u1_auth.permissions['repositories']['myownrepo'],
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
460 'repository.admin')