Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Static Private Attributes
CMFPlone.MembershipTool.MembershipTool Class Reference
Inheritance diagram for CMFPlone.MembershipTool.MembershipTool:
Inheritance graph
[legend]
Collaboration diagram for CMFPlone.MembershipTool.MembershipTool:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def manage_setMemberAreaType
def setMemberAreaType
def getMemberInfo
def getPersonalPortrait
def deletePersonalPortrait
def getHomeFolder
def getPersonalFolder
def changeMemberPortrait
def listMembers
def listMemberIds
def testCurrentPassword
def setPassword
def getCandidateLocalRoles
def loginUser
def logoutUser
def immediateLogout
def setLoginTimes
def getBadMembers

Public Attributes

 memberarea_type

Static Public Attributes

 meta_type = ToolNames.MembershipTool
string toolicon = 'skins/plone_images/user.gif'
int plone_tool = 1
string personal_id = '.personal'
string portrait_id = 'MyPortrait'
string default_portrait = 'defaultUser.gif'
string memberarea_type = 'Folder'
tuple security = ClassSecurityInfo()
tuple manage_options
tuple manage_mapRoles = DTMLFile('www/membershipRolemapping', globals())
tuple manage_portrait_fix = DTMLFile('www/portrait_fix', globals())
tuple setPassword = postonly(setPassword)

Private Member Functions

def _findUsersAclHome

Static Private Attributes

tuple __implements__ = (PloneBaseTool.__implements__, BaseTool.__implements__, )

Detailed Description

Definition at line 29 of file MembershipTool.py.


Member Function Documentation

def CMFPlone.MembershipTool.MembershipTool._findUsersAclHome (   self,
  userid 
) [private]

Definition at line 223 of file MembershipTool.py.

00223 
00224     def _findUsersAclHome(self, userid):
00225         portal = getToolByName(self, 'portal_url').getPortalObject()
00226         acl_users=portal.acl_users
00227         parent = acl_users
00228         while parent:
00229             if acl_users.aq_explicit.getUserById(userid, None) is not None:
00230                 break
00231             parent = aq_parent(aq_inner(parent)).aq_parent
00232             acl_users = getattr(parent, 'acl_users')
00233         if parent:
00234             return acl_users
00235         else:
00236             return None

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFPlone.MembershipTool.MembershipTool.changeMemberPortrait (   self,
  portrait,
  member_id = None 
)
given a portrait we will modify the users portrait
we put this method here because we do not want
.personal or portrait in the catalog

Definition at line 172 of file MembershipTool.py.

00172 
00173     def changeMemberPortrait(self, portrait, member_id=None):
00174         """
00175         given a portrait we will modify the users portrait
00176         we put this method here because we do not want
00177         .personal or portrait in the catalog
00178         """
00179         if not member_id:
00180             member_id = self.getAuthenticatedMember().getId()
00181 
00182         if portrait and portrait.filename:
00183             scaled, mimetype = scale_image(portrait)
00184             portrait = Image(id=member_id, file=scaled, title='')
00185             membertool   = getToolByName(self, 'portal_memberdata')
00186             membertool._setPortrait(portrait, member_id)

Here is the call graph for this function:

def CMFPlone.MembershipTool.MembershipTool.deletePersonalPortrait (   self,
  member_id = None 
)
deletes the Portrait of member_id

Definition at line 123 of file MembershipTool.py.

00123 
00124     def deletePersonalPortrait(self, member_id = None):
00125         """
00126         deletes the Portrait of member_id
00127         """
00128         membertool   = getToolByName(self, 'portal_memberdata')
00129 
00130         if not member_id:
00131             member_id = self.getAuthenticatedMember().getId()
00132 
00133         membertool._deletePortrait(member_id)

Here is the call graph for this function:

Will search for members with bad images in the portal_memberdata
delete their portraits and return their member ids

Definition at line 392 of file MembershipTool.py.

