Edgewall Software

source: trunk/svntrac/perm.py@ 1

Last change on this file since 1 was 1, checked in by Jonas Borgström, 20 years ago

Initial import

File size: 2.6 KB
Line 
1# svntrac
2#
3# Copyright (C) 2003 Xyche Software
4#
5# svntrac is free software; you can redistribute it and/or
6# modify it under the terms of the GNU General Public License as
7# published by the Free Software Foundation; either version 2 of the
8# License, or (at your option) any later version.
9#
10# svntrac is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18#
19# Author: Jonas Borgström <jonas@xyche.com>
20
21from exceptions import StandardError
22from auth import get_authname
23from db import get_connection
24
25perm_cache = {}
26
27# permissions
28LOG_VIEW = 'LOG_VIEW'
29
30FILE_VIEW = 'FILE_VIEW'
31
32CHANGESET_VIEW = 'CHANGESET_VIEW'
33
34BROWSER_VIEW = 'BROWSER_VIEW'
35
36TICKET_VIEW = 'TICKET_VIEW'
37TICKET_CREATE = 'TICKET_CREATE'
38TICKET_MODIFY = 'TICKET_MODIFY'
39
40REPORT_VIEW = 'REPORT_VIEW'
41REPORT_CREATE = 'REPORT_CREATE'
42REPORT_MODIFY = 'REPORT_MODIFY'
43REPORT_DELETE = 'REPORT_DELETE'
44
45WIKI_VIEW = 'WIKI_VIEW'
46WIKI_CREATE = 'WIKI_CREATE'
47WIKI_MODIFY = 'WIKI_MODIFY'
48WIKI_DELETE = 'WIKI_DELETE'
49
50TIMELINE_VIEW = 'TIMELINE_VIEW'
51
52meta_permission = {
53 'TICKET_ADMIN': [TICKET_VIEW, TICKET_CREATE, TICKET_MODIFY],
54 'REPORT_ADMIN': [REPORT_VIEW, REPORT_CREATE, REPORT_MODIFY, REPORT_DELETE],
55 'WIKI_ADMIN' : [WIKI_VIEW, WIKI_CREATE, WIKI_MODIFY, WIKI_DELETE]
56 }
57
58class PermissionError (StandardError):
59 """Insufficient svntrac permissions to complete the operation"""
60 def __init__ (self, action):
61 self.action = action
62 def __str__ (self):
63 return '%s privileges required to perform this operation' % self.action
64
65def cache_permissions ():
66 global perm_cache, meta_permission
67
68 cnx = get_connection ()
69 rs = cnx.db.execute ("SELECT action FROM permission "
70 "WHERE user='%s' OR user='anonymous'" %
71 get_authname ())
72 for row in rs.row_list:
73 action = row[0]
74 if meta_permission.has_key(action):
75 map (lambda action: perm_cache.__setitem__(action, 1),
76 meta_permission[action])
77 perm_cache[action] = 1
78
79def has_permission (action):
80 global perm_cache
81 return perm_cache.has_key (action)
82
83def assert_permission (action):
84 global perm_cache
85 if not perm_cache.has_key (action):
86 raise PermissionError (action)
Note: See TracBrowser for help on using the repository browser.