"factory permissions" for non-Archetype content

3 messages Options
Embed this post
Permalink
Derek Broughton-3 () "factory permissions" for non-Archetype content
Reply Threaded More More options
Print post
Permalink
I've been banging my head on this for a day, and it's time to ask for help.

Martin's borg.project has the following code (simplified here) which works
fine for Archetypes:

    portal_types = getToolByName(context, 'portal_types')
    for fti in portal_types.listTypeInfo():
        factory = getattr(fti, 'factory', None)
        product = getattr(fti, 'product', None)
        dispatcher = getattr(context, 'manage_addProduct', None)
        product_instance = dispatcher[product]
        factory_method = getattr(product_instance, factory, None)
        factory_instance = getattr(factory_method, 'im_self', None)
        factory_class = factory_instance.__class__
        role_permission = getattr(factory_class, factory+'__roles__', None)

Unfortunately, non-archetype content (borg.project included) doesn't have a
"product", and I can't find any way to find a corresponding PermissionRole
object for those.

[I do wish you'd made "default_addable_types" a utility, Martin...]
--
derek



_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers
Martin Aspeli () Re: "factory permissions" for non-Archetype content
Reply Threaded More More options
Print post
Permalink
Derek Broughton wrote:

> I've been banging my head on this for a day, and it's time to ask for help.
>
> Martin's borg.project has the following code (simplified here) which works
> fine for Archetypes:
>
>     portal_types = getToolByName(context, 'portal_types')
>     for fti in portal_types.listTypeInfo():
>         factory = getattr(fti, 'factory', None)
>         product = getattr(fti, 'product', None)
>         dispatcher = getattr(context, 'manage_addProduct', None)
>         product_instance = dispatcher[product]
>         factory_method = getattr(product_instance, factory, None)
>         factory_instance = getattr(factory_method, 'im_self', None)
>         factory_class = factory_instance.__class__
>         role_permission = getattr(factory_class, factory+'__roles__', None)
>
> Unfortunately, non-archetype content (borg.project included) doesn't have a
> "product", and I can't find any way to find a corresponding PermissionRole
> object for those.

Mmmm.... I'm not sure how this works, but I have a better idea:
http://plone.org/products/dexterity/documentation/manual/developers-manual

:-)

Dexterity has an explicit add permission in the FTI, which is checked by
the FTI isContructionAllowed.

That code in borg.project is kind of evil. I don't know a a better way
to find "the add permission" of an object.

I think you'd need to figure out what five:registerClass or does with
the add permission you give. Or maybe they're all "Add portal content"
by default?

> [I do wish you'd made "default_addable_types" a utility, Martin...]

I didn't know what a utility was back then, and I'm not sure this is
even my code. I think it was Tiran. :-)

Martin

--
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book


_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers
Derek Broughton-3 () Re: "factory permissions" for non-Archetype content
Reply Threaded More More options
Print post
Permalink
Martin Aspeli wrote:

> Derek Broughton wrote:
>> I've been banging my head on this for a day, and it's time to ask for
>> help.
>>
>> Martin's borg.project has the following code (simplified here) which
>> works fine for Archetypes:
>>
>>     portal_types = getToolByName(context, 'portal_types')
>>     for fti in portal_types.listTypeInfo():
>>         factory = getattr(fti, 'factory', None)
>>         product = getattr(fti, 'product', None)
>>         dispatcher = getattr(context, 'manage_addProduct', None)
>>         product_instance = dispatcher[product]
>>         factory_method = getattr(product_instance, factory, None)
>>         factory_instance = getattr(factory_method, 'im_self', None)
>>         factory_class = factory_instance.__class__
>>         role_permission = getattr(factory_class, factory+'__roles__',
>>         None)
>>
>> Unfortunately, non-archetype content (borg.project included) doesn't have
>> a "product", and I can't find any way to find a corresponding
>> PermissionRole object for those.
>
> Mmmm.... I'm not sure how this works, but I have a better idea:
> http://plone.org/products/dexterity/documentation/manual/developers-manual

Funny, I was just in the middle of reading that ...

> Dexterity has an explicit add permission in the FTI, which is checked by
> the FTI isContructionAllowed.
>
> That code in borg.project is kind of evil. I don't know a a better way
> to find "the add permission" of an object.

Damn - because the problem I'm having is trying to actually make borg
projects automatically addable to borg projects.  Seems like it should be
simple...
 
> I think you'd need to figure out what five:registerClass or does with
> the add permission you give. Or maybe they're all "Add portal content"
> by default?

I haven't even managed to figure out what the add permission _is_ (could be
"Add portal content").
>
>> [I do wish you'd made "default_addable_types" a utility, Martin...]
>
> I didn't know what a utility was back then, and I'm not sure this is
> even my code. I think it was Tiran. :-)

LOL.  I think I need to patch it to make a utility anyway...
--
derek



_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers