Skip to content

Commit 9e40158

Browse files
author
Richard Jones
committed
changes to support the new templating Unauthorised exception.
bugfix in file download fixed display of feedback messages in some situations [SF#739545]
1 parent 20ec90a commit 9e40158

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

roundup/cgi/client.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: client.py,v 1.151 2004-01-17 01:59:33 richard Exp $
1+
# $Id: client.py,v 1.152 2004-01-19 23:56:07 richard Exp $
22

33
__doc__ = """
44
WWW request handler (also used in the stand-alone server).
@@ -10,8 +10,7 @@
1010

1111
from roundup import roundupdb, date, hyperdb, password, token, rcsv
1212
from roundup.i18n import _
13-
from roundup.cgi.templating import Templates, HTMLRequest, NoTemplate
14-
from roundup.cgi import cgitb
13+
from roundup.cgi import templating, cgitb
1514
from roundup.cgi.PageTemplates import PageTemplate
1615
from roundup.rfc2822 import encode_header
1716
from roundup.mailgw import uidFromAddress
@@ -223,6 +222,9 @@ def inner_main(self):
223222
the action is cancelled, the request is rendered and an error
224223
message is displayed indicating that permission was not
225224
granted for the action to take place
225+
- templating.Unauthorised (templating action not permitted)
226+
raised by an attempted rendering of a template when the user
227+
doesn't have permission
226228
- NotFound (raised wherever it needs to be)
227229
percolates up to the CGI interface that called the client
228230
'''
@@ -272,7 +274,8 @@ def inner_main(self):
272274
self.request.send_response(304)
273275
self.request.end_headers()
274276
except Unauthorised, message:
275-
self.classname = None
277+
# users may always see the front page
278+
self.classname = self.nodeid = None
276279
self.template = ''
277280
self.error_message.append(message)
278281
self.write(self.renderContext())
@@ -413,6 +416,12 @@ def determine_context(self, dre=re.compile(r'([^\d]+)(\d+)')):
413416
error_message = self.form[key].value
414417
error_message = clean_message(error_message)
415418

419+
# see if we were passed in a message
420+
if ok_message:
421+
self.ok_message.append(ok_message)
422+
if error_message:
423+
self.error_message.append(error_message)
424+
416425
# determine the classname and possibly nodeid
417426
path = self.path.split('/')
418427
if not path or path[0] in ('', 'home', 'index'):
@@ -455,12 +464,6 @@ def determine_context(self, dre=re.compile(r'([^\d]+)(\d+)')):
455464
if template_override is not None:
456465
self.template = template_override
457466

458-
# see if we were passed in a message
459-
if ok_message:
460-
self.ok_message.append(ok_message)
461-
if error_message:
462-
self.error_message.append(error_message)
463-
464467
def serve_file(self, designator, dre=re.compile(r'([^\d]+)(\d+)')):
465468
''' Serve the file from the content property of the designated item.
466469
'''
@@ -474,9 +477,9 @@ def serve_file(self, designator, dre=re.compile(r'([^\d]+)(\d+)')):
474477

475478
# make sure we have the appropriate properties
476479
props = klass.getprops()
477-
if not pops.has_key('type'):
480+
if not props.has_key('type'):
478481
raise NotFound, designator
479-
if not pops.has_key('content'):
482+
if not props.has_key('content'):
480483
raise NotFound, designator
481484

482485
mime_type = klass.get(nodeid, 'type')
@@ -539,7 +542,8 @@ def renderContext(self):
539542
'''
540543
name = self.classname
541544
extension = self.template
542-
pt = Templates(self.instance.config.TEMPLATES).get(name, extension)
545+
pt = templating.Templates(self.instance.config.TEMPLATES).get(name,
546+
extension)
543547

544548
# catch errors so we can handle PT rendering errors more nicely
545549
args = {
@@ -551,8 +555,10 @@ def renderContext(self):
551555
result = pt.render(self, None, None, **args)
552556
self.additional_headers['Content-Type'] = pt.content_type
553557
return result
554-
except NoTemplate, message:
558+
except templating.NoTemplate, message:
555559
return '<strong>%s</strong>'%message
560+
except templating.Unauthorised, message:
561+
raise Unauthorised, str(message)
556562
except:
557563
# everything else
558564
return cgitb.pt_html()
@@ -1307,7 +1313,7 @@ def searchAction(self, wcre=re.compile(r'[\s,]+')):
13071313
# handle saving the query params
13081314
if queryname:
13091315
# parse the environment and figure what the query _is_
1310-
req = HTMLRequest(self)
1316+
req = templating.HTMLRequest(self)
13111317

13121318
# The [1:] strips off the '?' character, it isn't part of the
13131319
# query string.

0 commit comments

Comments
 (0)