[Zope] allow access to fileobject depending on role

leandros van den berg l.vandenberg at geo.uu.nl
Thu Jun 15 09:48:51 EDT 2006


Jonathan wrote:
  > Try something like:
> 
> fileObj = context.restrictedTraverse('/folderA/folderB/printsbestand.pdf')
> fileData = context.printsbestand()
> fileObj.update_data(fileData, content_type='application/pdf', 
> size=len(fileData) )
> 
> Warning: untested!
> Look in the ZopeBook for more info.
> 
> hth
> 
> Jonathan
> 

Yes! After getting an Unauthorized exception in Zope because I used a 
Python script and the method updata_data has permission Python only, I 
switched to an External Method. The new file is beeing uploaded, or 
updated if it already exists, and the assigned security roles are kept 
intact. This is how the external method turned out:

def uploadPdf(self):
    fileDir = '/bla/bla/'
    fileName = 'file.pdf'
    path_list = self.getPhysicalPath()
    path = "/".join(path_list) + "/" + fileName
    f = open(fileDir + fileName)
    fileBody = f.read()
    f.close

    try:
       self.manage_addFile(fileName, fileBody, 
content_type='application/pdf')
    except:
       fileObj = self.restrictedTraverse(path)
       fileObj.update_data(fileBody, content_type='application/pdf', 
size=len(fileBody))


Greetings,

Leandros




More information about the Zope mailing list