Migration méthodes (setMemberPassword entres autres).
[Plinn.git] / MemberDataTool.py
index a75f503..4a432eb 100755 (executable)
@@ -27,14 +27,17 @@ from Products.CMFCore.interfaces import IMemberDataTool
 from Globals import InitializeClass
 from Acquisition import aq_inner, aq_parent, aq_base
 from AccessControl import ClassSecurityInfo
+from OFS.SimpleItem import SimpleItem
 from Products.CMFCore.MemberDataTool import MemberDataTool as BaseTool
 from Products.CMFCore.MemberDataTool import MemberData as BaseData
 from Products.CMFCore.MemberDataTool import MemberAdapter as BaseMemberAdapter
 from zope.component import adapts
+from zope.component import getUtility
 from zope.interface import implements
 from Products.CMFCore.interfaces import IMember
+from Products.CMFCore.interfaces import IRegistrationTool
 # from Products.CMFCore.MemberDataTool import CleanupTemp
-from Products.CMFCore.utils import getToolByName
+#from Products.CMFCore.utils import getToolByName
 from Products.CMFCore.CMFCatalogAware import CMFCatalogAware
 from Products.CMFCore.DynamicType import DynamicType
 from utils import formatFullName
@@ -57,52 +60,11 @@ class MemberDataTool (BaseTool):
                self._setProperty('given_name', '', 'string')
                self._setProperty('wysiwyg_editor', 'FCK', 'string')
                self._setProperty('photo_width', 800, 'int')
-
-#      security.declarePrivate('wrapUser')
-#      def wrapUser(self, u):
-#              '''
-#              If possible, returns the Member object that corresponds
-#              to the given User object.
-#              '''
-#              id = u.getId()
-#              members = self._members
-#              if not id in members:
-#                      base = aq_base(self)
-#                      members[id] = MemberData(base, id)
-#              # Return a wrapper with self as containment and
-#              # the user as context.
-#              return members[id].__of__(self).__of__(u)
-
-#      security.declarePrivate('wrapUser')
-#      def wrapUser(self, u):
-#              """
-#              If possible, returns the Member object that corresponds
-#              to the given User object.
-#              """
-#              id = u.getId()
-#              members = self._members
-#              if not members.has_key(id):
-#                      # Get a temporary member that might be
-#                      # registered later via registerMemberData().
-#                      temps = self._v_temps
-#                      if temps is not None and temps.has_key(id):
-#                              m = temps[id]
-#                      else:
-#                              base = aq_base(self)
-#                              m = MemberData(base, id)
-#                              if temps is None:
-#                                      self._v_temps = {id:m}
-#                                      if hasattr(self, 'REQUEST'):
-#                                              # No REQUEST during tests.
-#                                              self.REQUEST._hold(CleanupTemp(self))
-#                              else:
-#                                      temps[id] = m
-#              else:
-#                      m = members[id]
-#              # Return a wrapper with self as containment and
-#              # the user as context.
-#              return m.__of__(self).__of__(u)
-
+       
+       def wrapUser(self, u) :
+           wu = super(MemberDataTool, self).wrapUser(u)
+           return wu.__of__(self).__of__(u)
+    
 
        def __bobo_traverse__(self, REQUEST, name):
                if hasattr(self,name):
@@ -114,13 +76,15 @@ class MemberDataTool (BaseTool):
 InitializeClass(MemberDataTool)
 
 
-class MemberAdapter(BaseMemberAdapter):
+class MemberAdapter(BaseMemberAdapter, SimpleItem, DynamicType, CMFCatalogAware):
 
        """Member data adapter.
        """
 
        adapts(IUser, IMemberDataTool)
        implements(IMember)
+       
+       portal_type = 'Member Data'
 
        security = ClassSecurityInfo()
        
@@ -135,97 +99,152 @@ class MemberAdapter(BaseMemberAdapter):
                memberGivenName = self.getProperty('given_name', default='')
                memberId = self.getId()
                return formatFullName(memberName, memberGivenName, memberId, nameBefore=nameBefore)
-    
-
-InitializeClass(MemberAdapter)
-
-
-class MemberData (BaseData, DynamicType, CMFCatalogAware):
-
-##              __implements__ = IMemberData
-
-       portal_type = 'Member Data'
-
-       security = ClassSecurityInfo()
-
-       security.declareProtected(SetMemberPassword, 'setMemberPassword')
-       def setMemberPassword(self, password, domains=None) :
-               """ set member password """
-
-               registration = getToolByName(self, 'portal_registration', None)
-               if registration:
-                       failMessage = registration.testPasswordValidity(password)
-                       if failMessage is not None:
-                               raise 'Bad Request', failMessage
-                               
-               user_folder = self.acl_users
-               self.setSecurityProfile(password=password, domains=domains)
-               if user_folder.meta_type == 'Group User Folder' :
-                       self.changePassword(password)
-       
-       
-       #XXX restore the previous implementation for GRUF 2 I'll remove that later...
-       security.declarePrivate('setSecurityProfile')
-       def setSecurityProfile(self, password=None, roles=None, domains=None):
-               """Set the user's basic security profile"""
-               u = self.getUser()
-               # This is really hackish.  The Zope User API needs methods
-               # for performing these functions.
-               if password is not None:
-                       u.__ = password
-               if roles is not None:
-                       u.roles = roles
-               if domains is not None:
-                       u.domains = domains
-
-
-       def getMemberFullName(self, nameBefore=1) :
-               """ Return the best full name representation """
-               memberName = self.getProperty('name', default='')
-               memberGivenName = self.getProperty('given_name', default='')
-               memberId = self.getProperty('id', default='')
-               return formatFullName(memberName, memberGivenName, memberId, nameBefore=nameBefore)
 
        def getMemberSortableFormat(self) :
                """ Return a specific format of full name for alphabetical sorting """
                return self.getMemberFullName(nameBefore = 1).lower()
