a2c25db04c0f386ccb9518b029bc4adeb0fee2f9
1 # -*- coding: utf-8 -*-
2 #######################################################################################
3 # Plinn - http://plinn.org #
4 # Copyright (C) 2005-2007 BenoƮt PIN <benoit.pin@ensmp.fr> #
6 # This program is free software; you can redistribute it and/or #
7 # modify it under the terms of the GNU General Public License #
8 # as published by the Free Software Foundation; either version 2 #
9 # of the License, or (at your option) any later version. #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program; if not, write to the Free Software #
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #
19 #######################################################################################
20 """ Workflow aware MemberData to provide reviewed member registration.
25 from AccessControl
.interfaces
import IUser
26 from Products
.CMFCore
.interfaces
import IMemberDataTool
27 from Globals
import InitializeClass
28 from Acquisition
import aq_inner
, aq_parent
, aq_base
29 from AccessControl
import ClassSecurityInfo
30 from OFS
.SimpleItem
import SimpleItem
31 from Products
.CMFCore
.MemberDataTool
import MemberDataTool
as BaseTool
32 from Products
.CMFCore
.MemberDataTool
import MemberData
as BaseData
33 from Products
.CMFCore
.MemberDataTool
import MemberAdapter
as BaseMemberAdapter
34 from zope
.component
import adapts
35 from zope
.interface
import implements
36 from Products
.CMFCore
.interfaces
import IMember
37 # from Products.CMFCore.MemberDataTool import CleanupTemp
38 from Products
.CMFCore
.utils
import getToolByName
39 from Products
.CMFCore
.CMFCatalogAware
import CMFCatalogAware
40 from Products
.CMFCore
.DynamicType
import DynamicType
41 from utils
import formatFullName
42 from permissions
import SetMemberProperties
, SetMemberPassword
45 class MemberDataTool (BaseTool
):
46 """ This tool wraps user objects, making them act as Member objects.
49 meta_type
= 'Plinn Member Data Tool'
50 ## __implements__ = (IMemberDataTool, ActionProviderBase.__implements__)
52 security
= ClassSecurityInfo()
55 BaseTool
.__init
__(self
)
56 # Create the default properties.
57 self
._setProperty
('name', '', 'string')
58 self
._setProperty
('given_name', '', 'string')
59 self
._setProperty
('wysiwyg_editor', 'FCK', 'string')
60 self
._setProperty
('photo_width', 800, 'int')
62 def wrapUser(self
, u
) :
63 wu
= super(MemberDataTool
, self
).wrapUser(u
)
64 return wu
.__of
__(self
).__of
__(u
)
67 def __bobo_traverse__(self
, REQUEST
, name
):
68 if hasattr(self
,name
):
69 return getattr(self
,name
)
71 if self
._members
.has_key(name
) :
72 return self
.wrapUser(self
.acl_users
.getUser(name
))
74 InitializeClass(MemberDataTool
)
77 class MemberAdapter(BaseMemberAdapter
, SimpleItem
, DynamicType
, CMFCatalogAware
):
79 """Member data adapter.
82 adapts(IUser
, IMemberDataTool
)
85 portal_type
= 'Member Data'
87 security
= ClassSecurityInfo()
89 def __init__(self
, user
, tool
):
90 super(MemberAdapter
, self
).__init
__(user
, tool
)
91 self
.id = self
.getId()
93 security
.declarePublic('getMemberFullName')
94 def getMemberFullName(self
, nameBefore
=1) :
95 """ Return the best full name representation """
96 memberName
= self
.getProperty('name', default
='')
97 memberGivenName
= self
.getProperty('given_name', default
='')
98 memberId
= self
.getId()
99 return formatFullName(memberName
, memberGivenName
, memberId
, nameBefore
=nameBefore
)
101 def getMemberSortableFormat(self
) :
102 """ Return a specific format of full name for alphabetical sorting """
103 return self
.getMemberFullName(nameBefore
= 1).lower()
106 InitializeClass(MemberAdapter
)
109 class MemberData (BaseData
, DynamicType
, CMFCatalogAware
):
111 ## __implements__ = IMemberData
113 portal_type
= 'Member Data'
115 security
= ClassSecurityInfo()
117 security
.declareProtected(SetMemberPassword
, 'setMemberPassword')
118 def setMemberPassword(self
, password
, domains
=None) :
119 """ set member password """
121 registration
= getToolByName(self
, 'portal_registration', None)
123 failMessage
= registration
.testPasswordValidity(password
)
124 if failMessage
is not None:
125 raise 'Bad Request', failMessage
127 user_folder
= self
.acl_users
128 self
.setSecurityProfile(password
=password
, domains
=domains
)
129 if user_folder
.meta_type
== 'Group User Folder' :
130 self
.changePassword(password
)
133 #XXX restore the previous implementation for GRUF 2 I'll remove that later...
134 security
.declarePrivate('setSecurityProfile')
135 def setSecurityProfile(self
, password
=None, roles
=None, domains
=None):
136 """Set the user's basic security profile"""
138 # This is really hackish. The Zope User API needs methods
139 # for performing these functions.
140 if password
is not None:
142 if roles
is not None:
144 if domains
is not None:
148 def getMemberFullName(self
, nameBefore
=1) :
149 """ Return the best full name representation """
150 memberName
= self
.getProperty('name', default
='')
151 memberGivenName
= self
.getProperty('given_name', default
='')
152 memberId
= self
.getProperty('id', default
='')
153 return formatFullName(memberName
, memberGivenName
, memberId
, nameBefore
=nameBefore
)
155 def getMemberSortableFormat(self
) :
156 """ Return a specific format of full name for alphabetical sorting """
157 return self
.getMemberFullName(nameBefore
= 1).lower()
160 ## overload default security declaration
161 security
.declareProtected(SetMemberProperties
, 'setMemberProperties')
162 def setMemberProperties(self
, mapping
):
163 BaseData
.setMemberProperties(self
, mapping
)
166 security
.declarePrivate('manage_beforeDelete')
167 def manage_beforeDelete(self
) :
168 """ uncatalog object """
171 def _setPortalTypeName(self
, pt
) :
172 """ Static Dynamic Type ;-) """
175 # user object interface
176 # overloads to make methods not publishable
178 def getUserName(self
):
179 return BaseData
.getUserName(self
)
182 return BaseData
.getId(self
)
185 return BaseData
.getRoles(self
)
187 def getRolesInContext(self
, object):
188 return BaseData
.getRolesInContext(self
, object)
190 def getDomains(self
):
191 return BaseData
.getDomains(self
)
193 def has_role(self
, roles
, object=None):
194 return BaseData
.has_role(self
, roles
, object=None)
198 InitializeClass(MemberData
)