00392 
00393     def getBadMembers(self):
00394         """Will search for members with bad images in the portal_memberdata
00395         delete their portraits and return their member ids"""
00396         memberdata = getToolByName(self, 'portal_memberdata')
00397         portraits = getattr(memberdata, 'portraits', None)
00398         if portraits is None:
00399             return []
00400         bad_member_ids = []
00401         import transaction
00402         TXN_THRESHOLD = 50
00403         counter = 1
00404         for member_id in tuple(portraits.objectIds()):
00405             portrait = portraits[member_id]
00406             portrait_data = str(portrait.data)
00407             if portrait_data == '':
00408                 continue
00409             try:
00410                 img = PIL.Image.open(StringIO(portrait_data))
00411             except ConflictError:
00412                 pass
00413             except:
00414                 # Anything else we have a bad bad image and we destroy it
00415                 # and ask questions later.
00416                 portraits._delObject(member_id)
00417                 bad_member_ids.append(member_id)
00418             if not counter%TXN_THRESHOLD:
00419                 transaction.savepoint(optimistic=True)
00420             counter = counter + 1
00421 
00422         return bad_member_ids
00423 
00424 MembershipTool.__doc__ = BaseTool.__doc__
00425 
00426 InitializeClass(MembershipTool)

Here is the call graph for this function:

What local roles can I assign?
    Override the CMFCore version so that we can see the local roles on
    an object, and so that local managers can assign all roles locally.

Definition at line 268 of file MembershipTool.py.

00268 
00269     def getCandidateLocalRoles(self, obj):
00270         """ What local roles can I assign?
00271             Override the CMFCore version so that we can see the local roles on
00272             an object, and so that local managers can assign all roles locally.
00273         """
00274         member = self.getAuthenticatedMember()
00275         # Use getRolesInContext as someone may be a local manager
00276         if 'Manager' in member.getRolesInContext(obj):
00277             # Use valid_roles as we may want roles defined only on a subobject
00278             local_roles = [r for r in obj.valid_roles() if r not in
00279                             ('Anonymous', 'Authenticated', 'Shared')]
00280         else:
00281             local_roles = [ role for role in member.getRolesInContext(obj)
00282                             if role not in ('Member', 'Authenticated') ]
00283         local_roles.sort()
00284         return tuple(local_roles)
00285 

Here is the call graph for this function:

def CMFPlone.MembershipTool.MembershipTool.getHomeFolder (   self,
  id = None,
  verifyPermission = 0 
)
Return a member's home folder object, or None.
dwm: straight from CMF1.5.2

Definition at line 135 of file MembershipTool.py.

00135 
00136     def getHomeFolder(self, id=None, verifyPermission=0):
00137         """ Return a member's home folder object, or None.
00138         dwm: straight from CMF1.5.2
00139         """
00140         if id is None:
00141             member = self.getAuthenticatedMember()
00142             if not hasattr(member, 'getMemberId'):
00143                 return None
00144             id = member.getMemberId()
00145         members = self.getMembersFolder()
00146         if members:
00147             try:
00148                 folder = members._getOb(id)
00149                 if verifyPermission and not _checkPermission(View, folder):
00150                     # Don't return the folder if the user can't get to it.
00151                     return None
00152                 return folder
00153             # KeyError added to deal with btree member folders
00154             except (AttributeError, KeyError, TypeError):
00155                 pass
00156         return None

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFPlone.MembershipTool.MembershipTool.getMemberInfo (   self,
  memberId = None 
)
Return 'harmless' Memberinfo of any member, such as Full name,
Location, etc

Definition at line 76 of file MembershipTool.py.

00076 
00077     def getMemberInfo(self, memberId=None):
00078         """
00079         Return 'harmless' Memberinfo of any member, such as Full name,
00080         Location, etc
00081         """
00082         if not memberId:
00083             member = self.getAuthenticatedMember()
00084         else:
00085             member = self.getMemberById(memberId)
00086 
00087         if member is None:
00088             return None
00089 
00090         memberinfo = { 'fullname'    : member.getProperty('fullname'),
00091                        'description' : member.getProperty('description'),
00092                        'location'    : member.getProperty('location'),
00093                        'language'    : member.getProperty('language'),
00094                        'home_page'   : member.getProperty('home_page'),
00095                        'username'    : member.getUserName(),
00096                      }
00097 
00098         return memberinfo

Here is the call graph for this function:

def CMFPlone.MembershipTool.MembershipTool.getPersonalFolder (   self,
  member_id = None 
)
returns the Personal Item folder for a member
if no Personal Folder exists will return None

Definition at line 158 of file MembershipTool.py.

