annotate rhodecode/tests/models/test_permissions.py @ 4116:ffd45b185016 rhodecode-2.2.5-gpl

Imported some of the GPLv3'd changes from RhodeCode v2.2.5. This imports changes between changesets 21af6c4eab3d and 6177597791c2 in RhodeCode's original repository, including only changes to Python files and HTML. RhodeCode clearly licensed its changes to these files under GPLv3 in their /LICENSE file, which states the following: The Python code and integrated HTML are licensed under the GPLv3 license. (See: https://code.rhodecode.com/rhodecode/files/v2.2.5/LICENSE or http://web.archive.org/web/20140512193334/https://code.rhodecode.com/rhodecode/files/f3b123159901f15426d18e3dc395e8369f70ebe0/LICENSE for an online copy of that LICENSE file) Conservancy reviewed these changes and confirmed that they can be licensed as a whole to the Kallithea project under GPLv3-only. While some of the contents committed herein are clearly licensed GPLv3-or-later, on the whole we must assume the are GPLv3-only, since the statement above from RhodeCode indicates that they intend GPLv3-only as their license, per GPLv3ยง14 and other relevant sections of GPLv3.
author Bradley M. Kuhn <bkuhn@sfconservancy.org>
date Wed, 02 Jul 2014 19:03:13 -0400
parents a5888ca796b5
children da3c57422ee6
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 from rhodecode.tests import *
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
2 from rhodecode.tests.fixture import Fixture
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
3 from rhodecode.model.repo_group import RepoGroupModel
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4 from rhodecode.model.repo import RepoModel
3733
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
5 from rhodecode.model.db import RepoGroup, User, UserGroupRepoGroupToPerm,\
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
6 Permission, UserToPerm
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7 from rhodecode.model.user import UserModel
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9 from rhodecode.model.meta import Session
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
10 from rhodecode.model.user_group import UserGroupModel
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11 from rhodecode.lib.auth import AuthUser
3733
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
12 from rhodecode.model.permission import PermissionModel
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
3829
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3787
diff changeset
18 class TestPermissions(BaseTestCase):
2527
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
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
22 @classmethod
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
23 def setUpClass(cls):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
24 #recreate default user to get a clean start
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
25 PermissionModel().create_default_permissions(user=User.DEFAULT_USER,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
26 force=True)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
27 Session().commit()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
28
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29 def setUp(self):
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30 self.u1 = UserModel().create_or_update(
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31 username=u'u1', password=u'qweqwe',
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
32 email=u'u1@rhodecode.org', firstname=u'u1', lastname=u'u1'
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33 )
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34 self.u2 = UserModel().create_or_update(
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
35 username=u'u2', password=u'qweqwe',
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36 email=u'u2@rhodecode.org', firstname=u'u2', lastname=u'u2'
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 )
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
38 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
39 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
40 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
41 )
3734
a8f520540ab0 New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents: 3733
diff changeset
42 self.anon = User.get_default_user()
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43 self.a1 = UserModel().create_or_update(
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44 username=u'a1', password=u'qweqwe',
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45 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
46 )
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47 Session().commit()
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
48
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49 def tearDown(self):
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50 if hasattr(self, 'test_repo'):
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51 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
52
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53 UserModel().delete(self.u1)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
54 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
55 UserModel().delete(self.u3)
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
56 UserModel().delete(self.a1)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
57 if hasattr(self, 'g1'):
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
58 RepoGroupModel().delete(self.g1.group_id)
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
59 if hasattr(self, 'g2'):
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
60 RepoGroupModel().delete(self.g2.group_id)
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62 if hasattr(self, 'ug1'):
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
63 UserGroupModel().delete(self.ug1, force=True)
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
65 Session().commit()
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
66
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
67 def test_default_perms_set(self):
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
68 u1_auth = AuthUser(user_id=self.u1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
69 perms = {
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
70 'repositories_groups': {},
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
71 'global': set([u'hg.create.repository', u'repository.read',
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
72 u'hg.register.manual_activate']),
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
73 'repositories': {u'vcs_test_hg': u'repository.read'}
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 self.assertEqual(u1_auth.permissions['repositories'][HG_REPO],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
76 perms['repositories'][HG_REPO])
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
77 new_perm = 'repository.write'
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
78 RepoModel().grant_user_permission(repo=HG_REPO, user=self.u1,
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
79 perm=new_perm)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80 Session().commit()
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
81
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
82 u1_auth = AuthUser(user_id=self.u1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
83 self.assertEqual(u1_auth.permissions['repositories'][HG_REPO],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
84 new_perm)
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 def test_default_admin_perms_set(self):
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
87 a1_auth = AuthUser(user_id=self.a1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
88 perms = {
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
89 'repositories_groups': {},
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
90 'global': set([u'hg.admin', 'hg.create.write_on_repogroup.true']),
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
91 'repositories': {u'vcs_test_hg': u'repository.admin'}
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
92 }
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
93 self.assertEqual(a1_auth.permissions['repositories'][HG_REPO],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
94 perms['repositories'][HG_REPO])
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
95 new_perm = 'repository.write'
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
96 RepoModel().grant_user_permission(repo=HG_REPO, user=self.a1,
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
97 perm=new_perm)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
98 Session().commit()
4089
a5888ca796b5 Fixed spelling of get's to gets
Marcin Kuzminski <marcin@python-works.com>
parents: 3829
diff changeset
99 # cannot really downgrade admins permissions !? they still gets set as
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
100 # admin !
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
101 u1_auth = AuthUser(user_id=self.a1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
102 self.assertEqual(u1_auth.permissions['repositories'][HG_REPO],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
103 perms['repositories'][HG_REPO])
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
104
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
105 def test_default_group_perms(self):
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
106 self.g1 = fixture.create_repo_group('test1', skip_if_exists=True)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
107 self.g2 = fixture.create_repo_group('test2', skip_if_exists=True)
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
108 u1_auth = AuthUser(user_id=self.u1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
109 perms = {
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
110 'repositories_groups': {u'test1': 'group.read', u'test2': 'group.read'},
3733
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
111 'global': set(Permission.DEFAULT_USER_PERMISSIONS),
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
112 'repositories': {u'vcs_test_hg': u'repository.read'}
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
113 }
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
114 self.assertEqual(u1_auth.permissions['repositories'][HG_REPO],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
115 perms['repositories'][HG_REPO])
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
116 self.assertEqual(u1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
117 perms['repositories_groups'])
3733
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
118 self.assertEqual(u1_auth.permissions['global'],
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
119 perms['global'])
2527
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 def test_default_admin_group_perms(self):
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
122 self.g1 = fixture.create_repo_group('test1', skip_if_exists=True)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
123 self.g2 = fixture.create_repo_group('test2', skip_if_exists=True)
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
124 a1_auth = AuthUser(user_id=self.a1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
125 perms = {
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
126 'repositories_groups': {u'test1': 'group.admin', u'test2': 'group.admin'},
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
127 'global': set(['hg.admin', 'hg.create.write_on_repogroup.true']),
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
128 'repositories': {u'vcs_test_hg': 'repository.admin'}
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
129 }
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
130
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
131 self.assertEqual(a1_auth.permissions['repositories'][HG_REPO],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
132 perms['repositories'][HG_REPO])
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
133 self.assertEqual(a1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
134 perms['repositories_groups'])
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
135
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
136 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
137 # 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
138 self.ug1 = fixture.create_user_group('G1')
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
139 UserGroupModel().add_user_to_group(self.ug1, self.u1)
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
140
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
141 # set permission to lower
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
142 new_perm = 'repository.none'
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
143 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
144 Session().commit()
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
145 u1_auth = AuthUser(user_id=self.u1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
146 self.assertEqual(u1_auth.permissions['repositories'][HG_REPO],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
147 new_perm)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
148
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
149 # 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
150 # 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
151 new_perm_gr = 'repository.write'
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
152 RepoModel().grant_user_group_permission(repo=HG_REPO,
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
153 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
154 perm=new_perm_gr)
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
155 # check perms
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
156 u1_auth = AuthUser(user_id=self.u1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
157 perms = {
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
158 'repositories_groups': {},
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
159 'global': set([u'hg.create.repository', u'repository.read',
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
160 u'hg.register.manual_activate']),
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
161 'repositories': {u'vcs_test_hg': u'repository.read'}
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
162 }
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
163 self.assertEqual(u1_auth.permissions['repositories'][HG_REPO],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
164 new_perm)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
165 self.assertEqual(u1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
166 perms['repositories_groups'])
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
167
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
168 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
169 # 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
170 self.ug1 = fixture.create_user_group('G1')
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
171 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
172
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
173 # 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
174 new_perm_gr = 'repository.write'
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
175 RepoModel().grant_user_group_permission(repo=HG_REPO,
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
176 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
177 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
178 # 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
179 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
180 perms = {
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
181 '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
182 '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
183 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
184 '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
185 }
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
186 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
187 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
188 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
189 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
190
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
191 def test_propagated_permission_from_users_group_lower_weight(self):
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
192 # 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
193 self.ug1 = fixture.create_user_group('G1')
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
194 # add user to group
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
195 UserGroupModel().add_user_to_group(self.ug1, self.u1)
2527
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 # set permission to lower
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
198 new_perm_h = 'repository.write'
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
199 RepoModel().grant_user_permission(repo=HG_REPO, user=self.u1,
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
200 perm=new_perm_h)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
201 Session().commit()
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
202 u1_auth = AuthUser(user_id=self.u1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
203 self.assertEqual(u1_auth.permissions['repositories'][HG_REPO],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
204 new_perm_h)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
205
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
206 # grant perm for group this should NOT override permission from user
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
207 # since it's lower than granted
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
208 new_perm_l = 'repository.read'
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
209 RepoModel().grant_user_group_permission(repo=HG_REPO,
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
210 group_name=self.ug1,
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
211 perm=new_perm_l)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
212 # check perms
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
213 u1_auth = AuthUser(user_id=self.u1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
214 perms = {
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
215 'repositories_groups': {},
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
216 'global': set([u'hg.create.repository', u'repository.read',
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
217 u'hg.register.manual_activate']),
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
218 'repositories': {u'vcs_test_hg': u'repository.write'}
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
219 }
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
220 self.assertEqual(u1_auth.permissions['repositories'][HG_REPO],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
221 new_perm_h)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
222 self.assertEqual(u1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
223 perms['repositories_groups'])
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
224
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
225 def test_repo_in_group_permissions(self):
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
226 self.g1 = fixture.create_repo_group('group1', skip_if_exists=True)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
227 self.g2 = fixture.create_repo_group('group2', skip_if_exists=True)
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
228 # both perms should be read !
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
229 u1_auth = AuthUser(user_id=self.u1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
230 self.assertEqual(u1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
231 {u'group1': u'group.read', u'group2': u'group.read'})
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
232
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
233 a1_auth = AuthUser(user_id=self.anon.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
234 self.assertEqual(a1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
235 {u'group1': u'group.read', u'group2': u'group.read'})
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
236
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
237 #Change perms to none for both groups
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
238 RepoGroupModel().grant_user_permission(repo_group=self.g1,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
239 user=self.anon,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
240 perm='group.none')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
241 RepoGroupModel().grant_user_permission(repo_group=self.g2,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
242 user=self.anon,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
243 perm='group.none')
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
244
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
245 u1_auth = AuthUser(user_id=self.u1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
246 self.assertEqual(u1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
247 {u'group1': u'group.none', u'group2': u'group.none'})
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
248
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
249 a1_auth = AuthUser(user_id=self.anon.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
250 self.assertEqual(a1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
251 {u'group1': u'group.none', u'group2': u'group.none'})
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
252
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
253 # add repo to group
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
254 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
255 self.test_repo = fixture.create_repo(name=name,
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
256 repo_type='hg',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
257 repo_group=self.g1,
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
258 cur_user=self.u1,)
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
259
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
260 u1_auth = AuthUser(user_id=self.u1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
261 self.assertEqual(u1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
262 {u'group1': u'group.none', u'group2': u'group.none'})
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
263
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
264 a1_auth = AuthUser(user_id=self.anon.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
265 self.assertEqual(a1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
266 {u'group1': u'group.none', u'group2': u'group.none'})
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
267
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
268 #grant permission for u2 !
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
269 RepoGroupModel().grant_user_permission(repo_group=self.g1, user=self.u2,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
270 perm='group.read')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
271 RepoGroupModel().grant_user_permission(repo_group=self.g2, user=self.u2,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
272 perm='group.read')
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
273 Session().commit()
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
274 self.assertNotEqual(self.u1, self.u2)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
275 #u1 and anon should have not change perms while u2 should !
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
276 u1_auth = AuthUser(user_id=self.u1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
277 self.assertEqual(u1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
278 {u'group1': u'group.none', u'group2': u'group.none'})
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
279
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
280 u2_auth = AuthUser(user_id=self.u2.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
281 self.assertEqual(u2_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
282 {u'group1': u'group.read', u'group2': u'group.read'})
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
283
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 self.assertEqual(a1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
286 {u'group1': u'group.none', u'group2': u'group.none'})
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
287
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
288 def test_repo_group_user_as_user_group_member(self):
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
289 # create Group1
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
290 self.g1 = fixture.create_repo_group('group1', skip_if_exists=True)
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
291 a1_auth = AuthUser(user_id=self.anon.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
292
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
293 self.assertEqual(a1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
294 {u'group1': u'group.read'})
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
295
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
296 # set default permission to none
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
297 RepoGroupModel().grant_user_permission(repo_group=self.g1,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
298 user=self.anon,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
299 perm='group.none')
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
300 # 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
301 self.ug1 = fixture.create_user_group('G1')
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
302 # add user to group
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
303 UserGroupModel().add_user_to_group(self.ug1, self.u1)
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
304 Session().commit()
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
305
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
306 # check if user is in the group
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
307 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
308 self.assertEqual(membrs, [self.u1.user_id])
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
309 # add some user to that group
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
310
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
311 # check his permissions
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
312 a1_auth = AuthUser(user_id=self.anon.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
313 self.assertEqual(a1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
314 {u'group1': u'group.none'})
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
315
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
316 u1_auth = AuthUser(user_id=self.u1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
317 self.assertEqual(u1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
318 {u'group1': u'group.none'})
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
319
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
320 # grant ug1 read permissions for
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
321 RepoGroupModel().grant_user_group_permission(repo_group=self.g1,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
322 group_name=self.ug1,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
323 perm='group.read')
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
324 Session().commit()
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
325 # check if the
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
326 obj = Session().query(UserGroupRepoGroupToPerm)\
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
327 .filter(UserGroupRepoGroupToPerm.group == self.g1)\
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
328 .filter(UserGroupRepoGroupToPerm.users_group == self.ug1)\
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
329 .scalar()
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
330 self.assertEqual(obj.permission.permission_name, 'group.read')
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
331
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
332 a1_auth = AuthUser(user_id=self.anon.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
333
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
334 self.assertEqual(a1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
335 {u'group1': u'group.none'})
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
336
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
337 u1_auth = AuthUser(user_id=self.u1.user_id)
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
338 self.assertEqual(u1_auth.permissions['repositories_groups'],
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
339 {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
340
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
341 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
342 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
343 # 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
344 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
345 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
346 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
347 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
348 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
349 # 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
350 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
351 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
352 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
353 # 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
354 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
355 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
356 'hg.register.manual_activate',
3787
a3b1016855f8 fixed tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3734
diff changeset
357 'hg.extern_activate.auto',
3733
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
358 'repository.read', 'group.read',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
359 'usergroup.read', 'hg.create.write_on_repogroup.true']))
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
360
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
361 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
362 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
363 # 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
364 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
365 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
366 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
367 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
368 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
369 # 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
370 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
371 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
372 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
373 # 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
374 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
375 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
376 'hg.register.manual_activate',
3787
a3b1016855f8 fixed tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3734
diff changeset
377 'hg.extern_activate.auto',
3733
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
378 'repository.read', 'group.read',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
379 'usergroup.read', 'hg.create.write_on_repogroup.true']))
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
380
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
381 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
382 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
383 # 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
384 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
385 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
386 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
387 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
388 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
389
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
390 #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
391 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
392 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
393 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
394 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
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 # 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
397 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
398 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
399 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
400 # 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
401 # 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
402 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
403 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
404 'hg.register.manual_activate',
3787
a3b1016855f8 fixed tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3734
diff changeset
405 'hg.extern_activate.auto',
3733
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
406 'repository.read', 'group.read',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
407 'usergroup.read', 'hg.create.write_on_repogroup.true']))
2709
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
408
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
409 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
410 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
411 # 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
412 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
413 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
414 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
415 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
416 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
417
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
418 #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
419 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
420 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
421 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
422 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
423
d2d35cf2b351 RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
424 # 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
425 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
426 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
427 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
428 # 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
429 # 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
430 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
431 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
432 'hg.register.manual_activate',
3787
a3b1016855f8 fixed tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3734
diff changeset
433 'hg.extern_activate.auto',
3733
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
434 'repository.read', 'group.read',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
435 'usergroup.read', 'hg.create.write_on_repogroup.true']))
2864
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
436
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
437 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
438 #create repo as USER,
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
439 self.test_repo = fixture.create_repo(name='myownrepo',
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
440 repo_type='hg',
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
441 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
442
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
443 #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
444 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
445 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
446 'repository.admin')
3415
b8f929bff7e3 fixed tests and missing replacements from 5f1850e4712a
Marcin Kuzminski <marcin@python-works.com>
parents: 3053
diff changeset
447 #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
448 self.ug1 = fixture.create_user_group('G1')
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
449 UserGroupModel().add_user_to_group(self.ug1, self.u1)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
450 RepoModel().grant_user_group_permission(self.test_repo,
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
451 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
452 perm='repository.none')
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
453
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
454 Session().commit()
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
455 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
456 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
457 'repository.admin')
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
458
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
459 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
460 #create repo as USER,
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
461 self.test_repo = fixture.create_repo(name='myownrepo',
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
462 repo_type='hg',
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
463 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
464
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
465 #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
466 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
467 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
468 'repository.admin')
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
469 #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
470 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
471 perm='repository.none')
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
472 Session().commit()
5c1ad3b410e5 fixed #570 explicit users group permissions can overwrite owner permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 2820
diff changeset
473 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
474 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
475 'repository.admin')
3733
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
476
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
477 def _test_def_perm_equal(self, user, change_factor=0):
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
478 perms = UserToPerm.query()\
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
479 .filter(UserToPerm.user == user)\
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
480 .all()
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
481 self.assertEqual(len(perms),
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
482 len(Permission.DEFAULT_USER_PERMISSIONS,)+change_factor,
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
483 msg=perms)
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
484
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
485 def test_set_default_permissions(self):
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
486 PermissionModel().create_default_permissions(user=self.u1)
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
487 self._test_def_perm_equal(user=self.u1)
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
488
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
489 def test_set_default_permissions_after_one_is_missing(self):
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
490 PermissionModel().create_default_permissions(user=self.u1)
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
491 self._test_def_perm_equal(user=self.u1)
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
492 #now we delete one, it should be re-created after another call
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
493 perms = UserToPerm.query()\
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
494 .filter(UserToPerm.user == self.u1)\
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
495 .all()
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
496 Session().delete(perms[0])
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
497 Session().commit()
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
498
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
499 self._test_def_perm_equal(user=self.u1, change_factor=-1)
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
500
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
501 #create missing one !
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
502 PermissionModel().create_default_permissions(user=self.u1)
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
503 self._test_def_perm_equal(user=self.u1)
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
504
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
505 @parameterized.expand([
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
506 ('repository.read', 'repository.none'),
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
507 ('group.read', 'group.none'),
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
508 ('usergroup.read', 'usergroup.none'),
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
509 ('hg.create.repository', 'hg.create.none'),
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
510 ('hg.fork.repository', 'hg.fork.none'),
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
511 ('hg.register.manual_activate', 'hg.register.auto_activate',)
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
512 ])
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
513 def test_set_default_permissions_after_modification(self, perm, modify_to):
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
514 PermissionModel().create_default_permissions(user=self.u1)
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
515 self._test_def_perm_equal(user=self.u1)
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
516
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
517 old = Permission.get_by_key(perm)
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
518 new = Permission.get_by_key(modify_to)
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
519 self.assertNotEqual(old, None)
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
520 self.assertNotEqual(new, None)
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
521
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
522 #now modify permissions
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
523 p = UserToPerm.query()\
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
524 .filter(UserToPerm.user == self.u1)\
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
525 .filter(UserToPerm.permission == old)\
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
526 .one()
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
527 p.permission = new
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
528 Session().add(p)
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
529 Session().commit()
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
530
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
531 PermissionModel().create_default_permissions(user=self.u1)
af049a957506 fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
532 self._test_def_perm_equal(user=self.u1)