Friday, July 17, 2009

Authenticating in the Plone debug prompt

While debugging through ./bin/instance debug, a catalog call would only yield published objects:

>>> len(site.portal_catalog(review_state='private'))

I'm sure i had more than that! There's surely some problem with authentication.

How to tell your debug instance that you are, in fact, The Man?

>>> from AccessControl.SecurityManagement import newSecurityManager
>>> admin = app.acl_users.getUser('admin')
>>> from zope.publisher.browser import TestRequest
>>> request = TestRequest()
>>> newSecurityManager(request,admin)
>>> len(site.portal_catalog(review_state='private'))

That's more like it.

You can also pass a request object to portal_catalog.searchResults, as in portal_catalog.searchResults(REQUEST=request,review_state='private').

You could also have used portal_catalog.unrestrictedSearchResults(...), as Gilles Lenfant pointed out. See Products.CMFCore.utils.CatalogTool.CatalogTool for details.

Thursday, July 16, 2009

Setup zcml from plone debug prompt

Some multiadapters are not available on the plone debug prompt by default. For an example, start an instance in debug mode and type:

site = app.plone-id
from zope.component import getMultiAdapter
from zope.publisher.browser import TestRequest
request = TestRequest()
#from Products.CMFPlone.browser.interfaces import IPlone
view = getMultiAdapter((plonesite, request), name="plone")

The above works.

However, trying to get a portlet manager to render will give an error:

context = site
provider = getMultiAdapter((context, request, view), name="plone.rightcolumn")

outputs zope.component.interfaces.ComponentLookupError: ((<PloneSite at /plone-id>, <zope.publisher.browser.TestRequest instance URL=>, <Products.Five.metaclass.Plone object at 0x6e84750>), <InterfaceClass zope.interface.Interface>, 'plone.rightcolumn')

Now try this:

from import setSite

and fetch the portlet manager again:

provider = getMultiAdapter((context, request, view), name="plone.rightcolumn")

This will return something like < object at 0xec3c110>.

Thursday, July 2, 2009

How do Plone's expiration/publication dates work?

Update 2011-11-28: Controlling permission: Access inactive portal content .

It's simple enough, but worth a summary:

  • When an item is past its expiration date, it's marked "expired" in red in its document byline when viewed.

  • An item whose publication date is before the current date doesn't get extra text in its byline.

  • In both cases, the item is "unpublished", which is not to be confused with a workflow state.

  • It merely means the item doesn't show up in listings and searches.

  • These listings include folder listings.

  • However, the owner of the item will keep seeing it, which is handy because you like to know what you have lying around in your site.

  • The permission that controls this is Access inactive portal content.

  • Expired items in a folder are marked as such when viewing the folder_contents.

  • There's no quick way of seeing if items in a folder listing are not yet published.

  • When you set an unpublished item as the default view for a folder, that item will be shown.

  • Unpublishing an item doesn't have any effect for admins. They will always see unpublished items in their listings and searches.

  • Giving another regular users rights ("can add", can edit", "can review") on the item doesn't make it any less unpublished for those users.

  • A practical way for a non-admin user to access an unpublished item is directly through its URL.