Skip to content

Commit 30727c4

Browse files
author
Richard Jones
committed
tweaks to last patch
1 parent 52b802a commit 30727c4

File tree

1 file changed

+23
-30
lines changed

1 file changed

+23
-30
lines changed

roundup/cgi/client.py

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: client.py,v 1.204 2004-11-21 13:27:03 a1s Exp $
1+
# $Id: client.py,v 1.205 2004-11-21 21:55:03 richard Exp $
22

33
"""WWW request handler (also used in the stand-alone server).
44
"""
@@ -219,9 +219,6 @@ def inner_main(self):
219219
self.determine_user()
220220

221221
# figure out the context and desired content template
222-
# do this first so we don't authenticate for static files
223-
# Note: this method opens the database as "admin" in order to
224-
# perform context checks
225222
self.determine_context()
226223

227224
# possibly handle a form submit action (may change self.classname
@@ -432,6 +429,28 @@ def determine_user(self):
432429
# reopen the database as the correct user
433430
self.opendb(self.user)
434431

432+
def opendb(self, username):
433+
''' Open the database and set the current user.
434+
435+
Opens a database once. On subsequent calls only the user is set on
436+
the database object the instance.optimize is set. If we are in
437+
"Development Mode" (cf. roundup_server) then the database is always
438+
re-opened.
439+
'''
440+
# don't do anything if the db is open and the user has not changed
441+
if hasattr(self, 'db') and self.db.isCurrentUser(username):
442+
return
443+
444+
# open the database or only set the user
445+
if not hasattr(self, 'db'):
446+
self.db = self.instance.open(username)
447+
else:
448+
if self.instance.optimize:
449+
self.db.setCurrentUser(username)
450+
else:
451+
self.db.close()
452+
self.db = self.instance.open(username)
453+
435454
def determine_context(self, dre=re.compile(r'([^\d]+)0*(\d+)')):
436455
"""Determine the context of this page from the URL:
437456
@@ -510,9 +529,6 @@ def determine_context(self, dre=re.compile(r'([^\d]+)0*(\d+)')):
510529
# send the file identified by the designator in path[0]
511530
raise SendFile, path[0]
512531

513-
# we need the db for further context stuff - open it as admin
514-
self.opendb('admin')
515-
516532
# see if we got a designator
517533
m = dre.match(self.classname)
518534
if m:
@@ -544,7 +560,6 @@ def serve_file(self, designator, dre=re.compile(r'([^\d]+)(\d+)')):
544560
raise NotFound, str(designator)
545561
classname, nodeid = m.group(1), m.group(2)
546562

547-
self.opendb('admin')
548563
klass = self.db.getclass(classname)
549564

550565
# make sure we have the appropriate properties
@@ -822,28 +837,6 @@ def make_user_anonymous(self):
822837
self.userid = self.db.user.lookup('anonymous')
823838
self.user = 'anonymous'
824839

825-
def opendb(self, username):
826-
''' Open the database and set the current user.
827-
828-
Opens a database once. On subsequent calls only the user is set on
829-
the database object the instance.optimize is set. If we are in
830-
"Development Mode" (cf. roundup_server) then the database is always
831-
re-opened.
832-
'''
833-
# don't do anything if the db is open and the user has not changed
834-
if hasattr(self, 'db') and self.db.isCurrentUser(username):
835-
return
836-
837-
# open the database or only set the user
838-
if not hasattr(self, 'db'):
839-
self.db = self.instance.open(username)
840-
else:
841-
if self.instance.optimize:
842-
self.db.setCurrentUser(username)
843-
else:
844-
self.db.close()
845-
self.db = self.instance.open(username)
846-
847840
def standard_message(self, to, subject, body, author=None):
848841
'''Send a standard email message from Roundup.
849842

0 commit comments

Comments
 (0)