[Product-Developers] Re: "factory permissions" for non-Archetype content

Derek Broughton derek at pointerstop.ca
Wed Aug 5 17:54:48 UTC 2009


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






More information about the Product-Developers mailing list