[Zope] Permissions, files and folders

Erik Billing erik at ekhagen.org
Mon Apr 10 14:38:25 EDT 2006


Hi!

I just started looking at zope, so this might be a pretty nooby question,
but I didnt find an answere anywhere, so...

I want to create a DTML Method that lists the files in a folder that the
current user has access to. Problem is that the objectValues-method returns
all files simultaniously, so I get a
AccessControl.unauthorized.Unauthorized exception when I call the method.

I did a litle python script that iterates over the objectValues and catches
the errors raised from unauthorized files as folows:

files = []
fileIterator = iter(container.objectValues('File'))
while True:
    try:
        files.append(fileIterator.next())
    except Exception, e:
        if isinstance(e,StopIteration):
            break
        else:
            files.append(e)
return files

This works fine, except that it's a bit clumsy and has one big error; I
catch just any exception that arises from the
files.append(fileIterator.next())-call,
and swallow it. I've tried catching only the Unauthorized-exception, but an
anonymus user does not have access to the Unauthorized-exception, so I can't
specify is in my except-declaration without getting a new authorization
error. All thaw it works fine to catch all exceptions for a simple directory
listing like this, its defiantly nothing I wanna put into a larger
application.

So my question is, how do I do this in a nicer way?
Thanx /Erik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zope/attachments/20060410/ac73906d/attachment.htm


More information about the Zope mailing list