Édition des propriétés des membres, à partir de l'annuaire, à nouveau possible.
[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.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
43
44
45 class MemberDataTool (BaseTool):
46 """ This tool wraps user objects, making them act as Member objects.
47 """
48
49 meta_type = 'Plinn Member Data Tool'
50 ## __implements__ = (IMemberDataTool, ActionProviderBase.__implements__)
51
52 security = ClassSecurityInfo()
53
54 def __init__(self):
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')
61
62 def wrapUser(self, u) :
63 wu = super(MemberDataTool, self).wrapUser(u)
64 return wu.__of__(self).__of__(u)
65
66
67 def __bobo_traverse__(self, REQUEST, name):
68 if hasattr(self,name):
69 return getattr(self,name)
70 else:
71 if self._members.has_key(name) :
72 return self.wrapUser(self.acl_users.getUser(name))
73
74 InitializeClass(MemberDataTool)
75
76
77 class MemberAdapter(BaseMemberAdapter, SimpleItem, DynamicType, CMFCatalogAware):
78
79 """Member data adapter.
80 """
81
82 adapts(IUser, IMemberDataTool)
83 implements(IMember)
84
85 portal_type = 'Member Data'
86
87 security = ClassSecurityInfo()
88
89 def __init__(self, user, tool):
90 super(MemberAdapter, self).__init__(user, tool)
91 self.id = self.getId()
92
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)
100
101 def getMemberSortableFormat(self) :
102 """ Return a specific format of full name for alphabetical sorting """
103 return self.getMemberFullName(nameBefore = 1).lower()
104
105 # security overload
106 security.declareProtected(SetMemberProperties, 'setMemberProperties')
107 def setMemberProperties(self, mapping):
108 super(MemberAdapter, self).setMemberProperties(mapping)
109 self.reindexObject()
110
111
112 InitializeClass(MemberAdapter)
113
114
115 class MemberData (BaseData, DynamicType, CMFCatalogAware):
116
117 ## __implements__ = IMemberData
118
119 portal_type = 'Member Data'
120
121 security = ClassSecurityInfo()
122
123 security.declareProtected(SetMemberPassword, 'setMemberPassword')
124 def setMemberPassword(self, password, domains=None) :
125 """ set member password """
126
127 registration = getToolByName(self, 'portal_registration', None)
128 if registration:
129 failMessage = registration.testPasswordValidity(password)
130 if failMessage is not None:
131 raise 'Bad Request', failMessage
132
133 user_folder = self.acl_users
134 self.setSecurityProfile(password=password, domains=domains)
135 if user_folder.meta_type == 'Group User Folder' :
136 self.changePassword(password)
137
138
139 #XXX restore the previous implementation for GRUF 2 I'll remove that later...
140 security.declarePrivate('setSecurityProfile')
141 def setSecurityProfile(self, password=None, roles=None, domains=None):
142 """Set the user's basic security profile"""
143 u = self.getUser()
144 # This is really hackish. The Zope User API needs methods
145 # for performing these functions.
146 if password is not None:
147 u.__ = password
148 if roles is not None:
149 u.roles = roles
150 if domains is not None:
151 u.domains = domains
152
153 # migré
154 # def getMemberFullName(self, nameBefore=1) :
155 # """ Return the best full name representation """
156 # memberName = self.getProperty('name', default='')
157 # memberGivenName = self.getProperty('given_name', default='')
158 # memberId = self.getProperty('id', default='')
159 # return formatFullName(memberName, memberGivenName, memberId, nameBefore=nameBefore)
160
161 # migré
162 # def getMemberSortableFormat(self) :
163 # """ Return a specific format of full name for alphabetical sorting """
164 # return self.getMemberFullName(nameBefore = 1).lower()
165
166
167 # migré
168 # ## overload default security declaration
169 # security.declareProtected(SetMemberProperties, 'setMemberProperties')
170 # def setMemberProperties(self, mapping):
171 # BaseData.setMemberProperties(self, mapping)
172 # self.reindexObject()
173
174 security.declarePrivate('manage_beforeDelete')
175 def manage_beforeDelete(self) :
176 """ uncatalog object """
177 self.unindexObject()
178
179 def _setPortalTypeName(self, pt) :
180 """ Static Dynamic Type ;-) """
181 pass
182
183 # user object interface
184 # overloads to make methods not publishable
185
186 def getUserName(self):
187 return BaseData.getUserName(self)
188
189 def getId(self):
190 return BaseData.getId(self)
191
192 def getRoles(self):
193 return BaseData.getRoles(self)
194
195 def getRolesInContext(self, object):
196 return BaseData.getRolesInContext(self, object)
197
198 def getDomains(self):
199 return BaseData.getDomains(self)
200
201 def has_role(self, roles, object=None):
202 return BaseData.has_role(self, roles, object=None)
203
204
205
206 InitializeClass(MemberData)