bugfix envoi du formulaire par méthode get.
[Plinn.git] / MemberDataTool.py
index a2c25db..c83ff49 100755 (executable)
@@ -32,12 +32,15 @@ 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 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 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.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 Products.CMFCore.CMFCatalogAware import CMFCatalogAware
 from Products.CMFCore.DynamicType import DynamicType
+from Products.CMFCore.exceptions import BadRequest
 from utils import formatFullName
 from permissions import SetMemberProperties, SetMemberPassword
 
 from utils import formatFullName
 from permissions import SetMemberProperties, SetMemberPassword
 
@@ -101,36 +104,24 @@ class MemberAdapter(BaseMemberAdapter, SimpleItem, DynamicType, CMFCatalogAware)
        def getMemberSortableFormat(self) :
                """ Return a specific format of full name for alphabetical sorting """
                return self.getMemberFullName(nameBefore = 1).lower()
        def getMemberSortableFormat(self) :
                """ Return a specific format of full name for alphabetical sorting """
                return self.getMemberFullName(nameBefore = 1).lower()
-    
-
-InitializeClass(MemberAdapter)
-
-
-class MemberData (BaseData, DynamicType, CMFCatalogAware):
-
-##              __implements__ = IMemberData
-
-       portal_type = 'Member Data'
-
-       security = ClassSecurityInfo()
+       
+       # security overload
+       security.declareProtected(SetMemberProperties, 'setMemberProperties')
+       def setMemberProperties(self, mapping):
+               super(MemberAdapter, self).setMemberProperties(mapping)
+               self.reindexObject()
 
        security.declareProtected(SetMemberPassword, 'setMemberPassword')
        def setMemberPassword(self, password, domains=None) :
                """ set member password """
 
 
        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
+               registration = getUtility(IRegistrationTool)
+               failMessage = registration.testPasswordValidity(password)
+               if failMessage is not None :
+                       raise BadRequest(failMessage)
+
                self.setSecurityProfile(password=password, domains=domains)
                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"""
        security.declarePrivate('setSecurityProfile')
        def setSecurityProfile(self, password=None, roles=None, domains=None):
                """Set the user's basic security profile"""
@@ -138,60 +129,138 @@ class MemberData (BaseData, DynamicType, CMFCatalogAware):
                # This is really hackish.  The Zope User API needs methods
                # for performing these functions.
                if password is not None:
                # This is really hackish.  The Zope User API needs methods
                # for performing these functions.
                if password is not None:
-                       u.__ = password
+                       u.setPassword(password)
                if roles is not None:
                if roles is not None:
-                       u.roles = roles
+                       u.setRoles(roles)
                if domains is not None:
                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.declareProtected(SetMemberProperties, 'setMemberProperties')
-       def setMemberProperties(self, mapping):
-               BaseData.setMemberProperties(self, mapping)
-               self.reindexObject()
+                       u.setDomains(domains)
 
        security.declarePrivate('manage_beforeDelete')
        def manage_beforeDelete(self) :
                """ uncatalog object """
                self.unindexObject()
 
        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 _setPortalTypeName(self, pt) :
                """ Static Dynamic Type ;-) """
                pass
 
        # user object interface
        # overloads to make methods not publishable
-       
+
        def getUserName(self):
        def getUserName(self):
-               return BaseData.getUserName(self)
+               return super(MemberAdapter, self).getUserName()
 
        def getId(self):
 
        def getId(self):
-               return BaseData.getId(self)
+               return super(MemberAdapter, self).getId()
 
        def getRoles(self):
 
        def getRoles(self):
-               return BaseData.getRoles(self)
+               return self._user.aq_inner.getRoles()
+               # return super(MemberAdapter, self).getRoles()
 
        def getRolesInContext(self, object):
 
        def getRolesInContext(self, object):
-               return BaseData.getRolesInContext(self, object)
+               return super(MemberAdapter, self).getRolesInContext(object)
 
        def getDomains(self):
 
        def getDomains(self):
-               return BaseData.getDomains(self)
+               return super(MemberAdapter, self).getDomains()
 
        def has_role(self, roles, object=None):
 
        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)
+       
+
+#migré        
+       #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)