You are here: Home / Documentation / How To's / How to change the owner of an item

How to change the owner of an item

by nguyen — published Apr 13, 2011 04:55 PM, last modified Aug 16, 2016 10:50 AM
Three methods: the plone.app.changeownership add-on, a Script (Python), and using the zopectl debug command line

The plone.app.changeownership Add-On

This is the method I recommend. Install this add-on:

http://plone.org/products/plone.app.changeownership

 

The change_owner Script (Python)

 

Using the ZMI, create a Script (Python) in the site's portal_skins/custom folder.  Call it "change_owner".

Set the parameter list to this: 

  • new_owner,recursive

where new_owner is a user ID and recursive is either 0 or 1 to indicate whether contained objects should also have their owner set to new_owner.

Here is the body of the Script (Python):

acl_users = getattr(context, 'acl_users')
user = acl_users.getUserById(new_owner)
utils = context.plone_utils
utils.changeOwnership(context, user, recursive)

context.setCreators([new_owner] + creators)

roles = list(context.get_local_roles_for_userid(new_owner))
if 'Owner' not in roles:
  roles.append('Owner')
  context.manage_setLocalRoles(new_owner, roles)

Use the Proxy tab to grant Manager role to this script.

To run the script, browse to the object for which you want to change the owner, then append

/change_owner?new_owner=someaccountid&recursive=1

so your final URL will look something like this:

http://localhost:8080/Plone/some-folder/change_owner?new_owner=someaccountid&recursive=1

When I ran it, however, it gave this error:

You are not allowed to access 'changeOwnership' in this context

I couldn't figure out why not, since I was running as a user with Manager role, so I gave up on this script. :)

Using zopectl debug 

I decided to start up a ZEO client in debug mode:

bin/client3 debug

For simple Plone setups, your command line might look like:

bin/instance debug

or

bin/zopectl debug

That gave me a prompt when it was ready, then I gave it these commands:

# bin/client3
zopectl> debug
Starting debugger (the name "app" is bound to the top-level Zope object)
>>> s=app.sites4.signup
>>> ss=getattr(s,'counseling-center')
>>> u=s.acl_users.getUserById('craanenb')
>>> u
<PloneUser 'craanenb'>
>>> ss.changeOwnership(u, recursive=1)
>>> import transaction
>>> transaction.commit()
>>> 
zopectl>

 This seemed to work.  When I browsed to the object and appended "/owner_info" it showed that the new owner of the item had been correctly set.

Coda

In the end, neither above method allowed the person to see the additional tabs and drop down menus that were expected for the person to be able to edit the item in question.  In my case I was trying to give someone the ability to edit a signup sheet created with our uwosh.timeslot product.

Instead, what worked was to use the item's sharing tab.  Normally, the uwosh.timeslot signup sheet object does not show a sharing tab, but you can get to it by appending "/@@sharing" to the object's URL.  There I granted "can add/edit/view/review" and the all-crucial "can view schedule" and "can manage schedule".  

 

 

Navigation