Skip to content

Commit bb89b40

Browse files
author
Richard Jones
committed
Re-enabled login and registration access...
...after lopping them off via disabling access for anonymous users. Major re-org of the htmltemplate code, cleaning it up significantly. Fixed a couple of bugs while I was there. Probably introduced a couple, but things seem to work OK at the moment.
1 parent 6f14205 commit bb89b40

File tree

6 files changed

+531
-467
lines changed

6 files changed

+531
-467
lines changed

roundup-admin

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818
#
19-
# $Id: roundup-admin,v 1.36 2001-10-21 00:45:15 richard Exp $
19+
# $Id: roundup-admin,v 1.37 2001-10-23 01:00:18 richard Exp $
2020

2121
import sys
2222
if int(sys.version[0]) < 2:
@@ -35,13 +35,13 @@ class AdminTool:
3535

3636
def __init__(self):
3737
self.commands = {}
38-
for k, v in AdminTool.__dict__.items():
38+
for k in AdminTool.__dict__.keys():
3939
if k[:3] == 'do_':
40-
self.commands[k[3:]] = v
40+
self.commands[k[3:]] = getattr(self, k)
4141
self.help = {}
42-
for k, v in AdminTool.__dict__.items():
42+
for k in AdminTool.__dict__.keys():
4343
if k[:5] == 'help_':
44-
self.help[k[5:]] = v
44+
self.help[k[5:]] = getattr(self, k)
4545

