Copying objects in ZODB programmatically
I am trying to make a copy of an object in my ZODB using manage_copyObjects and manage_pasteObjects. I have code like this: import Zope app=Zope.app() x=app.manage_copyObjects([app['getad'].id]) app.manage_pasteObjects(x) This raises an exception, like so: Traceback (innermost last): File "test.py", line 9, in ? app.manage_pasteObjects(x) File "lib\python\OFS\CopySupport.py", line 203, in manage_pasteObjects self._verifyObjectPaste(ob) File "lib\python\OFS\CopySupport.py", line 393, in _verifyObjectPaste if getSecurityManager().validate(None, parent, None, meth): File "/MC2\lib\python\AccessControl\SecurityManager.py", line 139, in validate self._context) File "/MC2\lib\python\AccessControl\ZopeSecurityPolicy.py", line 211, in valid ate raise 'Unauthorized', ( Unauthorized: You are not authorized to access <em>methodAdd</em>. However, I cannot see how to have my script authenticate itself to the ZODB so I can do the copy/paste. Can anyone tell me what I need to do here? Do I need to use Zope.AccessControl.SecurityManagement.newSecurityManager somehow? I'm using Zope 2.2.4, which for reasons too long to go into here I cannot change. Thanks in advance, Noel. -- Noel Duffy Tel: +353 96 36038 Fax: +353 96 36353
Hmm... why do you "import Zope" -- do you want to manipulate the ZODB from outside of Zope? On Fri, 12 Apr 2002, Noel Duffy wrote:
I am trying to make a copy of an object in my ZODB using manage_copyObjects and manage_pasteObjects. I have code like this:
import Zope app=Zope.app() x=app.manage_copyObjects([app['getad'].id]) app.manage_pasteObjects(x)
This raises an exception, like so:
Traceback (innermost last): File "test.py", line 9, in ? app.manage_pasteObjects(x) File "lib\python\OFS\CopySupport.py", line 203, in manage_pasteObjects self._verifyObjectPaste(ob) File "lib\python\OFS\CopySupport.py", line 393, in _verifyObjectPaste if getSecurityManager().validate(None, parent, None, meth): File "/MC2\lib\python\AccessControl\SecurityManager.py", line 139, in validate
self._context) File "/MC2\lib\python\AccessControl\ZopeSecurityPolicy.py", line 211, in valid ate raise 'Unauthorized', ( Unauthorized: You are not authorized to access <em>methodAdd</em>.
However, I cannot see how to have my script authenticate itself to the ZODB so I can do the copy/paste. Can anyone tell me what I need to do here? Do I need to use Zope.AccessControl.SecurityManagement.newSecurityManager somehow?
I'm using Zope 2.2.4, which for reasons too long to go into here I cannot change.
Thanks in advance,
Noel.
Noel Duffy writes:
I am trying to make a copy of an object in my ZODB using manage_copyObjects and manage_pasteObjects. I have code like this:
import Zope app=Zope.app() x=app.manage_copyObjects([app['getad'].id]) app.manage_pasteObjects(x) "manage_pasteObjects" (more precisely, "_verifyObjectPaste" performs its own security check, even if called in an unrestricted environment.
As in your context, there is not user, the check fails. I see two options: * modify Zope's code (e.g. by adding a new "manage_pasteObjects_woCheck" without this check) * create a request object with authentication information, perform a "traverse" on this object (this will set the user) and then call "manage_pasteObjects" on the traverse to object. Dieter
On Friday 12 April 2002 21:06, Dieter Maurer wrote:
Noel Duffy writes:
I am trying to make a copy of an object in my ZODB using manage_copyObjects and manage_pasteObjects. I have code like this:
import Zope app=Zope.app() x=app.manage_copyObjects([app['getad'].id]) app.manage_pasteObjects(x)
"manage_pasteObjects" (more precisely, "_verifyObjectPaste" performs its own security check, even if called in an unrestricted environment.
As in your context, there is not user, the check fails.
I see two options:
* modify Zope's code (e.g. by adding a new "manage_pasteObjects_woCheck" without this check)
* create a request object with authentication information, perform a "traverse" on this object (this will set the user) and then call "manage_pasteObjects" on the traverse to object.
Thanks for the quick reply. Do you have an example of how one would do this, as I cannot quite picture in my head how this should be approached? Thanks again, Noel.
Noel Duffy writes:
* create a request object with authentication information, perform a "traverse" on this object (this will set the user) and then call "manage_pasteObjects" on the traverse to object.
Thanks for the quick reply.
Do you have an example of how one would do this, as I cannot quite picture in my head how this should be approached? Attached...
You would use it in the form: from request import getAuthRequest R=getAuthRequest() # your authenticated request object (sure, you modified USER and PASSWORD!) o= R.traverse(URL) # the (site relative) URL of the object you want to reach # whatever you want to do with "o" Dieter
participants (4)
-
Dieter Maurer -
Noel Duffy -
Noel Duffy -
Peter Sabaini