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 super(MemberAdapter
, self
).getRoles()
159 def getRolesInContext(self
, object):
160 return super(MemberAdapter
, self
).getRolesInContext(object)
162 def getDomains(self
):
163 return super(MemberAdapter
, self
).getDomains()
165 def has_role(self
, roles
, object=None):
166 return super(MemberAdapter
, self
).has_role(roles
, object=None)
168 InitializeClass(MemberAdapter
)
171 class MemberData (BaseData
, DynamicType
, CMFCatalogAware
):
173 ## __implements__ = IMemberData
175 portal_type
= 'Member Data'
177 security
= ClassSecurityInfo()
179 # security.declareProtected(SetMemberPassword, 'setMemberPassword')
180 # def setMemberPassword(self, password, domains=None) :
181 # """ set member password """
183 # registration = getToolByName(self, 'portal_registration', None)
185 # failMessage = registration.testPasswordValidity(password)
186 # if failMessage is not None:
187 # raise 'Bad Request', failMessage
189 # user_folder = self.acl_users
190 # self.setSecurityProfile(password=password, domains=domains)
191 # if user_folder.meta_type == 'Group User Folder' :
192 # self.changePassword(password)
196 #XXX restore the previous implementation for GRUF 2 I'll remove that later...
197 # security.declarePrivate('setSecurityProfile')
198 # def setSecurityProfile(self, password=None, roles=None, domains=None):
199 # """Set the user's basic security profile"""
201 # # This is really hackish. The Zope User API needs methods
202 # # for performing these functions.
203 # if password is not None:
205 # if roles is not None:
207 # if domains is not None:
208 # u.domains = domains
211 # def getMemberFullName(self, nameBefore=1) :
212 # """ Return the best full name representation """
213 # memberName = self.getProperty('name', default='')
214 # memberGivenName = self.getProperty('given_name', default='')
215 # memberId = self.getProperty('id', default='')
216 # return formatFullName(memberName, memberGivenName, memberId, nameBefore=nameBefore)
219 # def getMemberSortableFormat(self) :
220 # """ Return a specific format of full name for alphabetical sorting """
221 # return self.getMemberFullName(nameBefore = 1).lower()
225 # ## overload default security declaration
226 # security.declareProtected(SetMemberProperties, 'setMemberProperties')
227 # def setMemberProperties(self, mapping):
228 # BaseData.setMemberProperties(self, mapping)
229 # self.reindexObject()
232 # security.declarePrivate('manage_beforeDelete')
233 # def manage_beforeDelete(self) :
234 # """ uncatalog object """
235 # self.unindexObject()
238 # def _setPortalTypeName(self, pt) :
239 # """ Static Dynamic Type ;-) """
243 # # user object interface
244 # # overloads to make methods not publishable
246 # def getUserName(self):
247 # return BaseData.getUserName(self)
250 # return BaseData.getId(self)
252 # def getRoles(self):
253 # return BaseData.getRoles(self)
255 # def getRolesInContext(self, object):
256 # return BaseData.getRolesInContext(self, object)
258 # def getDomains(self):
259 # return BaseData.getDomains(self)
261 # def has_role(self, roles, object=None):
262 # return BaseData.has_role(self, roles, object=None)
266 InitializeClass(MemberData
)