[CMF-checkins] CVS: CMF/CMFCore - MembershipTool.py:1.36
Yvo Schubbe
schubbe@web.de
Mon, 2 Jun 2003 12:19:17 -0400
Update of /cvs-repository/CMF/CMFCore
In directory cvs.zope.org:/tmp/cvs-serv31356/CMFCore
Modified Files:
MembershipTool.py
Log Message:
Merged yuppie-createMemberarea-branch:
- Made logged_in page instead of wrapUser call 'createMemberarea'.
- Added a customization hook to CMFDefault 'createMemberarea'.
=== CMF/CMFCore/MembershipTool.py 1.35 => 1.36 ===
--- CMF/CMFCore/MembershipTool.py:1.35 Wed May 28 07:52:15 2003
+++ CMF/CMFCore/MembershipTool.py Mon Jun 2 12:18:47 2003
@@ -17,7 +17,7 @@
from utils import UniqueObject, _getAuthenticatedUser, _checkPermission
from utils import getToolByName, _dtmldir
-from OFS.SimpleItem import SimpleItem
+from OFS.Folder import Folder
from Globals import InitializeClass, DTMLFile, MessageDialog, \
PersistentMapping
from Acquisition import aq_base
@@ -32,16 +32,8 @@
from interfaces.portal_membership \
import portal_membership as IMembershipTool
-default_member_content = '''Default page for %s
-
- This is the default document created for you when
- you joined this community.
-
- To change the content just select "Edit"
- in the Tool Box on the left.
-'''
-class MembershipTool (UniqueObject, SimpleItem, ActionProviderBase):
+class MembershipTool(UniqueObject, Folder, ActionProviderBase):
""" This tool accesses member data through an acl_users object.
It can be replaced with something that accesses member data in a
@@ -61,24 +53,24 @@
manage_options=( ({ 'label' : 'Configuration'
, 'action' : 'manage_mapRoles'
},) +
- ActionProviderBase.manage_options +
+ ActionProviderBase.manage_options +
( { 'label' : 'Overview'
, 'action' : 'manage_overview'
},
- ) + SimpleItem.manage_options)
+ ) + Folder.manage_options)
#
# ZMI methods
#
security.declareProtected(ManagePortal, 'manage_overview')
manage_overview = DTMLFile( 'explainMembershipTool', _dtmldir )
-
+
#
# 'portal_membership' interface methods
#
security.declareProtected(ManagePortal, 'manage_mapRoles')
manage_mapRoles = DTMLFile('membershipRolemapping', _dtmldir )
-
+
security.declareProtected(SetOwnPassword, 'setPassword')
def setPassword(self, password, domains=None):
'''Allows the authenticated member to set his/her own password.
@@ -123,7 +115,7 @@
# already registered with something that implements the
# member data tool at least partially.
return u
-
+
parent = self.aq_inner.aq_parent
base = getattr(parent, 'aq_base', None)
if hasattr(base, 'portal_memberdata'):
@@ -138,15 +130,7 @@
md = getToolByName(parent, 'portal_memberdata')
try:
portal_user = md.wrapUser(u)
-
- # Check for the member area creation flag and
- # take appropriate (non-) action
- if getattr(self, 'memberareaCreationFlag', 0) != 0:
- if self.getHomeUrl(portal_user.getId()) is None:
- self.createMemberarea(portal_user.getId())
-
return portal_user
-
except:
from zLOG import LOG, ERROR
import sys
@@ -238,35 +222,51 @@
message='Member area creation flag has been updated',
action ='manage_mapRoles')
- security.declareProtected(ManagePortal, 'createMemberarea')
- def createMemberarea(self, member_id):
- """
- create a member area
+ security.declarePublic('createMemberarea')
+ def createMemberarea(self, member_id=''):
+ """ Create a member area for 'member_id' or authenticated user.
"""
+ if not self.getMemberareaCreationFlag():
+ return None
parent = self.aq_inner.aq_parent
members = getattr(parent, 'Members', None)
-
- user = self.acl_users.getUserById( member_id, None )
- if user is None:
- raise ValueError, 'Member %s does not exist' % member_id
-
- if user is not None:
- user = user.__of__( self.acl_users )
-
- if members is not None and user is not None:
+ if not members:
+ return None
+ if self.isAnonymousUser():
+ return None
+ # Note: We can't use getAuthenticatedMember() and getMemberById()
+ # because they might be wrapped by MemberDataTool.
+ user = _getAuthenticatedUser(self)
+ user_id = user.getId()
+ if member_id in ('', user_id):
+ member = user
+ member_id = user_id
+ else:
+ if _checkPermission(ManagePortal, self):
+ member = self.acl_users.getUserById(member_id, None)
+ if member:
+ member = member.__of__(self.acl_users)
+ else:
+ raise ValueError, 'Member %s does not exist' % member_id
+ else:
+ return None
+ if hasattr( aq_base(members), member_id ):
+ return None
+ else:
f_title = "%s's Home" % member_id
members.manage_addPortalFolder( id=member_id, title=f_title )
f=getattr(members, member_id)
-
+
f.manage_permission(View,
['Owner','Manager','Reviewer'], 0)
f.manage_permission(AccessContentsInformation,
- ['Owner','Manager','Reviewer'], 0)
+ ['Owner','Manager','Reviewer'], 0)
# Grant Ownership and Owner role to Member
- f.changeOwnership(user)
+ f.changeOwnership(member)
f.__ac_local_roles__ = None
f.manage_setLocalRoles(member_id, ['Owner'])
+ return f
security.declarePublic('isAnonymousUser')
def isAnonymousUser(self):
@@ -343,7 +343,7 @@
'''
user_folder = self.__getPUS()
return [ x.getId() for x in user_folder.getUsers() ]
-
+
security.declareProtected(ManagePortal, 'listMembers')
def listMembers(self):
'''Gets the list of all members.
@@ -357,7 +357,6 @@
return md.searchMemberData( search_param, search_term )
-
security.declareProtected(View, 'getCandidateLocalRoles')
def getCandidateLocalRoles( self, obj ):
""" What local roles can I assign? """
@@ -430,7 +429,7 @@
doesn't have the View permission on the folder.
"""
return None
-
+
security.declarePublic('getHomeUrl')
def getHomeUrl(self, id=None, verifyPermission=0):
"""Returns the URL to a member's home folder or None.