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
.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
45 class MemberDataTool (BaseTool
):
46 """ This tool wraps user objects, making them act as Member objects.
49 meta_type
= 'Plinn Member Data Tool'
50 ## __implements__ = (IMemberDataTool, ActionProviderBase.__implements__)
52 security
= ClassSecurityInfo()
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')
62 def wrapUser(self
, u
) :
63 wu
= super(MemberDataTool
, self
).wrapUser(u
)
64 return wu
.__of
__(self
).__of
__(u
)
67 def __bobo_traverse__(self
, REQUEST
, name
):
68 if hasattr(self
,name
):
69 return getattr(self
,name
)
71 if self
._members
.has_key(name
) :
72 return self
.wrapUser(self
.acl_users
.getUser(name
))
74 InitializeClass(MemberDataTool
)
77 class MemberAdapter(BaseMemberAdapter
, SimpleItem
, DynamicType
, CMFCatalogAware
):
79 """Member data adapter.
82 adapts(IUser
, IMemberDataTool
)
85 portal_type
= 'Member Data'
87 security
= ClassSecurityInfo()
89 def __init__(self
, user
, tool
):
90 super(MemberAdapter
, self
).__init
__(user
, tool
)
91 self
.id = self
.getId()
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
)
101 def getMemberSortableFormat(self
) :
102 """ Return a specific format of full name for alphabetical sorting """
103 return self
.getMemberFullName(nameBefore
= 1).lower()
106 security
.declareProtected(SetMemberProperties
, 'setMemberProperties')
107 def setMemberProperties(self
, mapping
):
108 super(MemberAdapter
, self
).setMemberProperties(mapping
)
112 InitializeClass(MemberAdapter
)
115 class MemberData (BaseData
, DynamicType
, CMFCatalogAware
):
117 ## __implements__ = IMemberData
119 portal_type
= 'Member Data'
121 security
= ClassSecurityInfo()
123 security
.declareProtected(SetMemberPassword
, 'setMemberPassword')
124 def setMemberPassword(self
, password
, domains
=None) :
125 """ set member password """
127 registration
= getToolByName(self
, 'portal_registration', None)
129 failMessage
= registration
.testPasswordValidity(password
)
130 if failMessage
is not None:
131 raise 'Bad Request', failMessage
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
)
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"""
144 # This is really hackish. The Zope User API needs methods
145 # for performing these functions.
146 if password
is not None:
148 if roles
is not None:
150 if domains
is not None:
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)
162 # def getMemberSortableFormat(self) :
163 # """ Return a specific format of full name for alphabetical sorting """
164 # return self.getMemberFullName(nameBefore = 1).lower()
168 # ## overload default security declaration
169 # security.declareProtected(SetMemberProperties, 'setMemberProperties')
170 # def setMemberProperties(self, mapping):
171 # BaseData.setMemberProperties(self, mapping)
172 # self.reindexObject()
174 security
.declarePrivate('manage_beforeDelete')
175 def manage_beforeDelete(self
) :
176 """ uncatalog object """
179 def _setPortalTypeName(self
, pt
) :
180 """ Static Dynamic Type ;-) """
183 # user object interface
184 # overloads to make methods not publishable
186 def getUserName(self
):
187 return BaseData
.getUserName(self
)
190 return BaseData
.getId(self
)
193 return BaseData
.getRoles(self
)
195 def getRolesInContext(self
, object):
196 return BaseData
.getRolesInContext(self
, object)
198 def getDomains(self
):
199 return BaseData
.getDomains(self
)
201 def has_role(self
, roles
, object=None):
202 return BaseData
.has_role(self
, roles
, object=None)
206 InitializeClass(MemberData
)