comparison rhodecode/model/repo_permission.py @ 1586:2ccb32ddcfd7 beta

Add API for repositories and groups (creation, permission)
author Nicolas VINOT <aeris@imirhil.fr>
date Sun, 02 Oct 2011 17:39:52 +0200
parents
children 307ec693bdf2
comparison
equal deleted inserted replaced
1585:56276c716599 1586:2ccb32ddcfd7
1 # -*- coding: utf-8 -*-
2 """
3 rhodecode.model.users_group
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
6 repository permission model for RhodeCode
7
8 :created_on: Oct 1, 2011
9 :author: nvinot
10 :copyright: (C) 2011-2011 Nicolas Vinot <aeris@imirhil.fr>
11 :license: GPLv3, see COPYING for more details.
12 """
13 # This program is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation, either version 3 of the License, or
16 # (at your option) any later version.
17 #
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25
26 import logging
27 from rhodecode.model.db import BaseModel, RepoToPerm, Permission
28 from rhodecode.model.meta import Session
29
30 log = logging.getLogger(__name__)
31
32 class RepositoryPermissionModel(BaseModel):
33 def getUserPermission(self, repository, user):
34 return RepoToPerm.query() \
35 .filter(RepoToPerm.user == user) \
36 .filter(RepoToPerm.repository == repository) \
37 .scalar()
38
39 def updateUserPermission(self, repository, user, permission):
40 permission = Permission.get_by_key(permission)
41 current = self.getUserPermission(repository, user)
42 if current:
43 if not current.permission is permission:
44 current.permission = permission
45 else:
46 p = RepoToPerm()
47 p.user = user
48 p.repository = repository
49 p.permission = permission
50 Session.add(p)
51 Session.commit()
52
53 def deleteUserPermission(self, repository, user):
54 current = self.getUserPermission(repository, user)
55 Session.delete(current)
56 Session.commit()
57
58 def updateOrDeleteUserPermission(self, repository, user, permission):
59 if permission:
60 self.updateUserPermission(repository, user, permission)
61 else:
62 self.deleteUserPermission(repository, user)