Mercurial > kallithea
annotate rhodecode/model/permission.py @ 3852:eae62e28343e beta
handle case of rewrite without an gistid in nginx example
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 12 May 2013 17:19:21 +0200 |
parents | 222e6769e7b5 |
children | 7aa0ff5b4e09 |
rev | line source |
---|---|
759
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
1 # -*- coding: utf-8 -*- |
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
2 """ |
811 | 3 rhodecode.model.permission |
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
5 |
759
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
6 permissions model for RhodeCode |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
7 |
759
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
8 :created_on: Aug 20, 2010 |
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
9 :author: marcink |
1824
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com> |
759
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
11 :license: GPLv3, see COPYING for more details. |
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
12 """ |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
13 # This program is free software: you can redistribute it and/or modify |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
14 # it under the terms of the GNU General Public License as published by |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
15 # the Free Software Foundation, either version 3 of the License, or |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
16 # (at your option) any later version. |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
17 # |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 # This program is distributed in the hope that it will be useful, |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 # GNU General Public License for more details. |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
22 # |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 # You should have received a copy of the GNU General Public License |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
24 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
759
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
25 |
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
26 import logging |
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
27 import traceback |
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
28 |
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
29 from sqlalchemy.exc import DatabaseError |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
30 |
752
89b9037d68b7
fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents:
751
diff
changeset
|
31 from rhodecode.model import BaseModel |
2425
a970b6e7c5a2
Update permissions from admin permissions menu, also overwrites defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
32 from rhodecode.model.db import User, Permission, UserToPerm, UserRepoToPerm,\ |
3735
8a40028eaf73
fixed overwrite default user group permission flag
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
33 UserRepoGroupToPerm, UserUserGroupToPerm |
3730
e42e1d4e1c47
make the permission update function idempotent
Marcin Kuzminski <marcin@python-works.com>
parents:
3625
diff
changeset
|
34 from rhodecode.lib.utils2 import str2bool |
1669
f522f4d3bf93
moved caching query to libs
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
35 |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 log = logging.getLogger(__name__) |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 |
752
89b9037d68b7
fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents:
751
diff
changeset
|
39 class PermissionModel(BaseModel): |
1716
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1669
diff
changeset
|
40 """ |
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1669
diff
changeset
|
41 Permissions model for RhodeCode |
811 | 42 """ |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
43 |
2522
17893d61792a
Added associated classes into child models
Marcin Kuzminski <marcin@python-works.com>
parents:
2425
diff
changeset
|
44 cls = Permission |
17893d61792a
Added associated classes into child models
Marcin Kuzminski <marcin@python-works.com>
parents:
2425
diff
changeset
|
45 |
3734
a8f520540ab0
New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents:
3733
diff
changeset
|
46 def create_permissions(self): |
a8f520540ab0
New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents:
3733
diff
changeset
|
47 """ |
a8f520540ab0
New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents:
3733
diff
changeset
|
48 Create permissions for whole system |
a8f520540ab0
New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents:
3733
diff
changeset
|
49 """ |
a8f520540ab0
New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents:
3733
diff
changeset
|
50 for p in Permission.PERMS: |
a8f520540ab0
New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents:
3733
diff
changeset
|
51 if not Permission.get_by_key(p[0]): |
a8f520540ab0
New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents:
3733
diff
changeset
|
52 new_perm = Permission() |
a8f520540ab0
New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents:
3733
diff
changeset
|
53 new_perm.permission_name = p[0] |
a8f520540ab0
New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents:
3733
diff
changeset
|
54 new_perm.permission_longname = p[0] #translation err with p[1] |
a8f520540ab0
New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents:
3733
diff
changeset
|
55 self.sa.add(new_perm) |
a8f520540ab0
New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents:
3733
diff
changeset
|
56 |
3733
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
57 def create_default_permissions(self, user): |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
58 """ |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
59 Creates only missing default permissions for user |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
60 |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
61 :param user: |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
62 """ |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
63 user = self._get_user(user) |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
64 |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
65 def _make_perm(perm): |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
66 new_perm = UserToPerm() |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
67 new_perm.user = user |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
68 new_perm.permission = Permission.get_by_key(perm) |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
69 return new_perm |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
70 |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
71 def _get_group(perm_name): |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
72 return '.'.join(perm_name.split('.')[:1]) |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
73 |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
74 perms = UserToPerm.query().filter(UserToPerm.user == user).all() |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
75 defined_perms_groups = map(_get_group, |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
76 (x.permission.permission_name for x in perms)) |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
77 log.debug('GOT ALREADY DEFINED:%s' % perms) |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
78 DEFAULT_PERMS = Permission.DEFAULT_USER_PERMISSIONS |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
79 |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
80 # for every default permission that needs to be created, we check if |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
81 # it's group is already defined, if it's not we create default perm |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
82 for perm_name in DEFAULT_PERMS: |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
83 gr = _get_group(perm_name) |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
84 if gr not in defined_perms_groups: |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
85 log.debug('GR:%s not found, creating permission %s' |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
86 % (gr, perm_name)) |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
87 new_perm = _make_perm(perm_name) |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
88 self.sa.add(new_perm) |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
89 |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
90 def update(self, form_result): |
3730
e42e1d4e1c47
make the permission update function idempotent
Marcin Kuzminski <marcin@python-works.com>
parents:
3625
diff
changeset
|
91 perm_user = User.get_by_username(username=form_result['perm_user_name']) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
92 |
418
63c697d1a631
added logic for changin defualt permissions, and option to overwrite all defualt permissions on each repository
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
93 try: |
3733
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
94 # stage 1 set anonymous access |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
95 if perm_user.username == 'default': |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
96 perm_user.active = str2bool(form_result['anonymous']) |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
97 self.sa.add(perm_user) |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
98 |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
99 # stage 2 reset defaults and set them from form data |
3730
e42e1d4e1c47
make the permission update function idempotent
Marcin Kuzminski <marcin@python-works.com>
parents:
3625
diff
changeset
|
100 def _make_new(usr, perm_name): |
3734
a8f520540ab0
New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents:
3733
diff
changeset
|
101 log.debug('Creating new permission:%s' % (perm_name)) |
3730
e42e1d4e1c47
make the permission update function idempotent
Marcin Kuzminski <marcin@python-works.com>
parents:
3625
diff
changeset
|
102 new = UserToPerm() |
e42e1d4e1c47
make the permission update function idempotent
Marcin Kuzminski <marcin@python-works.com>
parents:
3625
diff
changeset
|
103 new.user = usr |
e42e1d4e1c47
make the permission update function idempotent
Marcin Kuzminski <marcin@python-works.com>
parents:
3625
diff
changeset
|
104 new.permission = Permission.get_by_key(perm_name) |
e42e1d4e1c47
make the permission update function idempotent
Marcin Kuzminski <marcin@python-works.com>
parents:
3625
diff
changeset
|
105 return new |
e42e1d4e1c47
make the permission update function idempotent
Marcin Kuzminski <marcin@python-works.com>
parents:
3625
diff
changeset
|
106 # clear current entries, to make this function idempotent |
e42e1d4e1c47
make the permission update function idempotent
Marcin Kuzminski <marcin@python-works.com>
parents:
3625
diff
changeset
|
107 # it will fix even if we define more permissions or permissions |
e42e1d4e1c47
make the permission update function idempotent
Marcin Kuzminski <marcin@python-works.com>
parents:
3625
diff
changeset
|
108 # are somehow missing |
3733
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
109 u2p = self.sa.query(UserToPerm)\ |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
110 .filter(UserToPerm.user == perm_user)\ |
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
111 .all() |
418
63c697d1a631
added logic for changin defualt permissions, and option to overwrite all defualt permissions on each repository
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
112 for p in u2p: |
3730
e42e1d4e1c47
make the permission update function idempotent
Marcin Kuzminski <marcin@python-works.com>
parents:
3625
diff
changeset
|
113 self.sa.delete(p) |
e42e1d4e1c47
make the permission update function idempotent
Marcin Kuzminski <marcin@python-works.com>
parents:
3625
diff
changeset
|
114 #create fresh set of permissions |
e42e1d4e1c47
make the permission update function idempotent
Marcin Kuzminski <marcin@python-works.com>
parents:
3625
diff
changeset
|
115 for def_perm_key in ['default_repo_perm', 'default_group_perm', |
3734
a8f520540ab0
New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents:
3733
diff
changeset
|
116 'default_user_group_perm', |
a8f520540ab0
New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents:
3733
diff
changeset
|
117 'default_repo_create', |
a8f520540ab0
New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents:
3733
diff
changeset
|
118 #'default_repo_group_create', #not implemented yet |
a8f520540ab0
New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents:
3733
diff
changeset
|
119 'default_user_group_create', |
3786
222e6769e7b5
Added separate default permission for external_auth account
Marcin Kuzminski <marcin@python-works.com>
parents:
3735
diff
changeset
|
120 'default_fork', 'default_register', |
222e6769e7b5
Added separate default permission for external_auth account
Marcin Kuzminski <marcin@python-works.com>
parents:
3735
diff
changeset
|
121 'default_extern_activate']: |
3730
e42e1d4e1c47
make the permission update function idempotent
Marcin Kuzminski <marcin@python-works.com>
parents:
3625
diff
changeset
|
122 p = _make_new(perm_user, form_result[def_perm_key]) |
e42e1d4e1c47
make the permission update function idempotent
Marcin Kuzminski <marcin@python-works.com>
parents:
3625
diff
changeset
|
123 self.sa.add(p) |
2709
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
124 |
3733
af049a957506
fixed default permissions population during upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
3730
diff
changeset
|
125 #stage 3 update all default permissions for repos if checked |
3052
d3200c58764e
implemented #663 Admin/permission: specify default repogroup perms
Marcin Kuzminski <marcin@python-works.com>
parents:
2798
diff
changeset
|
126 if form_result['overwrite_default_repo'] == True: |
d3200c58764e
implemented #663 Admin/permission: specify default repogroup perms
Marcin Kuzminski <marcin@python-works.com>
parents:
2798
diff
changeset
|
127 _def_name = form_result['default_repo_perm'].split('repository.')[-1] |
3730
e42e1d4e1c47
make the permission update function idempotent
Marcin Kuzminski <marcin@python-works.com>
parents:
3625
diff
changeset
|
128 _def = Permission.get_by_key('repository.' + _def_name) |
2425
a970b6e7c5a2
Update permissions from admin permissions menu, also overwrites defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
129 # repos |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1271
diff
changeset
|
130 for r2p in self.sa.query(UserRepoToPerm)\ |
2425
a970b6e7c5a2
Update permissions from admin permissions menu, also overwrites defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
131 .filter(UserRepoToPerm.user == perm_user)\ |
a970b6e7c5a2
Update permissions from admin permissions menu, also overwrites defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
132 .all(): |
3220
9e76876a0690
Global permission update with "overwrite existing settings" shouldn't override private repositories.
Marcin Kuzminski <marcin@python-works.com>
parents:
3052
diff
changeset
|
133 |
9e76876a0690
Global permission update with "overwrite existing settings" shouldn't override private repositories.
Marcin Kuzminski <marcin@python-works.com>
parents:
3052
diff
changeset
|
134 #don't reset PRIVATE repositories |
3625
260a7a01b054
follow Python conventions for boolean values
Mads Kiilerich <madski@unity3d.com>
parents:
3220
diff
changeset
|
135 if not r2p.repository.private: |
3220
9e76876a0690
Global permission update with "overwrite existing settings" shouldn't override private repositories.
Marcin Kuzminski <marcin@python-works.com>
parents:
3052
diff
changeset
|
136 r2p.permission = _def |
9e76876a0690
Global permission update with "overwrite existing settings" shouldn't override private repositories.
Marcin Kuzminski <marcin@python-works.com>
parents:
3052
diff
changeset
|
137 self.sa.add(r2p) |
3052
d3200c58764e
implemented #663 Admin/permission: specify default repogroup perms
Marcin Kuzminski <marcin@python-works.com>
parents:
2798
diff
changeset
|
138 |
d3200c58764e
implemented #663 Admin/permission: specify default repogroup perms
Marcin Kuzminski <marcin@python-works.com>
parents:
2798
diff
changeset
|
139 if form_result['overwrite_default_group'] == True: |
d3200c58764e
implemented #663 Admin/permission: specify default repogroup perms
Marcin Kuzminski <marcin@python-works.com>
parents:
2798
diff
changeset
|
140 _def_name = form_result['default_group_perm'].split('group.')[-1] |
2425
a970b6e7c5a2
Update permissions from admin permissions menu, also overwrites defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
141 # groups |
3730
e42e1d4e1c47
make the permission update function idempotent
Marcin Kuzminski <marcin@python-works.com>
parents:
3625
diff
changeset
|
142 _def = Permission.get_by_key('group.' + _def_name) |
2425
a970b6e7c5a2
Update permissions from admin permissions menu, also overwrites defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
143 for g2p in self.sa.query(UserRepoGroupToPerm)\ |
a970b6e7c5a2
Update permissions from admin permissions menu, also overwrites defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
144 .filter(UserRepoGroupToPerm.user == perm_user)\ |
a970b6e7c5a2
Update permissions from admin permissions menu, also overwrites defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
145 .all(): |
a970b6e7c5a2
Update permissions from admin permissions menu, also overwrites defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
146 g2p.permission = _def |
a970b6e7c5a2
Update permissions from admin permissions menu, also overwrites defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
147 self.sa.add(g2p) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
148 |
3735
8a40028eaf73
fixed overwrite default user group permission flag
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
149 if form_result['overwrite_default_user_group'] == True: |
8a40028eaf73
fixed overwrite default user group permission flag
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
150 _def_name = form_result['default_user_group_perm'].split('usergroup.')[-1] |
8a40028eaf73
fixed overwrite default user group permission flag
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
151 # groups |
8a40028eaf73
fixed overwrite default user group permission flag
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
152 _def = Permission.get_by_key('usergroup.' + _def_name) |
8a40028eaf73
fixed overwrite default user group permission flag
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
153 for g2p in self.sa.query(UserUserGroupToPerm)\ |
8a40028eaf73
fixed overwrite default user group permission flag
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
154 .filter(UserUserGroupToPerm.user == perm_user)\ |
8a40028eaf73
fixed overwrite default user group permission flag
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
155 .all(): |
8a40028eaf73
fixed overwrite default user group permission flag
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
156 g2p.permission = _def |
8a40028eaf73
fixed overwrite default user group permission flag
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
157 self.sa.add(g2p) |
8a40028eaf73
fixed overwrite default user group permission flag
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
158 |
3730
e42e1d4e1c47
make the permission update function idempotent
Marcin Kuzminski <marcin@python-works.com>
parents:
3625
diff
changeset
|
159 self.sa.commit() |
759
a7f50911a945
Models code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
160 except (DatabaseError,): |
418
63c697d1a631
added logic for changin defualt permissions, and option to overwrite all defualt permissions on each repository
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
161 log.error(traceback.format_exc()) |
3730
e42e1d4e1c47
make the permission update function idempotent
Marcin Kuzminski <marcin@python-works.com>
parents:
3625
diff
changeset
|
162 self.sa.rollback() |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
163 raise |