##// END OF EJS Templates
pep8: cleanup code for permissions
marcink -
r2078:b7b80022 default
parent child Browse files
Show More
@@ -1,102 +1,102 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2011-2017 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21
22 22 """
23 23 repository permission model for RhodeCode
24 24 """
25 25
26 26 import logging
27 27 from rhodecode.model import BaseModel
28 28 from rhodecode.model.db import UserRepoToPerm, UserGroupRepoToPerm, \
29 29 Permission
30 30
31 31 log = logging.getLogger(__name__)
32 32
33 33
34 34 class RepositoryPermissionModel(BaseModel):
35 35
36 36 cls = UserRepoToPerm
37 37
38 38 def get_user_permission(self, repository, user):
39 39 repository = self._get_repo(repository)
40 40 user = self._get_user(user)
41 41
42 42 return UserRepoToPerm.query() \
43 43 .filter(UserRepoToPerm.user == user) \
44 44 .filter(UserRepoToPerm.repository == repository) \
45 45 .scalar()
46 46
47 47 def update_user_permission(self, repository, user, permission):
48 48 permission = Permission.get_by_key(permission)
49 49 current = self.get_user_permission(repository, user)
50 50 if current:
51 if not current.permission is permission:
51 if current.permission is not permission:
52 52 current.permission = permission
53 53 else:
54 54 p = UserRepoToPerm()
55 55 p.user = user
56 56 p.repository = repository
57 57 p.permission = permission
58 58 self.sa.add(p)
59 59
60 60 def delete_user_permission(self, repository, user):
61 61 current = self.get_user_permission(repository, user)
62 62 if current:
63 63 self.sa.delete(current)
64 64
65 65 def get_users_group_permission(self, repository, users_group):
66 66 return UserGroupRepoToPerm.query() \
67 67 .filter(UserGroupRepoToPerm.users_group == users_group) \
68 68 .filter(UserGroupRepoToPerm.repository == repository) \
69 69 .scalar()
70 70
71 71 def update_user_group_permission(self, repository, users_group,
72 72 permission):
73 73 permission = Permission.get_by_key(permission)
74 74 current = self.get_users_group_permission(repository, users_group)
75 75 if current:
76 if not current.permission is permission:
76 if current.permission is not permission:
77 77 current.permission = permission
78 78 else:
79 79 p = UserGroupRepoToPerm()
80 80 p.users_group = users_group
81 81 p.repository = repository
82 82 p.permission = permission
83 83 self.sa.add(p)
84 84
85 85 def delete_users_group_permission(self, repository, users_group):
86 86 current = self.get_users_group_permission(repository, users_group)
87 87 if current:
88 88 self.sa.delete(current)
89 89
90 90 def update_or_delete_user_permission(self, repository, user, permission):
91 91 if permission:
92 92 self.update_user_permission(repository, user, permission)
93 93 else:
94 94 self.delete_user_permission(repository, user)
95 95
96 def update_or_delete_users_group_permission(self, repository, user_group,
97 permission):
96 def update_or_delete_users_group_permission(
97 self, repository, user_group, permission):
98 98 if permission:
99 self.update_user_group_permission(repository, user_group,
100 permission)
99 self.update_user_group_permission(
100 repository, user_group, permission)
101 101 else:
102 102 self.delete_users_group_permission(repository, user_group)
General Comments 0
You need to be logged in to leave comments. Login now