1515# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717#
18- # $Id: cgi_client.py,v 1.145 2002-07-26 08:26:59 richard Exp $
18+ # $Id: cgi_client.py,v 1.146 2002-07-30 05:27:30 richard Exp $
1919
2020__doc__ = """
2121WWW request handler (also used in the stand-alone server).
@@ -232,7 +232,6 @@ def pagehead(self, title, message=None):
232232<a href="user%(userid)s">My Details</a> | <a href="logout">Logout</a>
233233''' )% locals ()
234234
235-
236235 # figure the "add class" links
237236 if hasattr (self .instance , 'HEADER_ADD_LINKS' ):
238237 classes = self .instance .HEADER_ADD_LINKS
@@ -572,7 +571,8 @@ def basicClassEditPage(self):
572571 '''
573572 userid = self .db .user .lookup (self .user )
574573 if not self .db .security .hasPermission ('Edit' , userid ):
575- raise Unauthorised
574+ raise Unauthorised , _ ("You do not have permission to access" \
575+ " %(action)s." )% {'action' : self .classname }
576576 w = self .write
577577 cn = self .classname
578578 cl = self .db .classes [cn ]
@@ -951,7 +951,8 @@ def newnode(self, message=None):
951951 cn = self .classname
952952 userid = self .db .user .lookup (self .user )
953953 if not self .db .security .hasPermission ('View' , userid , cn ):
954- raise Unauthorised
954+ raise Unauthorised , _ ("You do not have permission to access" \
955+ " %(action)s." )% {'action' : self .classname }
955956 cl = self .db .classes [cn ]
956957 if self .form .has_key (':multilink' ):
957958 link = self .form [':multilink' ].value
@@ -965,7 +966,8 @@ def newnode(self, message=None):
965966 if [i for i in keys if i [0 ] != ':' ]:
966967 # no dice if you can't edit!
967968 if not self .db .security .hasPermission ('Edit' , userid , cn ):
968- raise Unauthorised
969+ raise Unauthorised , _ ("You do not have permission to access" \
970+ " %(action)s." )% {'action' : 'new' + self .classname }
969971 props = {}
970972 try :
971973 nid = self ._createnode ()
@@ -1008,7 +1010,8 @@ def newuser(self, message=None):
10081010 '''
10091011 userid = self .db .user .lookup (self .user )
10101012 if not self .db .security .hasPermission ('Edit' , userid , 'user' ):
1011- raise Unauthorised
1013+ raise Unauthorised , _ ("You do not have permission to access" \
1014+ " %(action)s." )% {'action' : 'newuser' }
10121015
10131016 cn = self .classname
10141017 cl = self .db .classes [cn ]
@@ -1046,7 +1049,8 @@ def newfile(self, message=None):
10461049 '''
10471050 userid = self .db .user .lookup (self .user )
10481051 if not self .db .security .hasPermission ('Edit' , userid , 'file' ):
1049- raise Unauthorised
1052+ raise Unauthorised , _ ("You do not have permission to access" \
1053+ " %(action)s." )% {'action' : 'newfile' }
10501054 cn = self .classname
10511055 cl = self .db .classes [cn ]
10521056 props = parsePropsFromForm (self .db , cl , self .form )
@@ -1095,14 +1099,19 @@ def showuser(self, message=None, num_re=re.compile('^\d+$')):
10951099 user = self .db .user
10961100
10971101 # get the username of the node being edited
1098- node_user = user .get (self .nodeid , 'username' )
1102+ try :
1103+ node_user = user .get (self .nodeid , 'username' )
1104+ except IndexError :
1105+ raise NotFound , 'user%s' % self .nodeid
10991106
11001107 # ok, so we need to be able to edit everything, or be this node's
11011108 # user
11021109 userid = self .db .user .lookup (self .user )
11031110 if (not self .db .security .hasPermission ('Edit' , userid )
11041111 and self .user != node_user ):
1105- raise Unauthorised
1112+ raise Unauthorised , _ ("You do not have permission to access" \
1113+ " %(action)s." )% {'action' : self .classname +
1114+ str (self .nodeid )}
11061115
11071116 #
11081117 # perform any editing
@@ -1152,7 +1161,10 @@ def showfile(self):
11521161 '''
11531162 nodeid = self .nodeid
11541163 cl = self .db .classes [self .classname ]
1155- mime_type = cl .get (nodeid , 'type' )
1164+ try :
1165+ mime_type = cl .get (nodeid , 'type' )
1166+ except IndexError :
1167+ raise NotFound , 'file%s' % nodeid
11561168 if mime_type == 'message/rfc822' :
11571169 mime_type = 'text/plain'
11581170 self .header (headers = {'Content-Type' : mime_type })
@@ -1166,8 +1178,8 @@ def classes(self, message=None):
11661178 ''' display a list of all the classes in the database
11671179 '''
11681180 userid = self .db .user .lookup (self .user )
1169- if not self . db . security . hasPermission ( 'Edit' , userid ):
1170- raise Unauthorised
1181+ raise Unauthorised , _ ( "You do not have permission to access" \
1182+ " %(action)s." ) % { 'action' : 'all classes' }
11711183
11721184 self .pagehead (_ ('Table of classes' ), message )
11731185 classnames = self .db .classes .keys ()
@@ -1188,7 +1200,9 @@ def classes(self, message=None):
11881200 def login (self , message = None , newuser_form = None , action = 'index' ):
11891201 '''Display a login page.
11901202 '''
1191- self .pagehead (_ ('Login to roundup' ), message )
1203+ self .pagehead (_ ('Login to roundup' ))
1204+ if message :
1205+ self .write ('<p class="system-msg">%s</p>' % message )
11921206 self .write (_ ('''
11931207<table>
11941208<tr><td colspan=2 class="strong-header">Existing User Login</td></tr>
@@ -1289,7 +1303,8 @@ def newuser_action(self, message=None):
12891303 # make sure we're allowed to register
12901304 userid = self .db .user .lookup (self .user )
12911305 if not self .db .security .hasPermission ('Web Registration' , userid ):
1292- raise Unauthorised
1306+ raise Unauthorised , _ ("You do not have permission to access" \
1307+ " %(action)s." )% {'action' : 'registration' }
12931308
12941309 # re-open the database as "admin"
12951310 self .opendb ('admin' )
@@ -1387,12 +1402,18 @@ def main(self):
13871402 self .desired_action = None
13881403 try :
13891404 self .main_action ()
1390- except Unauthorised :
1405+ except Unauthorised , message :
13911406 self .header (response = 403 )
13921407 if self .desired_action is None or self .desired_action == 'login' :
1393- self .login () # go to the index after login
1408+ if not message :
1409+ message = _ ("You do not have permission." )
1410+ # go to the index after login
1411+ self .login (message = message )
13941412 else :
1395- self .login (action = self .desired_action )
1413+ if not message :
1414+ message = _ ("You do not have permission to access" \
1415+ " %(action)s." )% {'action' : self .desired_action }
1416+ self .login (action = self .desired_action , message = message )
13961417
13971418 def main_action (self ):
13981419 '''Wrap the database accesses so we can close the database cleanly
@@ -1668,6 +1689,11 @@ def parsePropsFromForm(db, cl, form, nodeid=0, num_re=re.compile('^\d+$')):
16681689
16691690#
16701691# $Log: not supported by cvs2svn $
1692+ # Revision 1.145 2002/07/26 08:26:59 richard
1693+ # Very close now. The cgi and mailgw now use the new security API. The two
1694+ # templates have been migrated to that setup. Lots of unit tests. Still some
1695+ # issue in the web form for editing Roles assigned to users.
1696+ #
16711697# Revision 1.144 2002/07/25 07:14:05 richard
16721698# Bugger it. Here's the current shape of the new security implementation.
16731699# Still to do:
0 commit comments