Quantcast

invokeFactory throws Unauthorized

classic Classic list List threaded Threaded
4 messages Options
Eemeli Kantola Eemeli Kantola
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

invokeFactory throws Unauthorized

Hi All,

I've been struggling with a permission problem with my custom view
(Plone 3.3.1). I created a form, backed by
ImportEventsView(BrowserView) that would be used for batch-adding
Events to a Folder, but for some reason that doesn't work and gives
"Unauthorized: Cannot create Event":

Traceback (innermost last):
  Module ZPublisher.Publish, line 110, in publish
  Module ZPublisher.BaseRequest, line 488, in traverse
  Module ZPublisher.BaseRequest, line 314, in traverseName
  Module zope.traversing.namespace, line 109, in namespaceLookup
  Module zope.traversing.namespace, line 340, in traverse
  Module zope.component._api, line 114, in queryMultiAdapter
  Module zope.component.registry, line 206, in queryMultiAdapter
  Module zope.interface.adapter, line 482, in queryMultiAdapter
  Module Products.TestProduct.browser.importer, line 38, in __init__
  Module Products.TestProduct.browser.importer, line 48, in _import
  Module Products.TestProduct.browser.importer, line 162, in
quickAddCalendarEvent
  Module Products.CMFCore.PortalFolder, line 315, in invokeFactory
  Module Products.CMFCore.TypesTool, line 716, in constructContent
  Module Products.CMFCore.TypesTool, line 274, in constructInstance
Unauthorized: Cannot create Event

The relevant parts of the conf and code are:

- configure.zcml:
   <browser:page
      for="Products.CMFCore.interfaces.IFolderish"
      name="import_test"
      class=".importer.ImportEventsView"
      template="import_events.pt"
      permission="cmf.AddPortalContent"allowed_attributes="get_imported"
      />

- importer.py, line 162 (the one that causes the error):
self.context.invokeFactory('Event', id=id, title=title,
startDate=startDate, endDate=endDate)

After playing with the Python console a bit, I figured out that the
cause is in isConstructionAllowed(...) on line 421 of
Products/CMFCore/TypesTool.py, where queryUtility returns None:
m = queryUtility(IFactory, self.factory, None)
if m is not None:
    ...

I have probably missed something in the docs, but can't figure out
what, and googling didn't help yet. The full source code for the
product is in <http://pakki-dev.papa.partio.fi/svn/pakki/buildout/trunk/src/Products.TestProduct>,
if that helps.

Thanks!
-Eemeli

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Plone-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
Carsten Senger Carsten Senger
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: invokeFactory throws Unauthorized

Hi Eemeli,

--On Mittwoch, Oktober 21, 2009 00:37:52 +0300 Eemeli Kantola
<[hidden email]> wrote:

> Hi All,
>
> I've been struggling with a permission problem with my custom view
> (Plone 3.3.1). I created a form, backed by
> ImportEventsView(BrowserView) that would be used for batch-adding
> Events to a Folder, but for some reason that doesn't work and gives
> "Unauthorized: Cannot create Event":
>
> Traceback (innermost last):
>   Module ZPublisher.Publish, line 110, in publish
>   Module ZPublisher.BaseRequest, line 488, in traverse
>   Module ZPublisher.BaseRequest, line 314, in traverseName
>   Module zope.traversing.namespace, line 109, in namespaceLookup
>   Module zope.traversing.namespace, line 340, in traverse
>   Module zope.component._api, line 114, in queryMultiAdapter
>   Module zope.component.registry, line 206, in queryMultiAdapter
>   Module zope.interface.adapter, line 482, in queryMultiAdapter
>   Module Products.TestProduct.browser.importer, line 38, in __init__
>   Module Products.TestProduct.browser.importer, line 48, in _import
>   Module Products.TestProduct.browser.importer, line 162, in
> quickAddCalendarEvent
>   Module Products.CMFCore.PortalFolder, line 315, in invokeFactory
>   Module Products.CMFCore.TypesTool, line 716, in constructContent
>   Module Products.CMFCore.TypesTool, line 274, in constructInstance
> Unauthorized: Cannot create Event

Authorization is not finished during __init__. Call _import from
__call__ or a method you call from the template.

..Carsten

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Plone-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
Dieter Maurer Dieter Maurer
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: invokeFactory throws Unauthorized

In reply to this post by Eemeli Kantola
Eemeli Kantola wrote at 2009-10-21 00:37 +0300:

>I've been struggling with a permission problem with my custom view
>(Plone 3.3.1). I created a form, backed by
>ImportEventsView(BrowserView) that would be used for batch-adding
>Events to a Folder, but for some reason that doesn't work and gives
>"Unauthorized: Cannot create Event":
>
>Traceback (innermost last):
> ...
>  Module Products.CMFCore.TypesTool, line 274, in constructInstance
>Unauthorized: Cannot create Event

The "Unauthorized" in this error message can be misleading.

The error occurs when "isConstructionAllowed" returns False.
This happens when either the factory cannot be found
or the meta type description belonging to the type has
a permission the current user does not have.

I would call "isConstructionAllowed" in an interactive Python
session ("bin/plonectl debug") and single step through it
to find out what really is the problem. Of course, other debugging
approaches may also reveal this....



--
Dieter

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Plone-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
Eemeli Kantola Eemeli Kantola
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: invokeFactory throws Unauthorized

In reply to this post by Carsten Senger
Hi,

I moved the code to __call__ and that was it, thanks!. The problem was
simple to fix, as I thought :)

-Eemeli

2009/10/21 Carsten Senger <[hidden email]>:

> Hi Eemeli,
>
> --On Mittwoch, Oktober 21, 2009 00:37:52 +0300 Eemeli Kantola
> <[hidden email]> wrote:
>
>> Hi All,
>>
>> I've been struggling with a permission problem with my custom view
>> (Plone 3.3.1). I created a form, backed by
>> ImportEventsView(BrowserView) that would be used for batch-adding
>> Events to a Folder, but for some reason that doesn't work and gives
>> "Unauthorized: Cannot create Event":
>>
>> Traceback (innermost last):
>>  Module ZPublisher.Publish, line 110, in publish
>>  Module ZPublisher.BaseRequest, line 488, in traverse
>>  Module ZPublisher.BaseRequest, line 314, in traverseName
>>  Module zope.traversing.namespace, line 109, in namespaceLookup
>>  Module zope.traversing.namespace, line 340, in traverse
>>  Module zope.component._api, line 114, in queryMultiAdapter
>>  Module zope.component.registry, line 206, in queryMultiAdapter
>>  Module zope.interface.adapter, line 482, in queryMultiAdapter
>>  Module Products.TestProduct.browser.importer, line 38, in __init__
>>  Module Products.TestProduct.browser.importer, line 48, in _import
>>  Module Products.TestProduct.browser.importer, line 162, in
>> quickAddCalendarEvent
>>  Module Products.CMFCore.PortalFolder, line 315, in invokeFactory
>>  Module Products.CMFCore.TypesTool, line 716, in constructContent
>>  Module Products.CMFCore.TypesTool, line 274, in constructInstance
>> Unauthorized: Cannot create Event
>
> Authorization is not finished during __init__. Call _import from
> __call__ or a method you call from the template.
>
> ..Carsten
>

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Plone-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
Loading...