source: products/CMFPlone_membership_hotfix/trunk/patch_del_members.py @ 2111

Last change on this file since 2111 was 1, checked in by myroslav, 14 years ago

Building directory structure

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1from Products.CMFCore.CMFCorePermissions import SetOwnPassword
2from Products.CMFCore.utils import getToolByName
3from Products.CMFDefault.MembershipTool import MembershipTool as BaseTool
4from Products.CMFPlone import ToolNames
5from AccessControl import ClassSecurityInfo, getSecurityManager
6from Globals import InitializeClass
7from Acquisition import aq_base, aq_parent, aq_inner
8from Products.CMFCore.CMFCorePermissions import View
9from Products.CMFPlone.PloneBaseTool import PloneBaseTool
10from ZODB.POSException import ConflictError
11from Products.CMFCore.utils import _checkPermission
12
13from Products.CMFPlone.MembershipTool import MembershipTool
14   
15
16
17def deleteMemberArea(self, member_id):
18    """ Delete member area of member specified by member_id.
19    """
20    members = self.getMembersFolder()
21    if not members:
22        return 0
23    if hasattr( aq_base(members), member_id ):
24        members.manage_delObjects(member_id)
25        return 1
26    else:
27        return 0
28
29
30def deleteMembers(self, member_ids, delete_memberareas=1,
31                    delete_localroles=1):
32    """ Delete members specified by member_ids.
33    """
34
35    # Delete members in acl_users.
36    acl_users = self.acl_users
37    if _checkPermission('Manage Users', acl_users):
38        if isinstance(member_ids, basestring):
39            member_ids = (member_ids,)
40        member_ids = list(member_ids)
41        for member_id in member_ids[:]:
42            if not acl_users.getUserById(member_id, None):
43                member_ids.remove(member_id)
44        try:
45            acl_users.userFolderDelUsers(member_ids)
46        except (NotImplementedError, 'NotImplemented'):
47            raise NotImplementedError('The underlying User Folder '
48                                        'doesn\'t support deleting members.')
49    else:
50        raise AccessControl_Unauthorized('You need the \'Manage users\' '
51                                'permission for the underlying User Folder.')
52
53    # Delete member data in portal_memberdata.
54    mdtool = getToolByName(self, 'portal_memberdata', None)
55    if mdtool is not None:
56        for member_id in member_ids:
57            members = mdtool._members
58            if members.has_key(member_id):
59                del members[member_id]
60
61    # Delete members' home folders including all content items.
62    if delete_memberareas:
63        for member_id in member_ids:
64                self.deleteMemberArea(member_id)
65
66    # Delete members' local roles.
67    if delete_localroles:
68        utool = getToolByName(self, 'portal_url', None)
69        self.deleteLocalRoles( utool.getPortalObject(), member_ids,
70                                reindex=1 )
71
72    return tuple(member_ids)
73
74MembershipTool.security = ClassSecurityInfo()
75MembershipTool.security.declareProtected('Manage Users', 'deleteMemberArea')
76MembershipTool.deleteMemberArea = deleteMemberArea
77MembershipTool.security.declareProtected('Manage Users', 'deleteMembers')
78MembershipTool.deleteMembers = deleteMembers
79
80InitializeClass(MembershipTool)
Note: See TracBrowser for help on using the repository browser.