Hacking at Plone membership's core: different content types for member folders

I'm using this technique for a site created with Plone 2.1, but it I think it can work on Plone 2.5 as well. Basically, I need a site with different membership types, and each membership type has a "personal area" (different member folder) where the user can add different object types and generally have a completely different browsing experience. I haven't implemented anything exotic such as CMFMember (not future proof) or membrane (not compatible, don't want to mess around yet) so I'm sticking with plain Plone users.

No 1 on the list is monkey patching MembershipTool to be able to specify more then one type of member folders. The module below (patch.py) also shows what monkey patching is about (look for clues at the end of the snippet):

#patching below
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.utils import _createObjectByType
from AccessControl import ClassSecurityInfo, getSecurityManager
from Products.CMFPlone.MembershipTool import MembershipTool

def createMemberarea(self, member_id=None, minimal=1, areaType=None):
    """
    Create a member area for 'member_id' or the authenticated user.
    areaType is a string that contains a portal type.
    """
... <SNIPED>

    if hasattr(members, member_id):
        # has already this member
        # TODO exception
        return

#START CHANGES
    if areaType is not None:
        memberarea_type = areaType
    else:
        memberarea_type = self.memberarea_type
#END CHANGED

    _createObjectByType(memberarea_type, members, id=member_id)

... <SNIPED>

#monkeypatching

print "Monkey patching Products.CMFPlone.MembershipTool.MembershipTool to provide aditional member folders types..."

security = ClassSecurityInfo()

security.declarePublic('createMemberarea')
MembershipTool.createMemberarea = createMemberarea
MembershipTool.createMemberArea = createMemberarea

print "Done."

In the Product/__init__.py file add a simple 'import patch' to enable loading the patch.

Because I've created a complete alternate login system (again, different user experiences, duplicating the plone_login folder seemed easier to get this running), it is easy for me to plug in the special member folder creation. I've customized logged_in.cpy to contain:

membership_tool.createMemberArea(areaType='ServiceProviderHome')

instead of the usual

membership_tool.createMemberArea() 

I'm not feeling very smart for this site because of the complicated setup: monkey patching, duplicating plone_login, etc, but this is what it works and it's easiest for me right now. Perhaps the future Plone 3 will make this kind of things easier (extending the MembershipTool with new behaviour).

Comments