c83ff49954d2b57059dac7171f74a3f343cebb63
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 Products
.CMFCore
.exceptions
import BadRequest
44 from utils
import formatFullName
45 from permissions
import SetMemberProperties
, SetMemberPassword
48 class MemberDataTool (BaseTool
):
49 """ This tool wraps user objects, making them act as Member objects.
52 meta_type
= 'Plinn Member Data Tool'
53 ## __implements__ = (IMemberDataTool, ActionProviderBase.__implements__)
55 security
= ClassSecurityInfo()
58 BaseTool
.__init
__(self
)
59 # Create the default properties.
60 self
._setProperty
('name', '', 'string')
61 self
._setProperty
('given_name', '', 'string')
62 self
._setProperty
('wysiwyg_editor', 'FCK', 'string')
63 self
._setProperty
('photo_width', 800, 'int')
65 def wrapUser(self
, u
) :
66 wu
= super(MemberDataTool
, self
).wrapUser(u
)
67 return wu
.__of
__(self
).__of
__(u
)
70 def __bobo_traverse__(self
, REQUEST
, name
):
71 if hasattr(self
,name
):
72 return getattr(self
,name
)
74 if self
._members
.has_key(name
) :
75 return self
.wrapUser(self
.acl_users
.getUser(name
))
77 InitializeClass(MemberDataTool
)
80 class MemberAdapter(BaseMemberAdapter
, SimpleItem
, DynamicType
, CMFCatalogAware
):
82 """Member data adapter.
85 adapts(IUser
, IMemberDataTool
)
88 portal_type
= 'Member Data'
90 security
= ClassSecurityInfo()
92 def __init__(self
, user
, tool
):
93 super(MemberAdapter
, self
).__init
__(user
, tool
)
94 self
.id = self
.getId()
96 security
.declarePublic('getMemberFullName')
97 def getMemberFullName(self
, nameBefore
=1) :
98 """ Return the best full name representation """
99 memberName
= self
.getProperty('name', default
='')
100 memberGivenName
= self
.getProperty('given_name', default
='')
101 memberId
= self
.getId()
102 return formatFullName(memberName
, memberGivenName
, memberId
, nameBefore
=nameBefore
)
104 def getMemberSortableFormat(self
) :
105 """ Return a specific format of full name for alphabetical sorting """
106 return self
.getMemberFullName(nameBefore
= 1).lower()
109 security
.declareProtected(SetMemberProperties
, 'setMemberProperties')
110 def setMemberProperties(self
, mapping
):
111 super(MemberAdapter
, self
).setMemberProperties(mapping
)
114 security
.declareProtected(SetMemberPassword
, 'setMemberPassword')
115 def setMemberPassword(self
, password
, domains
=None) :
116 """ set member password """
118 registration
= getUtility(IRegistrationTool
)
119 failMessage
= registration
.testPasswordValidity(password
)
120 if failMessage
is not None :
121 raise BadRequest(failMessage
)
123 self
.setSecurityProfile(password
=password
, domains
=domains
)
125 security
.declarePrivate('setSecurityProfile')
126 def setSecurityProfile(self
, password
=None, roles
=None, domains
=None):
127 """Set the user's basic security profile"""
129 # This is really hackish. The Zope User API needs methods
130 # for performing these functions.
131 if password
is not None:
132 u
.setPassword(password
)
133 if roles
is not None:
135 if domains
is not None:
136 u
.setDomains(domains
)
138 security
.declarePrivate('manage_beforeDelete')
139 def manage_beforeDelete(self
) :
140 """ uncatalog object """
143 def _setPortalTypeName(self
, pt
) :
144 """ Static Dynamic Type ;-) """
147 # user object interface
148 # overloads to make methods not publishable
150 def getUserName(self
):
151 return super(MemberAdapter
, self
).getUserName()
154 return super(MemberAdapter
, self
).getId()
157 return self
._user
.aq_inner
.getRoles()
158 # return super(MemberAdapter, self).getRoles()
160 def getRolesInContext(self
, object):
161 return super(MemberAdapter
, self
).getRolesInContext(object)
163 def getDomains(self
):
164 return super(MemberAdapter
, self
).getDomains()
166 def has_role(self
, roles
, object=None):
167 return super(MemberAdapter
, self
).has_role(roles
, object=None)
169 InitializeClass(MemberAdapter
)
172 class MemberData (BaseData
, DynamicType
, CMFCatalogAware
):
174 ## __implements__ = IMemberData
176 portal_type
= 'Member Data'
178 security
= ClassSecurityInfo()
180 # security.declareProtected(SetMemberPassword, 'setMemberPassword')
181 # def setMemberPassword(self, password, domains=None) :
182 # """ set member password """
184 # registration = getToolByName(self, 'portal_registration', None)
186 # failMessage = registration.testPasswordValidity(password)
187 # if failMessage is not None:
188 # raise 'Bad Request', failMessage
190 # user_folder = self.acl_users
191 # self.setSecurityProfile(password=password, domains=domains)
192 # if user_folder.meta_type == 'Group User Folder' :
193 # self.changePassword(password)
197 #XXX restore the previous implementation for GRUF 2 I'll remove that later...
198 # security.declarePrivate('setSecurityProfile')
199 # def setSecurityProfile(self, password=None, roles=None, domains=None):
200 # """Set the user's basic security profile"""
202 # # This is really hackish. The Zope User API needs methods
203 # # for performing these functions.
204 # if password is not None:
206 # if roles is not None:
208 # if domains is not None:
209 # u.domains = domains
212 # def getMemberFullName(self, nameBefore=1) :
213 # """ Return the best full name representation """
214 # memberName = self.getProperty('name', default='')
215 # memberGivenName = self.getProperty('given_name', default='')
216 # memberId = self.getProperty('id', default='')
217 # return formatFullName(memberName, memberGivenName, memberId, nameBefore=nameBefore)
220 # def getMemberSortableFormat(self) :
221 # """ Return a specific format of full name for alphabetical sorting """
222 # return self.getMemberFullName(nameBefore = 1).lower()
226 # ## overload default security declaration
227 # security.declareProtected(SetMemberProperties, 'setMemberProperties')
228 # def setMemberProperties(self, mapping):
229 # BaseData.setMemberProperties(self, mapping)
230 # self.reindexObject()
233 # security.declarePrivate('manage_beforeDelete')
234 # def manage_beforeDelete(self) :
235 # """ uncatalog object """
236 # self.unindexObject()
239 # def _setPortalTypeName(self, pt) :
240 # """ Static Dynamic Type ;-) """
244 # # user object interface
245 # # overloads to make methods not publishable
247 # def getUserName(self):
248 # return BaseData.getUserName(self)
251 # return BaseData.getId(self)
253 # def getRoles(self):
254 # return BaseData.getRoles(self)
256 # def getRolesInContext(self, object):
257 # return BaseData.getRolesInContext(self, object)
259 # def getDomains(self):
260 # return BaseData.getDomains(self)
262 # def has_role(self, roles, object=None):
263 # return BaseData.has_role(self, roles, object=None)
267 InitializeClass(MemberData
)