-
-
-       ## overload default security declaration
+       
+       # security overload
        security.declareProtected(SetMemberProperties, 'setMemberProperties')
        def setMemberProperties(self, mapping):
-               BaseData.setMemberProperties(self, mapping)
+               super(MemberAdapter, self).setMemberProperties(mapping)
                self.reindexObject()
 
+       security.declareProtected(SetMemberPassword, 'setMemberPassword')
+       def setMemberPassword(self, password, domains=None) :
+               """ set member password """
+
+               registration = getUtility(IRegistrationTool)
+               failMessage = registration.testPasswordValidity(password)
+               if failMessage is not None :
+                       raise ValueError(failMessage)
+
+               self.setSecurityProfile(password=password, domains=domains)
+
        security.declarePrivate('manage_beforeDelete')
        def manage_beforeDelete(self) :
                """ uncatalog object """
                self.unindexObject()
-
+    
        def _setPortalTypeName(self, pt) :
                """ Static Dynamic Type ;-) """
                pass
 
        # user object interface
        # overloads to make methods not publishable
-       
+
        def getUserName(self):
-               return BaseData.getUserName(self)
+               return super(MemberAdapter, self).getUserName()
 
        def getId(self):
-               return BaseData.getId(self)
+               return super(MemberAdapter, self).getId()
 
        def getRoles(self):
-               return BaseData.getRoles(self)
+               return super(MemberAdapter, self).getRoles()
 
        def getRolesInContext(self, object):
-               return BaseData.getRolesInContext(self, object)
+               return super(MemberAdapter, self).getRolesInContext(object)
 
        def getDomains(self):
-               return BaseData.getDomains(self)
+               return super(MemberAdapter, self).getDomains()
 
        def has_role(self, roles, object=None):
-               return BaseData.has_role(self, roles, object=None)
+               return super(MemberAdapter, self).has_role(roles, object=None)
+
+InitializeClass(MemberAdapter)
+
+
+class MemberData (BaseData, DynamicType, CMFCatalogAware):
+
+##              __implements__ = IMemberData
+
+       portal_type = 'Member Data'
+
+       security = ClassSecurityInfo()
+# migré
+#      security.declareProtected(SetMemberPassword, 'setMemberPassword')
+#      def setMemberPassword(self, password, domains=None) :
+#              """ set member password """
+#
+#              registration = getToolByName(self, 'portal_registration', None)
+#              if registration:
+#                      failMessage = registration.testPasswordValidity(password)
+#                      if failMessage is not None:
+#                              raise 'Bad Request', failMessage
+#                              
+#              user_folder = self.acl_users
+#              self.setSecurityProfile(password=password, domains=domains)
+#              if user_folder.meta_type == 'Group User Folder' :
+#                      self.changePassword(password)
+       
+       
+       #XXX restore the previous implementation for GRUF 2 I'll remove that later...
+       security.declarePrivate('setSecurityProfile')
+       def setSecurityProfile(self, password=None, roles=None, domains=None):
+               """Set the user's basic security profile"""
+               u = self.getUser()
+               # This is really hackish.  The Zope User API needs methods
+               # for performing these functions.
+               if password is not None:
+                       u.__ = password
+               if roles is not None:
+                       u.roles = roles
+               if domains is not None:
+                       u.domains = domains
+
+# migré
+#      def getMemberFullName(self, nameBefore=1) :
+#              """ Return the best full name representation """
+#              memberName = self.getProperty('name', default='')
+#              memberGivenName = self.getProperty('given_name', default='')
+#              memberId = self.getProperty('id', default='')
+#              return formatFullName(memberName, memberGivenName, memberId, nameBefore=nameBefore)
+
+# migré
+#      def getMemberSortableFormat(self) :
+#              """ Return a specific format of full name for alphabetical sorting """
+#              return self.getMemberFullName(nameBefore = 1).lower()
+
+
+# migré
+#      ## overload default security declaration
+#      security.declareProtected(SetMemberProperties, 'setMemberProperties')
+#      def setMemberProperties(self, mapping):
+#              BaseData.setMemberProperties(self, mapping)
+#              self.reindexObject()
+
+# migré
+#      security.declarePrivate('manage_beforeDelete')
+#      def manage_beforeDelete(self) :
+#              """ uncatalog object """
+#              self.unindexObject()
+
+# migré
+#      def _setPortalTypeName(self, pt) :
+#              """ Static Dynamic Type ;-) """
+#              pass
+
+# migré
+#      # user object interface
+#      # overloads to make methods not publishable
+#      
+#      def getUserName(self):
+#              return BaseData.getUserName(self)
+#
+#      def getId(self):
+#              return BaseData.getId(self)
+#
+#      def getRoles(self):
+#              return BaseData.getRoles(self)
+#
+#      def getRolesInContext(self, object):
+#              return BaseData.getRolesInContext(self, object)
+#
+#      def getDomains(self):
+#              return BaseData.getDomains(self)
+#
+#      def has_role(self, roles, object=None):
+#              return BaseData.has_role(self, roles, object=None)