[Zope-CMF] adding two types with different permissions

kapil thangavelu kthangavelu@earthlink.net
Wed, 31 Jul 2002 09:56:33 -0700


On Wednesday 31 July 2002 06:42 am, Florent Guillaume wrote:
> kapil thangavelu  <kthangavelu@earthlink.net> wrote:
> > On Monday 29 July 2002 12:53 pm, Karl Anderson wrote:
> > > I'm trying to add two types from the same Zope product.  Because I
> > > want separate permissions for each's constructors, I'm using two
> > > ContentInit calls.  However, this isn't working.
> >
> > short answer, as far as i can tell, it isn't possible. the long answer,
> > is infinitely more ugly.
> >
> > if you do try it as below, you should get the results and registration
> > of the last ContentInit, assuming everything else is working.
>
> Why wouldn't it work ? The classes, constructors and fti are all
> different. I don't see the problem.

i think i spoke too soon... but it still seems as if the factory type 
information stored on the factory dispatcher gets over-written, such that the 
last ContentInit is the only one visible.

there is a dirty trick that solves the problem for karl's case, inside 
initialize do
   context._ProductContext__prod.factory_type_information = fti1+fti2

where fti1 and fti2 are the tuples of factory type infos. because this 
mechanism exists, i'm curious if there is a cleaner way to utilize it... i 
haven't found one yet.

from a permission standpoint though this is not meaningful wrt to security if 
the constructors are the same.

on another note, i spent much time and hair pulling wrestling with the type 
tool, before itamar clued me in that edits to filesystem factory type infos 
and registration are not meaningful unless you blow away the product from the 
control panel. ick.

-k

> Florent
>
> > > The Post ContentInit call below seems to wreck everything.  Starting
> > > Zope with the code below in the shared __init__.py causes neither type
> > > to show up in the types tool.  If I comment out the Post ContentInit,
> > > the forum type gets added.  If I use only the commented-out
> > > ContentInit that inits both, it works as well, but I can't use a
> > > separate permission in that case.
> > >
> > > I'm not getting a startup error or any indication of failure in the
> > > console that starts Zope.
> > >
> > > Seems like Post is wrecking it, of course, but then why is the double
> > > init working?
> > >
> > > factory_type_informations from both products appended.
> > >
> > >
> > > from __init__.py:
> > >
> > > def initialize( context ):
> > >
> > >     #utils.ContentInit( 'CMF Forum Content My',
> > >     #                   content_types = (Forum.ForumMy, Post.PostMy),
> > >     #                   permission = 'Add portal content',
> > >     #                   extra_constructors = (Forum.addForum,
> > > Post.addPost), #                   fti =
> > > (Forum.factory_type_information, #                         
> > > Post.factory_type_information)
> > >     #                 ).initialize( context )
> > >     utils.ContentInit( 'CMF Forum My',
> > >                        content_types = (Forum.ForumMy,),
> > >                        permission = 'Add portal content',
> > >                        extra_constructors = (Forum.addForum,),
> > >                        fti = (Forum.factory_type_information,)
> > >                      ).initialize( context )
> > >     utils.ContentInit( 'CMF Post My',
> > >                        content_types = (Post.PostMy,),
> > >                        permission = 'Add portal content',
> > >                        extra_constructors = (Post.addPost,),
> > >                        fti = (Post.factory_type_information,)
> > >                      ).initialize( context )
> > >
> > >
> > >
> > >
> > >
> > >
> > > from Post.py:
> > >
> > > factory_type_information =   { 'id'             : 'PostMy'
> > >                              , 'portal_type'    : 'PostMy'
> > >                              , 'meta_type'      : 'PostMy'
> > >                              , 'description'    : """\
> > > Posts are like Discussion items but they just can be added into
> > > Forums.""" , 'icon'           : 'icon_post.gif' , 'product'        :
> > > 'CMFForumMy' , 'factory'        : 'addPost'
> > >                              , 'filter_content_types' : 1
> > >                              , 'allowed_content_types' : ('PostMy', )
> > >                              #, 'immediate_view' : 'metadata_edit_form'
> > >                              , 'immediate_view' :
> > > 'cwip_metadata_edit_form' , 'global_allow'   : 0
> > >                              , 'actions'        :
> > >                                 ( { 'id'            : 'view'
> > >                                   , 'name'          : 'View'
> > >                                   , 'action'        : 'post_view'
> > >                                   , 'permissions'   : (
> > >                                       View, )
> > >                                   }
> > >                                 , { 'id'            : 'post_reply'
> > >                                   , 'name'          : 'Reply'
> > >                                   , 'action'        :
> > > 'forum_post_message' , 'permissions'   : (
> > >                                       AddPortalContent, )
> > >                                   }
> > >                                 , { 'id'            : 'metadata'
> > >                                   , 'name'          : 'Metadata'
> > >                                   , 'action'        :
> > > 'cwip_metadata_edit_form' , 'permissions'   : (ModifyPortalContent, ) }
> > >                                 )
> > >                              }
> > >
> > >
> > > from Forum.py:
> > >
> > >
> > > factory_type_information = { 'id'             : 'ForumMy'
> > >                              , 'portal_type'	: 'ForumMy'
> > >                              , 'meta_type'      : 'ForumMy'
> > >                              , 'description'    : \
> > >                              "Forums hold threaded discussions."
> > >                              , 'icon'           : 'forum_icon.gif'
> > >                              , 'product'        : 'CMFForumMy'
> > >                              , 'factory'        : 'addForum'
> > >                              , 'filter_content_types' : 1
> > >                              , 'allowed_content_types' : ('PostMy', )
> > >                              , 'immediate_view' :
> > > 'cwip_metadata_edit_form' #, 'immediate_view' : 'forum_edit_form' ,
> > > 'actions'        :
> > >                                 ( { 'id'            : 'view'
> > >                                   , 'name'          : 'View'
> > >                                   , 'action'        : 'forum_listing'
> > >                                   , 'permissions'   : (View,)
> > >                                   , 'category'      : 'folder'
> > >                                   }
> > >                                 , { 'id'            : 'edit'
> > >                                   , 'name'          : 'Edit'
> > >                                   , 'action'        : 'forum_edit_form'
> > >                                   , 'permissions'   :
> > > (ManageProperties,) , 'category'      : 'folder' }
> > >                                 , { 'id'            : 'localroles'
> > >                                   , 'name'          : 'Local Roles'
> > >                                   , 'action'        :
> > > 'folder_localrole_form' , 'permissions'   : (ManageProperties,) ,
> > > 'category'      : 'folder'
> > >                                   }
> > >                                 , { 'id'            :
> > > 'forum_post_message' , 'name'          : 'Post Message' , 'action'     
> > >   : 'forum_post_message' , 'permissions'   : (AddPortalContent, ) ,
> > > 'category'      : 'folder' }
> > >                                 , { 'id'            : 'metadata'
> > >                                   , 'name'          : 'Metadata'
> > >                                   , 'action'        :
> > > 'cwip_metadata_edit_form' , 'permissions'   : (ModifyPortalContent, ) }
> > >                                 )
> > >                              }