manage_permission from script
I'm trying to use manage_permission from a script against the root application object. When I do I get the following error from ObjectManager. This definitely works from within zope since I'm able to edit permissions from the ZMI. I guess the app object returned from Zope.app() doesn't have an acquisition wrapper? -EAD
app.manage_permission("View", ['Owner',], 1) Traceback (most recent call last): File "<stdin>", line 1, in ? File "/home/edahl/zope-2.7.0/lib/python/AccessControl/Role.py", line 164, in manage_permission for p in self.ac_inherited_permissions(1): File "/home/edahl/zope-2.7.0/lib/python/AccessControl/Role.py", line 82, in ac_inherited_permissions for p in self._subobject_permissions(): File "/home/edahl/zope-2.7.0/lib/python/OFS/ObjectManager.py", line 212, in _subobject_permissions return (Products.__ac_permissions__+ AttributeError: aq_acquire
For setting permission on the root application object, use setPermissionDefault of SecurityInfo. e.g. in your product: class MyClass: security = ClassSecurityInfo() security.setPermissionDefault(Permissions.view, ('Owner',)) Reagrds, Sandor
-----Original Message----- From: zope-dev-bounces@zope.org [mailto:zope-dev-bounces@zope.org] On Behalf Of Erik A.Dahl Sent: Wednesday, April 07, 2004 5:40 PM To: zope-dev@zope.org Subject: [Zope-dev] manage_permission from script
I'm trying to use manage_permission from a script against the root application object. When I do I get the following error from ObjectManager. This definitely works from within zope since I'm able to edit permissions from the ZMI. I guess the app object returned from Zope.app() doesn't have an acquisition wrapper?
-EAD
app.manage_permission("View", ['Owner',], 1) Traceback (most recent call last): File "<stdin>", line 1, in ? File "/home/edahl/zope-2.7.0/lib/python/AccessControl/Role.py", line 164, in manage_permission for p in self.ac_inherited_permissions(1): File "/home/edahl/zope-2.7.0/lib/python/AccessControl/Role.py", line 82, in ac_inherited_permissions for p in self._subobject_permissions(): File "/home/edahl/zope-2.7.0/lib/python/OFS/ObjectManager.py", line 212, in _subobject_permissions return (Products.__ac_permissions__+ AttributeError: aq_acquire
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )
For setting permission on the root application object, use setPermissionDefault of SecurityInfo.
Eh, this only works for my own defined permissions. However I just tried this from my product and it does what it supposed to do: self.getPhysicalRoot().manage_permission('View', ['Owner']) Sandor
Thanks for the suggestion but no joy here. Here is the full trace... Python 2.3.3 (#1, Jan 27 2004, 09:17:28) [GCC 3.2 20020903 (Red Hat Linux 8.0 3.2-7)] on linux2 Type "help", "copyright", "credits" or "license" for more information.
import Zope app = Zope.app() app.testfolder <Folder instance at 410d9f50> tf = app.testfolder tf.getPhysicalRoot().manage_permission("View", ["Owner",]) Traceback (most recent call last): File "<stdin>", line 1, in ? File "/home/edahl/zope-2.7.0/lib/python/AccessControl/Role.py", line 164, in manage_permission for p in self.ac_inherited_permissions(1): File "/home/edahl/zope-2.7.0/lib/python/AccessControl/Role.py", line 82, in ac_inherited_permissions for p in self._subobject_permissions(): File "/home/edahl/zope-2.7.0/lib/python/OFS/ObjectManager.py", line 212, in _subobject_permissions return (Products.__ac_permissions__+ AttributeError: aq_acquire
On Apr 7, 2004, at 7:30 PM, <zope@netchan.cotse.net> wrote:
For setting permission on the root application object, use setPermissionDefault of SecurityInfo.
Eh, this only works for my own defined permissions. However I just tried this from my product and it does what it supposed to do:
self.getPhysicalRoot().manage_permission('View', ['Owner'])
Sandor
Erik A.Dahl wrote:
Thanks for the suggestion but no joy here. Here is the full trace...
Python 2.3.3 (#1, Jan 27 2004, 09:17:28) [GCC 3.2 20020903 (Red Hat Linux 8.0 3.2-7)] on linux2 Type "help", "copyright", "credits" or "license" for more information.
import Zope app = Zope.app() app.testfolder <Folder instance at 410d9f50> tf = app.testfolder tf.getPhysicalRoot().manage_permission("View", ["Owner",]) Traceback (most recent call last): File "<stdin>", line 1, in ? File "/home/edahl/zope-2.7.0/lib/python/AccessControl/Role.py", line 164, in manage_permission for p in self.ac_inherited_permissions(1): File "/home/edahl/zope-2.7.0/lib/python/AccessControl/Role.py", line 82, in ac_inherited_permissions for p in self._subobject_permissions(): File "/home/edahl/zope-2.7.0/lib/python/OFS/ObjectManager.py", line 212, in _subobject_permissions return (Products.__ac_permissions__+ AttributeError: aq_acquire
'manage_permission' (really, the methods it calls) make the assumption (unwarranted in your case) that they are called on an acquisition-wrapped object. In your case, the root object is *not* wrapped, and therefore does not have the 'aq_acquire' method. Normally, when called via the publisher, the root object *is* wrapped (in a RequestContainer). A workaround would be to wrap the root first: zopectl> debug Starting debugger (the name "app" is bound to the top-level Zope object)
app <Application instance at 40dc1bf0> app.aq_chain # not wrapped Traceback (most recent call last): File "<stdin>", line 1, in ? AttributeError: aq_chain app.manage_addFolder( 'testfolder' ) tf = app.testfolder pr = tf.getPhysicalRoot() pr.aq_acquire Traceback (most recent call last): File "<stdin>", line 1, in ? AttributeError: aq_acquire pr = pr.__of__(tf) pr.aq_chain [<Application instance at 40dc1bf0>, <Folder instance at 40e51d10>, <Application instance at 40dc1bf0>] pr.aq_acquire <CMethod object at 0x40dfac60> manage_permission("View", ["Owner"])
The real fix would be to rip out the use *anywhere* of 'self.aq_acquire'; the 'aq_aquire' function from Acquisition will always do the Right Thing (TM) if the object is not yet wrapped (the difference parallels using 'aq_base', 'aq_parent', 'aq_inner' as functions rather than methods). Tres. -- =============================================================== Tres Seaver tseaver@zope.com Zope Corporation "Zope Dealers" http://www.zope.com
participants (3)
-
Erik A.Dahl -
Tres Seaver -
zope@netchan.cotse.net