Mercurial > kallithea
annotate rhodecode/model/repo_permission.py @ 3882:2c5ceb546234 beta
renamed gists routing to proper plural names
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 20 May 2013 21:40:00 +0200 |
parents | fa6ba6727475 |
children | 3563bb7b4b82 |
rev | line source |
---|---|
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
2 """ |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
3 rhodecode.model.users_group |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
5 |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
6 repository permission model for RhodeCode |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
7 |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
8 :created_on: Oct 1, 2011 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
9 :author: nvinot, marcink |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
10 :copyright: (C) 2011-2011 Nicolas Vinot <aeris@imirhil.fr> |
1824
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
11 :copyright: (C) 2011-2012 Marcin Kuzminski <marcin@python-works.com> |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
12 :license: GPLv3, see COPYING for more details. |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
13 """ |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
14 # This program is free software: you can redistribute it and/or modify |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
15 # it under the terms of the GNU General Public License as published by |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
16 # the Free Software Foundation, either version 3 of the License, or |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
17 # (at your option) any later version. |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
18 # |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
19 # This program is distributed in the hope that it will be useful, |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
22 # GNU General Public License for more details. |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
23 # |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
24 # You should have received a copy of the GNU General Public License |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
25 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
26 |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
27 import logging |
1716
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
28 from rhodecode.model import BaseModel |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
2522
diff
changeset
|
29 from rhodecode.model.db import UserRepoToPerm, UserGroupRepoToPerm, \ |
2432
d3ac7491a5c8
Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
30 Permission |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
31 |
1593 | 32 log = logging.getLogger(__name__) |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
33 |
1716
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
34 |
1593 | 35 class RepositoryPermissionModel(BaseModel): |
1716
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
36 |
2522
17893d61792a
Added associated classes into child models
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
37 cls = UserRepoToPerm |
17893d61792a
Added associated classes into child models
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
38 |
1593 | 39 def get_user_permission(self, repository, user): |
2432
d3ac7491a5c8
Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
40 repository = self._get_repo(repository) |
d3ac7491a5c8
Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
41 user = self._get_user(user) |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
42 |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1593
diff
changeset
|
43 return UserRepoToPerm.query() \ |
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1593
diff
changeset
|
44 .filter(UserRepoToPerm.user == user) \ |
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1593
diff
changeset
|
45 .filter(UserRepoToPerm.repository == repository) \ |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
46 .scalar() |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
47 |
1593 | 48 def update_user_permission(self, repository, user, permission): |
49 permission = Permission.get_by_key(permission) | |
50 current = self.get_user_permission(repository, user) | |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
51 if current: |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
52 if not current.permission is permission: |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
53 current.permission = permission |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
54 else: |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1593
diff
changeset
|
55 p = UserRepoToPerm() |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
56 p.user = user |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
57 p.repository = repository |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
58 p.permission = permission |
1716
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
59 self.sa.add(p) |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
60 |
1593 | 61 def delete_user_permission(self, repository, user): |
62 current = self.get_user_permission(repository, user) | |
1589
307ec693bdf2
[API] Create groups needed when creating repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
63 if current: |
1716
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
64 self.sa.delete(current) |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
65 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
66 def get_users_group_permission(self, repository, users_group): |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
2522
diff
changeset
|
67 return UserGroupRepoToPerm.query() \ |
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
2522
diff
changeset
|
68 .filter(UserGroupRepoToPerm.users_group == users_group) \ |
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
2522
diff
changeset
|
69 .filter(UserGroupRepoToPerm.repository == repository) \ |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
70 .scalar() |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
71 |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1795
diff
changeset
|
72 def update_users_group_permission(self, repository, users_group, |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
73 permission): |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
74 permission = Permission.get_by_key(permission) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
75 current = self.get_users_group_permission(repository, users_group) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
76 if current: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
77 if not current.permission is permission: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
78 current.permission = permission |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
79 else: |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
2522
diff
changeset
|
80 p = UserGroupRepoToPerm() |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
81 p.users_group = users_group |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
82 p.repository = repository |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
83 p.permission = permission |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
84 self.sa.add(p) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
85 |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
86 def delete_users_group_permission(self, repository, users_group): |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
87 current = self.get_users_group_permission(repository, users_group) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
88 if current: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
89 self.sa.delete(current) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
90 |
1593 | 91 def update_or_delete_user_permission(self, repository, user, permission): |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
92 if permission: |
1593 | 93 self.update_user_permission(repository, user, permission) |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
94 else: |
1593 | 95 self.delete_user_permission(repository, user) |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
96 |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
97 def update_or_delete_users_group_permission(self, repository, user_group, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
98 permission): |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
99 if permission: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
100 self.update_users_group_permission(repository, user_group, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
101 permission) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
102 else: |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1795
diff
changeset
|
103 self.delete_users_group_permission(repository, user_group) |