[Zope-PTK] Cut and Paste of PortalContent - a hacky fix.

Steve Alexander steve@cat-box.net
Sun, 02 Jul 2000 20:02:20 +0100


Hi folks,

I've just been hacking on getting PortalContent to cut and paste.

See the Tracker report:

  http://www.zope.org/Products/PTK/Tracker/56

I'm using Zope 2.1.6, and a PTK that was from CVS at the time it got
LoginManager support, but before Membership was split off.

My apologies in advance for not using the latest CVS stuff for this.
Also, my apologies that this is long and technical and verbose.



The problem seems to be with the method "_verifyObjectPaste" in
lib/python/OFS/CopySupport.py, and its naive handling of the case when
the "action" field of the collected meta_types that pertains to the
meta_type of the object being pasted represents a path to an object.

For example, 'Wizards/NewsItem' is the action for the metatype "News
Item".

The purpose of _verifyObjectPaste is to check the pasting-user's roles
against the permissions for the constructor of the meta_type being
pasted.

The method _verifyObjectPaste assumes that this compound-path action
should really be under manage_addProduct(xxxx):

                # Handle strange names that come from the Product
                # machinery ;(
                mn=string.split(method_name, '/')
                if len(mn) > 1:
                    pname= mn[1]
                    product=self.manage_addProduct[pname]
                    fname=mn[2]
                    factory=getattr(product, fname)
                    try: meth=getattr(factory, factory.initial)
                    except: meth=factory

The first part of the path is assumed to be "manage_addProduct". In most
cases, this is ok.

I believe the correct fix would be to patch CopySupport.py to see if the
first part of the path is "manage_addProduct", and if so, do as it does
now. If not, however, is should traverse down the containment hierarchy
(repeatedly using  getattr() or whatever) to find the given action in
the ZODB. For all I know, this may be fixed in Zope 2.2.


As a quick fix to this version of PTK running on zope 2.1.6, you can
change the last statements in all PortalContent types from something
like this:

from Products.PTKBase.register import registerPortalContent
registerPortalContent(NewsItem,
                      constructors=(addNewsItem,),
                      action='Wizards/NewsItem',
                      icon="newsitem.gif")

To something like this:

from Products.PTKBase.register import registerPortalContent
registerPortalContent(NewsItem,
                      constructors=(addNewsItem,),
                      action='Wizards',
                      icon="newsitem.gif")


Note that "action='Wizards/NewsItem'" has become "action='Wizards'".

The disadvantage of this is that the permissions for pasting
PortalContent are taken from whatever permissions you happen to have on
your Wizards folder. This may be less than optimal, especially if you
want to restrict who may paste what portal-content, depending on their
role.


--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net