4646
def usage(message=''):
4747
if message: message = 'Problem: '+message+'\n'
@@ -133,7 +133,7 @@ Command help:
133133
'''
134134
help = self.help.get(args[0], None)
135135
if help:
136-
help(self)
136+
help()
137137
return
138138
help = self.commands.get(args[0], None)
139139
if help:
@@ -212,7 +212,11 @@ Command help:
212212
designators = string.split(args[1], ',')
213213
l = []
214214
for designator in designators:
215-
classname, nodeid = roundupdb.splitDesignator(designator)
215+
try:
216+
classname, nodeid = roundupdb.splitDesignator(designator)
217+
except roundupdb.DesignatorError, message:
218+
print 'Error: %s'%message
219+
return 1
216220
if self.comma_sep:
217221
l.append(self.db.getclass(classname).get(nodeid, propname))
218222
else:
@@ -236,7 +240,11 @@ Command help:
236240
key, value = prop.split('=')
237241
props[key] = value
238242
for designator in designators:
239-
classname, nodeid = roundupdb.splitDesignator(designator)
243+
try:
244+
classname, nodeid = roundupdb.splitDesignator(designator)
245+
except roundupdb.DesignatorError, message:
246+
print 'Error: %s'%message
247+
return 1
240248
cl = self.db.getclass(classname)
241249
properties = cl.getprops()
242250
for key, value in props.items():
@@ -427,7 +435,11 @@ Command help:
427435
428436
Lists the journal entries for the node identified by the designator.
429437
'''
430-
classname, nodeid = roundupdb.splitDesignator(args[0])
438+
try:
439+
classname, nodeid = roundupdb.splitDesignator(args[0])
440+
except roundupdb.DesignatorError, message:
441+
print 'Error: %s'%message
442+
return 1
431443
# TODO: handle the -c option?
432444
print self.db.getclass(classname).history(nodeid)
433445
return 0
@@ -441,7 +453,11 @@ Command help:
441453
'''
442454
designators = string.split(args[0], ',')
443455
for designator in designators:
444-
classname, nodeid = roundupdb.splitDesignator(designator)
456+
try:
457+
classname, nodeid = roundupdb.splitDesignator(designator)
458+
except roundupdb.DesignatorError, message:
459+
print 'Error: %s'%message
460+
return 1
445461
self.db.getclass(classname).retire(nodeid)
446462
return 0
447463

@@ -610,7 +626,7 @@ Command help:
610626

611627
# do the command
612628
try:
613-
return function(self, args[1:])
629+
return function(args[1:])
614630
finally:
615631
self.db.close()
616632

@@ -671,6 +687,9 @@ if __name__ == '__main__':
671687

672688
#
673689
# $Log: not supported by cvs2svn $
690+
# Revision 1.36 2001/10/21 00:45:15 richard
691+
# Added author identification to e-mail messages from roundup.
692+
#
674693
# Revision 1.35 2001/10/20 11:58:48 richard
675694
# Catch errors in login - no username or password supplied.
676695
# Fixed editing of password (Password property type) thanks Roch'e Compaan.

roundup/cgi_client.py

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
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.38 2001-10-22 03:25:01 richard Exp $
18+
# $Id: cgi_client.py,v 1.39 2001-10-23 01:00:18 richard Exp $
1919

2020
import os, cgi, pprint, StringIO, urlparse, re, traceback, mimetypes
2121
import base64, Cookie, time
@@ -240,8 +240,8 @@ def list(self, sort=None, group=None, filter=None, columns=None,
240240
if show_customization is None:
241241
show_customization = self.customization_widget()
242242

243-
htmltemplate.index(self, self.TEMPLATES, self.db, cn, filterspec,
244-
filter, columns, sort, group,
243+
index = htmltemplate.IndexTemplate(self, self.TEMPLATES, cn)
244+
index.render(filterspec, filter, columns, sort, group,
245245
show_customization=show_customization)
246246
self.pagefoot()
247247

@@ -276,7 +276,9 @@ def shownode(self, message=None):
276276
nodeid = self.nodeid
277277

278278
# use the template to display the item
279-
htmltemplate.item(self, self.TEMPLATES, self.db, self.classname, nodeid)
279+
item = htmltemplate.ItemTemplate(self, self.TEMPLATES, self.classname)
280+
item.render(nodeid)
281+
280282
self.pagefoot()
281283
showissue = shownode
282284
showmsg = shownode
@@ -433,8 +435,12 @@ def newnode(self, message=None):
433435
traceback.print_exc(None, s)
434436
message = '<pre>%s</pre>'%cgi.escape(s.getvalue())
435437
self.pagehead('New %s'%self.classname.capitalize(), message)
436-
htmltemplate.newitem(self, self.TEMPLATES, self.db, self.classname,
437-
self.form)
438+
439+
# call the template
440+
newitem = htmltemplate.NewItemTemplate(self, self.TEMPLATES,
441+
self.classname)
442+
newitem.render(self.form)
443+
438444
self.pagefoot()
439445
newissue = newnode
440446
newuser = newnode
@@ -466,8 +472,9 @@ def newfile(self, message=None):
466472
message = '<pre>%s</pre>'%cgi.escape(s.getvalue())
467473

468474
self.pagehead('New %s'%self.classname.capitalize(), message)
469-
htmltemplate.newitem(self, self.TEMPLATES, self.db, self.classname,
470-
self.form)
475+
newitem = htmltemplate.NewItemTemplate(self, self.TEMPLATES,
476+
self.classname)
477+
newitem.render(self.form)
471478
self.pagefoot()
472479

473480
def classes(self, message=None):
@@ -541,6 +548,7 @@ def login_action(self, message=None):
541548
password = self.form['__login_password'].value
542549
else:
543550
password = ''
551+
print self.user, password
544552
# make sure the user exists
545553
try:
546554
uid = self.db.user.lookup(self.user)
@@ -585,6 +593,10 @@ def newuser_action(self, message=None):
585593
''' create a new user based on the contents of the form and then
586594
set the cookie
587595
'''
596+
# re-open the database as "admin"
597+
self.db.close()
598+
self.db = self.instance.open('admin')
599+
588600
# TODO: pre-check the required fields and username key property
589601
cl = self.db.classes['user']
590602
props, dummy = parsePropsFromForm(self.db, cl, self.form)
@@ -626,10 +638,6 @@ def main(self, dre=re.compile(r'([^\d]+)(\d+)'),
626638
self.user = user
627639
self.db.close()
628640

629-
# make sure totally anonymous access is OK
630-
if self.ANONYMOUS_ACCESS == 'deny' and self.user is None:
631-
return self.login()
632-
633641
# re-open the database for real, using the user
634642
self.db = self.instance.open(self.user)
635643

@@ -647,18 +655,28 @@ def main(self, dre=re.compile(r'([^\d]+)(\d+)'),
647655
# appends the name of the file to the URL so the download file name
648656
# is correct, but doesn't actually use it.
649657
action = path[0]
650-
if action == 'list_classes':
651-
self.classes()
652-
return
653-
if action == 'login':
654-
self.login()
655-
return
656658
if action == 'login_action':
657659
self.login_action()
658660
return
661+
662+
# make sure anonymous are allowed to register
663+
if self.ANONYMOUS_REGISTER == 'deny' and self.user is None:
664+
return self.login()
665+
659666
if action == 'newuser_action':
660667
self.newuser_action()
661668
return
669+
670+
# make sure totally anonymous access is OK
671+
if self.ANONYMOUS_ACCESS == 'deny' and self.user is None:
672+
return self.login()
673+
674+
if action == 'list_classes':
675+
self.classes()
676+
return
677+
if action == 'login':
678+
self.login()
679+
return
662680
if action == 'logout':
663681
self.logout()
664682
return
@@ -834,6 +852,12 @@ def parsePropsFromForm(db, cl, form, nodeid=0):
834852

835853
#
836854
# $Log: not supported by cvs2svn $
855+
# Revision 1.38 2001/10/22 03:25:01 richard
856+
# Added configuration for:
857+
# . anonymous user access and registration (deny/allow)
858+
# . filter "widget" location on index page (top, bottom, both)
859+
# Updated some documentation.
860+
#
837861
# Revision 1.37 2001/10/21 07:26:35 richard
838862
# feature #473127: Filenames. I modified the file.index and htmltemplate
839863
# source so that the filename is used in the link and the creation

0 commit comments

Comments
 (0)