Mercurial > kallithea
annotate rhodecode/model/repo_permission.py @ 2433:74f2910f7ad9 codereview
Added pull requests filter into notification inbox.
- Mark all read now also marks only filtered results
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 10 Jun 2012 00:08:29 +0200 |
parents | d3ac7491a5c8 |
children | 17893d61792a |
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 |
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
|
29 from rhodecode.model.db import UserRepoToPerm, UsersGroupRepoToPerm, \ |
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 |
1593 | 37 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
|
38 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
|
39 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
|
40 |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1593
diff
changeset
|
41 return UserRepoToPerm.query() \ |
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1593
diff
changeset
|
42 .filter(UserRepoToPerm.user == user) \ |
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1593
diff
changeset
|
43 .filter(UserRepoToPerm.repository == repository) \ |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
44 .scalar() |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
45 |
1593 | 46 def update_user_permission(self, repository, user, permission): |
47 permission = Permission.get_by_key(permission) | |
48 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
|
49 if current: |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
50 if not current.permission is permission: |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
51 current.permission = permission |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
52 else: |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1593
diff
changeset
|
53 p = UserRepoToPerm() |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
54 p.user = user |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
55 p.repository = repository |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
56 p.permission = permission |
1716
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
57 self.sa.add(p) |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
58 |
1593 | 59 def delete_user_permission(self, repository, user): |
60 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
|
61 if current: |
1716
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
62 self.sa.delete(current) |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
diff
changeset
|
63 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
64 def get_users_group_permission(self, repository, users_group): |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
65 return UsersGroupRepoToPerm.query() \ |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
66 .filter(UsersGroupRepoToPerm.users_group == users_group) \ |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
67 .filter(UsersGroupRepoToPerm.repository == repository) \ |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
68 .scalar() |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
69 |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1795
diff
changeset
|
70 def update_users_group_permission(self, repository, users_group, |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
71 permission): |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
72 permission = Permission.get_by_key(permission) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
73 current = self.get_users_group_permission(repository, users_group) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
74 if current: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
75 if not current.permission is permission: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
76 current.permission = permission |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
77 else: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
78 p = UsersGroupRepoToPerm() |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
79 p.users_group = users_group |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
80 p.repository = repository |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
81 p.permission = permission |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
82 self.sa.add(p) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
83 |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
84 def delete_users_group_permission(self, repository, users_group): |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
85 current = self.get_users_group_permission(repository, users_group) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
86 if current: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
87 self.sa.delete(current) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
88 |
1593 | 89 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
|
90 if permission: |
1593 | 91 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
|
92 else: |
1593 | 93 self.delete_user_permission(repository, user) |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
94 |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
95 def update_or_delete_users_group_permission(self, repository, user_group, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
96 permission): |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
97 if permission: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
98 self.update_users_group_permission(repository, user_group, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
99 permission) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
100 else: |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1795
diff
changeset
|
101 self.delete_users_group_permission(repository, user_group) |