00158 
00159     def getPersonalFolder(self, member_id=None):
00160         """
00161         returns the Personal Item folder for a member
00162         if no Personal Folder exists will return None
00163         """
00164         home=self.getHomeFolder(member_id)
00165         personal=None
00166         if home:
00167             personal=getattr( home
00168                             , self.personal_id
00169                             , None )
00170         return personal

Here is the call graph for this function:

def CMFPlone.MembershipTool.MembershipTool.getPersonalPortrait (   self,
  member_id = None,
  verifyPermission = 0 
)
returns the Portrait for a member_id

Definition at line 100 of file MembershipTool.py.

00100 
00101     def getPersonalPortrait(self, member_id = None, verifyPermission=0):
00102         """
00103         returns the Portrait for a member_id
00104         """
00105         membertool   = getToolByName(self, 'portal_memberdata')
00106 
00107         if not member_id:
00108             member_id = self.getAuthenticatedMember().getId()
00109 
00110         portrait = membertool._getPortrait(member_id)
00111         if type(portrait) == type(''):
00112             portrait = None
00113         if portrait is not None:
00114             if verifyPermission and not _checkPermission('View', portrait):
00115                 # Don't return the portrait if the user can't get to it
00116                 portrait = None
00117         if portrait is None:
00118             portal = getToolByName(self, 'portal_url').getPortalObject()
00119             portrait = getattr(portal, default_portrait)
00120 
00121         return portrait

Here is the call graph for this function:

Log the current user out immediately.  Used by logout.py so that
    we do not have to do a redirect to show the logged out status. 

Definition at line 367 of file MembershipTool.py.

00367 
00368     def immediateLogout(self):
00369         """ Log the current user out immediately.  Used by logout.py so that
00370             we do not have to do a redirect to show the logged out status. """
00371         noSecurityManager()

Lists the ids of all members.  This may eventually be
replaced with a set of methods for querying pieces of the
list rather than the entire list at once.

Definition at line 202 of file MembershipTool.py.

00202 
00203     def listMemberIds(self):
00204         '''Lists the ids of all members.  This may eventually be
00205         replaced with a set of methods for querying pieces of the
00206         list rather than the entire list at once.
00207         '''
00208         uf = self.acl_users
00209         if hasattr(aq_base(uf), 'getPureUserIds'): # GRUF
00210             return uf.getPureUserIds()
00211         else:
00212             return self.__getPUS().getUserIds()

Here is the call graph for this function:

Gets the list of all members.
THIS METHOD MIGHT BE VERY EXPENSIVE ON LARGE USER FOLDERS AND MUST BE USED
WITH CARE! We plan to restrict its use in the future (ie. force large requests
to use searchForMembers instead of listMembers, so that it will not be
possible anymore to have a method returning several hundred of users :)

Definition at line 188 of file MembershipTool.py.

00188 
00189     def listMembers(self):
00190         '''Gets the list of all members.
00191         THIS METHOD MIGHT BE VERY EXPENSIVE ON LARGE USER FOLDERS AND MUST BE USED
00192         WITH CARE! We plan to restrict its use in the future (ie. force large requests
00193         to use searchForMembers instead of listMembers, so that it will not be
00194         possible anymore to have a method returning several hundred of users :)
00195         '''
00196         uf = self.acl_users
00197         if uf.meta_type == 'Group User Folder':
00198             return [BaseTool.wrapUser(self, x) for x in uf.getPureUsers()]
00199         else:
00200             return BaseTool.listMembers(self)

Here is the caller graph for this function:

def CMFPlone.MembershipTool.MembershipTool.loginUser (   self,
  REQUEST = None 
)
Handle a login for the current user.

This method takes care of all the standard work that needs to be
done when a user logs in:
- clear the copy/cut/paste clipboard
- PAS credentials update
- sending a logged-in event
- storing the login time
- create the member area if it does not exist

Definition at line 287 of file MembershipTool.py.

