Renommage variable dans méthodes de manipulation de la file d'envoi.
[Plinn.git] / MemberDataTool.py
1 # -*- coding: utf-8 -*-
2 #######################################################################################
3 # Plinn - http://plinn.org #
4 # Copyright (C) 2005-2007 Benoît PIN <benoit.pin@ensmp.fr> #
5 # #
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. #
10 # #
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. #
15 # #
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.
21
22
23
24 """
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
46
47
48 class MemberDataTool (BaseTool):
49 """ This tool wraps user objects, making them act as Member objects.
50 """
51
52 meta_type = 'Plinn Member Data Tool'
53 ## __implements__ = (IMemberDataTool, ActionProviderBase.__implements__)
54
55 security = ClassSecurityInfo()
56
57 def __init__(self):
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')
64
65 def wrapUser(self, u) :
66 wu = super(MemberDataTool, self).wrapUser(u)
67 return wu.__of__(self).__of__(u)
68
69
70 def __bobo_traverse__(self, REQUEST, name):
71 if hasattr(self,name):
72 return getattr(self,name)
73 else:
74 if self._members.has_key(name) :
75 return self.wrapUser(self.acl_users.getUser(name))
76
77 InitializeClass(MemberDataTool)
78
79
80 class MemberAdapter(BaseMemberAdapter, SimpleItem, DynamicType, CMFCatalogAware):
81
82 """Member data adapter.
83 """
84
85 adapts(IUser, IMemberDataTool)
86 implements(IMember)
87
88 portal_type = 'Member Data'
89
90 security = ClassSecurityInfo()
91
92 def __init__(self, user, tool):
93 super(MemberAdapter, self).__init__(user, tool)
94 self.id = self.getId()
95
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)
103
104 def getMemberSortableFormat(self) :
105 """ Return a specific format of full name for alphabetical sorting """
106 return self.getMemberFullName(nameBefore = 1).lower()
107
108 # security overload
109 security.declareProtected(SetMemberProperties, 'setMemberProperties')
110 def setMemberProperties(self, mapping):
111 super(MemberAdapter, self).setMemberProperties(mapping)
112 self.reindexObject()
113
114 security.declareProtected(SetMemberPassword, 'setMemberPassword')
115 def setMemberPassword(self, password, domains=None) :
116 """ set member password """
117
118 registration = getUtility(IRegistrationTool)
119 failMessage = registration.testPasswordValidity(password)
120 if failMessage is not None :
121 raise BadRequest(failMessage)
122
123 self.setSecurityProfile(password=password, domains=domains)
124
125 security.declarePrivate('setSecurityProfile')
126 def setSecurityProfile(self, password=None, roles=None, domains=None):
127 """Set the user's basic security profile"""
128 u = self.getUser()
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:
134 u.setRoles(roles)
135 if domains is not None:
136 u.setDomains(domains)
137
138 security.declarePrivate('manage_beforeDelete')
139 def manage_beforeDelete(self) :
140 """ uncatalog object """
141 self.unindexObject()
142
143 def _setPortalTypeName(self, pt) :
144 """ Static Dynamic Type ;-) """
145 pass
146
147 # user object interface
148 # overloads to make methods not publishable
149
150 def getUserName(self):
151 return super(MemberAdapter, self).getUserName()
152
153 def getId(self):
154 return super(MemberAdapter, self).getId()
155
156 def getRoles(self):
157 return self._user.aq_inner.getRoles()
158 # return super(MemberAdapter, self).getRoles()
159
160 def getRolesInContext(self, object):
161 return super(MemberAdapter, self).getRolesInContext(object)
162
163 def getDomains(self):
164 return super(MemberAdapter, self).getDomains()
165
166 def has_role(self, roles, object=None):
167 return super(MemberAdapter, self).has_role(roles, object=None)
168
169 InitializeClass(MemberAdapter)
170
171
172 class MemberData (BaseData, DynamicType, CMFCatalogAware):
173
174 ## __implements__ = IMemberData
175
176 portal_type = 'Member Data'
177
178 security = ClassSecurityInfo()
179 # migré
180 # security.declareProtected(SetMemberPassword, 'setMemberPassword')
181 # def setMemberPassword(self, password, domains=None) :
182 # """ set member password """
183 #
184 # registration = getToolByName(self, 'portal_registration', None)
185 # if registration:
186 # failMessage = registration.testPasswordValidity(password)
187 # if failMessage is not None:
188 # raise 'Bad Request', failMessage
189 #
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)
194
195
196 #migré
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"""
201 # u = self.getUser()
202 # # This is really hackish. The Zope User API needs methods
203 # # for performing these functions.
204 # if password is not None:
205 # u.__ = password
206 # if roles is not None:
207 # u.roles = roles
208 # if domains is not None:
209 # u.domains = domains
210
211 # migré
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)
218
219 # migré
220 # def getMemberSortableFormat(self) :
221 # """ Return a specific format of full name for alphabetical sorting """
222 # return self.getMemberFullName(nameBefore = 1).lower()
223
224
225 # migré
226 # ## overload default security declaration
227 # security.declareProtected(SetMemberProperties, 'setMemberProperties')
228 # def setMemberProperties(self, mapping):
229 # BaseData.setMemberProperties(self, mapping)
230 # self.reindexObject()
231
232 # migré
233 # security.declarePrivate('manage_beforeDelete')
234 # def manage_beforeDelete(self) :
235 # """ uncatalog object """
236 # self.unindexObject()
237
238 # migré
239 # def _setPortalTypeName(self, pt) :
240 # """ Static Dynamic Type ;-) """
241 # pass
242
243 # migré
244 # # user object interface
245 # # overloads to make methods not publishable
246 #
247 # def getUserName(self):
248 # return BaseData.getUserName(self)
249 #
250 # def getId(self):
251 # return BaseData.getId(self)
252 #
253 # def getRoles(self):
254 # return BaseData.getRoles(self)
255 #
256 # def getRolesInContext(self, object):
257 # return BaseData.getRolesInContext(self, object)
258 #
259 # def getDomains(self):
260 # return BaseData.getDomains(self)
261 #
262 # def has_role(self, roles, object=None):
263 # return BaseData.has_role(self, roles, object=None)
264
265
266
267 InitializeClass(MemberData)