4a432ebec57303d2cbba78cc9853b795c0677d80
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
.component
import getUtility
36 from zope
.interface
import implements
37 from Products
.CMFCore
.interfaces
import IMember
38 from Products
.CMFCore
.interfaces
import IRegistrationTool
39 # from Products.CMFCore.MemberDataTool import CleanupTemp
40 #from Products.CMFCore.utils import getToolByName
41 from Products
.CMFCore
.CMFCatalogAware
import CMFCatalogAware
42 from Products
.CMFCore
.DynamicType
import DynamicType
43 from utils
import formatFullName
44 from permissions
import SetMemberProperties
, SetMemberPassword
47 class MemberDataTool (BaseTool
):
48 """ This tool wraps user objects, making them act as Member objects.
51 meta_type
= 'Plinn Member Data Tool'
52 ## __implements__ = (IMemberDataTool, ActionProviderBase.__implements__)
54 security
= ClassSecurityInfo()
57 BaseTool
.__init
__(self
)
58 # Create the default properties.
59 self
._setProperty
('name', '', 'string')
60 self
._setProperty
('given_name', '', 'string')
61 self
._setProperty
('wysiwyg_editor', 'FCK', 'string')
62 self
._setProperty
('photo_width', 800, 'int')
64 def wrapUser(self
, u
) :
65 wu
= super(MemberDataTool
, self
).wrapUser(u
)
66 return wu
.__of
__(self
).__of
__(u
)
69 def __bobo_traverse__(self
, REQUEST
, name
):
70 if hasattr(self
,name
):
71 return getattr(self
,name
)
73 if self
._members
.has_key(name
) :
74 return self
.wrapUser(self
.acl_users
.getUser(name
))
76 InitializeClass(MemberDataTool
)
79 class MemberAdapter(BaseMemberAdapter
, SimpleItem
, DynamicType
, CMFCatalogAware
):
81 """Member data adapter.
84 adapts(IUser
, IMemberDataTool
)
87 portal_type
= 'Member Data'
89 security
= ClassSecurityInfo()
91 def __init__(self
, user
, tool
):
92 super(MemberAdapter
, self
).__init
__(user
, tool
)
93 self
.id = self
.getId()
95 security
.declarePublic('getMemberFullName')
96 def getMemberFullName(self
, nameBefore
=1) :
97 """ Return the best full name representation """
98 memberName
= self
.getProperty('name', default
='')
99 memberGivenName
= self
.getProperty('given_name', default
='')
100 memberId
= self
.getId()
101 return formatFullName(memberName
, memberGivenName
, memberId
, nameBefore
=nameBefore
)
103 def getMemberSortableFormat(self
) :
104 """ Return a specific format of full name for alphabetical sorting """
105 return self
.getMemberFullName(nameBefore
= 1).lower()
108 security
.declareProtected(SetMemberProperties
, 'setMemberProperties')
109 def setMemberProperties(self
, mapping
):
110 super(MemberAdapter
, self
).setMemberProperties(mapping
)
113 security
.declareProtected(SetMemberPassword
, 'setMemberPassword')
114 def setMemberPassword(self
, password
, domains
=None) :
115 """ set member password """
117 registration
= getUtility(IRegistrationTool
)
118 failMessage
= registration
.testPasswordValidity(password
)
119 if failMessage
is not None :
120 raise ValueError(failMessage
)
122 self
.setSecurityProfile(password
=password
, domains
=domains
)
124 security
.declarePrivate('manage_beforeDelete')
125 def manage_beforeDelete(self
) :
126 """ uncatalog object """
129 def _setPortalTypeName(self
, pt
) :
130 """ Static Dynamic Type ;-) """
133 # user object interface
134 # overloads to make methods not publishable
136 def getUserName(self
):
137 return super(MemberAdapter
, self
).getUserName()
140 return super(MemberAdapter
, self
).getId()
143 return super(MemberAdapter
, self
).getRoles()
145 def getRolesInContext(self
, object):
146 return super(MemberAdapter
, self
).getRolesInContext(object)
148 def getDomains(self
):
149 return super(MemberAdapter
, self
).getDomains()
151 def has_role(self
, roles
, object=None):
152 return super(MemberAdapter
, self
).has_role(roles
, object=None)
154 InitializeClass(MemberAdapter
)
157 class MemberData (BaseData
, DynamicType
, CMFCatalogAware
):
159 ## __implements__ = IMemberData
161 portal_type
= 'Member Data'
163 security
= ClassSecurityInfo()
165 # security.declareProtected(SetMemberPassword, 'setMemberPassword')
166 # def setMemberPassword(self, password, domains=None) :
167 # """ set member password """
169 # registration = getToolByName(self, 'portal_registration', None)
171 # failMessage = registration.testPasswordValidity(password)
172 # if failMessage is not None:
173 # raise 'Bad Request', failMessage
175 # user_folder = self.acl_users
176 # self.setSecurityProfile(password=password, domains=domains)
177 # if user_folder.meta_type == 'Group User Folder' :
178 # self.changePassword(password)
181 #XXX restore the previous implementation for GRUF 2 I'll remove that later...
182 security
.declarePrivate('setSecurityProfile')
183 def setSecurityProfile(self
, password
=None, roles
=None, domains
=None):
184 """Set the user's basic security profile"""
186 # This is really hackish. The Zope User API needs methods
187 # for performing these functions.
188 if password
is not None:
190 if roles
is not None:
192 if domains
is not None:
196 # def getMemberFullName(self, nameBefore=1) :
197 # """ Return the best full name representation """
198 # memberName = self.getProperty('name', default='')
199 # memberGivenName = self.getProperty('given_name', default='')
200 # memberId = self.getProperty('id', default='')
201 # return formatFullName(memberName, memberGivenName, memberId, nameBefore=nameBefore)
204 # def getMemberSortableFormat(self) :
205 # """ Return a specific format of full name for alphabetical sorting """
206 # return self.getMemberFullName(nameBefore = 1).lower()
210 # ## overload default security declaration
211 # security.declareProtected(SetMemberProperties, 'setMemberProperties')
212 # def setMemberProperties(self, mapping):
213 # BaseData.setMemberProperties(self, mapping)
214 # self.reindexObject()
217 # security.declarePrivate('manage_beforeDelete')
218 # def manage_beforeDelete(self) :
219 # """ uncatalog object """
220 # self.unindexObject()
223 # def _setPortalTypeName(self, pt) :
224 # """ Static Dynamic Type ;-) """
228 # # user object interface
229 # # overloads to make methods not publishable
231 # def getUserName(self):
232 # return BaseData.getUserName(self)
235 # return BaseData.getId(self)
237 # def getRoles(self):
238 # return BaseData.getRoles(self)
240 # def getRolesInContext(self, object):
241 # return BaseData.getRolesInContext(self, object)
243 # def getDomains(self):
244 # return BaseData.getDomains(self)
246 # def has_role(self, roles, object=None):
247 # return BaseData.has_role(self, roles, object=None)
251 InitializeClass(MemberData
)