00287 
00288     def loginUser(self, REQUEST=None):
00289         """ Handle a login for the current user.
00290 
00291         This method takes care of all the standard work that needs to be
00292         done when a user logs in:
00293         - clear the copy/cut/paste clipboard
00294         - PAS credentials update
00295         - sending a logged-in event
00296         - storing the login time
00297         - create the member area if it does not exist
00298         """
00299         user=getSecurityManager().getUser()
00300         if user is None:
00301             return
00302 
00303         if self.setLoginTimes():
00304             event.notify(UserInitialLoginInEvent(user))
00305         else:
00306             event.notify(UserLoggedInEvent(user))
00307 
00308         if REQUEST is None:
00309             REQUEST=getattr(self, 'REQUEST', None)
00310         if REQUEST is None:
00311             return
00312 
00313         # Expire the clipboard
00314         if REQUEST.get('__cp', None) is not None:
00315             REQUEST.RESPONSE.expireCookie('__cp', path='/')
00316 
00317         self.createMemberArea()
00318 
00319         try:
00320             pas = getToolByName(self, 'acl_users')
00321             pas.credentials_cookie_auth.login()
00322         except AttributeError:
00323             # The cookie plugin may not be present
00324             pass
00325 

Here is the call graph for this function:

def CMFPlone.MembershipTool.MembershipTool.logoutUser (   self,
  REQUEST = None 
)
Process a user logout.

This takes care of all the standard logout work:
- ask the user folder to logout
- expire a skin selection cookie
- invalidate a Zope session if there is one

Definition at line 327 of file MembershipTool.py.

00327 
00328     def logoutUser(self, REQUEST=None):
00329         """Process a user logout.
00330 
00331         This takes care of all the standard logout work:
00332         - ask the user folder to logout
00333         - expire a skin selection cookie
00334         - invalidate a Zope session if there is one
00335         """
00336         # Invalidate existing sessions, but only if they exist.
00337         sdm = getToolByName(self, 'session_data_manager', None)
00338         if sdm is not None:
00339                 session = sdm.getSessionData(create=0)
00340                 if session is not None:
00341                             session.invalidate()
00342 
00343         if REQUEST is None:
00344             REQUEST=getattr(self, 'REQUEST', None)
00345         if REQUEST is not None:
00346             pas = getToolByName(self, 'acl_users')
00347             try:
00348                 pas.logout(REQUEST)
00349             except:
00350                 # XXX Bare except copied from logout.cpy. This should be
00351                 # changed in the next Plone release.
00352                 pass
00353 
00354             # Expire the skin cookie if it is not configured to persist
00355             st = getToolByName(self, "portal_skins")
00356             skinvar = st.getRequestVarname()
00357             if REQUEST.has_key(skinvar) and not st.getCookiePersistence():
00358                     portal = getToolByName(self, "portal_url").getPortalObject()
00359                     path = '/' + portal.absolute_url(1)
00360                     # XXX check if this path is sane
00361                     REQUEST.RESPONSE.expireCookie(skinvar, path=path)
00362 
00363         user=getSecurityManager().getUser()
00364         if user is not None:
00365             event.notify(UserLoggedOutEvent(user))

Here is the call graph for this function:

def CMFPlone.MembershipTool.MembershipTool.manage_setMemberAreaType (   self,
  type_name,
  REQUEST = None 
)
ZMI method to set the home folder type by its type name.

Definition at line 58 of file MembershipTool.py.

00058 
00059     def manage_setMemberAreaType(self, type_name, REQUEST=None):
00060         """ ZMI method to set the home folder type by its type name.
00061         """
00062         self.setMemberAreaType(type_name)
00063         if REQUEST is not None:
00064             REQUEST['RESPONSE'].redirect(self.absolute_url()
00065                     + '/manage_mapRoles'
00066                     + '?manage_tabs_message=Member+area+type+changed.')

Here is the call graph for this function:

Called by logged_in to set the login time properties
    even if members lack the "Set own properties" permission.

    The return value indicates if this is the first logged
    login time.

Definition at line 373 of file MembershipTool.py.

00373 
00374     def setLoginTimes(self):
00375         """ Called by logged_in to set the login time properties
00376             even if members lack the "Set own properties" permission.
00377 
00378             The return value indicates if this is the first logged
00379             login time.
00380         """
00381         res=False
00382         if not self.isAnonymousUser():
00383             member = self.getAuthenticatedMember()
00384             login_time = member.getProperty('login_time', '2000/01/01')
00385             if str(login_time) == '2000/01/01':
00386                 res=True
00387                 login_time = self.ZopeTime()
00388             member.setProperties(login_time=self.ZopeTime(),
00389                                  last_login_time=login_time)
00390         return res

Here is the call graph for this function:

Here is the caller graph for this function:

Sets the portal type to use for new home folders.

Definition at line 68 of file MembershipTool.py.

00068 
00069     def setMemberAreaType(self, type_name):
00070         """ Sets the portal type to use for new home folders.
00071         """
00072         # No check for folderish since someone somewhere may actually want
00073         # members to have objects instead of folders as home "directory".
00074         self.memberarea_type = str(type_name).strip()

Here is the caller graph for this function:

def CMFPlone.MembershipTool.MembershipTool.setPassword (   self,
  password,
  domains = None,
  REQUEST = None 
)
Allows the authenticated member to set his/her own password.

Definition at line 238 of file MembershipTool.py.

00238 
00239     def setPassword(self, password, domains=None, REQUEST=None):
00240         '''Allows the authenticated member to set his/her own password.
00241         '''
00242         registration = getToolByName(self, 'portal_registration', None)
00243         if not self.isAnonymousUser():
00244             member = self.getAuthenticatedMember()
00245             acl_users = self._findUsersAclHome(member.getUserId())#self.acl_users
00246             if not acl_users:
00247                 # should not possibly ever happen
00248                 raise BadRequest, 'did not find current user in any user folder'
00249             if registration:
00250                 failMessage = registration.testPasswordValidity(password)
00251                 if failMessage is not None:
00252                     raise BadRequest, failMessage
00253 
00254             if domains is None:
00255                 domains = []
00256             user = acl_users.getUserById(member.getUserId(), None)
00257             # we must change the users password trough grufs changepassword
00258             # to keep her  group settings
00259             if hasattr(user, 'changePassword'):
00260                 user.changePassword(password)
00261             else:
00262                 acl_users._doChangeUser(member.getUserId(), password, member.getRoles(), domains)
00263             self.credentialsChanged(password, REQUEST=REQUEST)
00264         else:
            raise BadRequest, 'Not logged in.'

Here is the call graph for this function:

test to see if password is current 

Definition at line 214 of file MembershipTool.py.

00214 
00215     def testCurrentPassword(self, password):
00216         """ test to see if password is current """
00217         REQUEST=getattr(self, 'REQUEST', {})
00218         userid=self.getAuthenticatedMember().getUserId()
00219         acl_users = self._findUsersAclHome(userid)
00220         if not acl_users:
00221             return 0
00222         return acl_users.authenticate(userid, password, REQUEST)

Here is the call graph for this function:


Member Data Documentation

tuple CMFPlone.MembershipTool.MembershipTool.__implements__ = (PloneBaseTool.__implements__, BaseTool.__implements__, ) [static, private]

Definition at line 40 of file MembershipTool.py.

string CMFPlone.MembershipTool.MembershipTool.default_portrait = 'defaultUser.gif' [static]

Definition at line 36 of file MembershipTool.py.

tuple CMFPlone.MembershipTool.MembershipTool.manage_mapRoles = DTMLFile('www/membershipRolemapping', globals()) [static]

Definition at line 52 of file MembershipTool.py.

Initial value:
(BaseTool.manage_options +
                      ( { 'label' : 'Portraits'
                     , 'action' : 'manage_portrait_fix'
                     },))

Definition at line 42 of file MembershipTool.py.

tuple CMFPlone.MembershipTool.MembershipTool.manage_portrait_fix = DTMLFile('www/portrait_fix', globals()) [static]

Definition at line 55 of file MembershipTool.py.

Definition at line 37 of file MembershipTool.py.

Definition at line 73 of file MembershipTool.py.

Definition at line 31 of file MembershipTool.py.

Definition at line 34 of file MembershipTool.py.

Definition at line 33 of file MembershipTool.py.

Definition at line 35 of file MembershipTool.py.

tuple CMFPlone.MembershipTool.MembershipTool.security = ClassSecurityInfo() [static]

Definition at line 38 of file MembershipTool.py.

Definition at line 265 of file MembershipTool.py.

string CMFPlone.MembershipTool.MembershipTool.toolicon = 'skins/plone_images/user.gif' [static]

Definition at line 32 of file MembershipTool.py.


The documentation for this class was generated from the following file: