Back to index

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

List of all members.

Public Member Functions

def addMember
def searchForMembers
def createMemberarea
 sanitize home folders (we may get URL-illegal ids)
def getHomeFolder
def getPersonalPortrait
def deletePersonalPortrait
def changeMemberPortrait

Static Public Attributes

string meta_type = "PlonePAS Membership Tool"
string toolicon = 'tool.gif'
tuple security = ClassSecurityInfo()
tuple user_search_keywords
 createMemberArea = createMemberarea

Private Member Functions

def _getSafeMemberId

Static Private Attributes

tuple _properties

Detailed Description

PAS-based customization of MembershipTool.

Uses CMFPlone's as base.

Definition at line 37 of file membership.py.


Member Function Documentation

def PlonePAS.tools.membership.MembershipTool._getSafeMemberId (   self,
  id = None 
) [private]
Return a safe version of a member id.

If no id is given return the id for the currently authenticated user.

Definition at line 309 of file membership.py.

00309 
00310     def _getSafeMemberId(self, id=None):
00311         """Return a safe version of a member id.
00312 
00313         If no id is given return the id for the currently authenticated user.
00314         """
00315 
00316         if id is None:
00317             member = self.getAuthenticatedMember()
00318             if not hasattr(member, 'getMemberId'):
00319                 return None
00320             id = member.getMemberId()
00321 
00322         return cleanId(id)

Here is the call graph for this function:

Here is the caller graph for this function:

def PlonePAS.tools.membership.MembershipTool.addMember (   self,
  id,
  password,
  roles,
  domains,
  properties = None 
)
Adds a new member to the user folder.

Security checks will have already been performed.  Called by
portal_registration.  This one specific to PAS. PAS ignores
domains. Adding members with login_name also not yet
supported.

Definition at line 57 of file membership.py.

00057 
00058     def addMember(self, id, password, roles, domains, properties=None):
00059         """Adds a new member to the user folder.
00060 
00061         Security checks will have already been performed.  Called by
00062         portal_registration.  This one specific to PAS. PAS ignores
00063         domains. Adding members with login_name also not yet
00064         supported.
00065         """
00066         acl_users = self.acl_users
00067         acl_users._doAddUser(id, password, roles, domains)
00068 
00069         if properties is not None:
00070             member = self.getMemberById(id)
00071             member.setMemberProperties(properties)

Here is the call graph for this function:

def PlonePAS.tools.membership.MembershipTool.changeMemberPortrait (   self,
  portrait,
  id = None 
)
update the portait of a member.

Modified from CMFPlone version to URL-quote the member id.

Definition at line 352 of file membership.py.

00352 
00353     def changeMemberPortrait(self, portrait, id=None):
00354         """update the portait of a member.
00355 
00356         Modified from CMFPlone version to URL-quote the member id.
00357         """
00358         safe_id = self._getSafeMemberId(id)
00359         return BaseMembershipTool.changeMemberPortrait(self, portrait, safe_id)
00360 
00361 InitializeClass(MembershipTool)
00362 

Here is the call graph for this function:

def PlonePAS.tools.membership.MembershipTool.createMemberarea (   self,
  member_id = None,
  minimal = True 
)

sanitize home folders (we may get URL-illegal ids)

Create a member area for 'member_id' or the authenticated
user, but don't assume that member_id is url-safe.

Unfortunately, a pretty close copy of the (very large)
original and only a few lines different.  Plone should
probably do this.

Definition at line 203 of file membership.py.

00203 
00204     def createMemberarea(self, member_id=None, minimal=True):
00205         """
00206         Create a member area for 'member_id' or the authenticated
00207         user, but don't assume that member_id is url-safe.
00208 
00209         Unfortunately, a pretty close copy of the (very large)
00210         original and only a few lines different.  Plone should
00211         probably do this.
00212         """
00213         if not self.getMemberareaCreationFlag():
00214             return None
00215         catalog = getToolByName(self, 'portal_catalog')
00216         membership = getToolByName(self, 'portal_membership')
00217         members = self.getMembersFolder()
00218 
00219         if not member_id:
00220             # member_id is optional (see CMFCore.interfaces.portal_membership:
00221             #     Create a member area for 'member_id' or authenticated user.)
00222             member = membership.getAuthenticatedMember()
00223             member_id = member.getId()
00224 
00225         if hasattr(members, 'aq_explicit'):
00226             members=members.aq_explicit
00227 
00228         if members is None:
00229             # no members area
00230             logger.debug('createMemberarea: members area does not exist.')
00231             return
00232 
00233         safe_member_id = cleanId(member_id)
00234         if hasattr(members, safe_member_id):
00235             # has already this member
00236             logger.debug(
00237                 'createMemberarea: member area '
00238                 'for %r already exists.' % safe_member_id)
00239             return
00240 
00241         if not safe_member_id:
00242             # Could be one of two things:
00243             # - A Emergency User
00244             # - cleanId made a empty string out of member_id
00245             logger.debug(
00246                 'createMemberarea: empty member id '
00247                 '(%r, %r), skipping member area creation.' % (
00248                 member_id, safe_member_id))
00249             return
00250 
00251         _createObjectByType(self.memberarea_type, members, id=safe_member_id)
00252 
00253         # Get the user object from acl_users
00254         acl_users = self.__getPUS()
00255         user = acl_users.getUserById(member_id)
00256         if user is not None:
00257             user = user.__of__(acl_users)
00258         else:
00259             user = getSecurityManager().getUser()
00260             # check that we do not do something wrong
00261             if user.getId() != member_id:
00262                 raise NotImplementedError, \
00263                     'cannot get user for member area creation'
00264 
00265         member_object = self.getMemberById(member_id)
00266 
00267         ## Modify member folder
00268         member_folder = self.getHomeFolder(member_id)
00269         # Grant Ownership and Owner role to Member
00270         member_folder.changeOwnership(user)
00271         member_folder.__ac_local_roles__ = None
00272         member_folder.manage_setLocalRoles(member_id, ['Owner'])
00273         # We use ATCT now use the mutators
00274         fullname = member_object.getProperty('fullname')
00275         member_folder.setTitle(fullname or member_id)
00276         member_folder.reindexObject()
00277 
00278         if not minimal:
00279             ## add homepage text
00280             # get the text from portal_skins automagically
00281             homepageText = getattr(self, 'homePageText', None)
00282             if homepageText:
00283                 portal = getToolByName(self, "portal_url").getPortalObject()
00284                 # call the page template
00285                 content = homepageText(member=member_object, portal=portal).strip()
00286                 _createObjectByType('Document', member_folder, id='index_html')
00287                 hpt = getattr(member_folder, 'index_html')
00288                 # edit title, text and format
00289                 hpt.setTitle(fullname or member_id)
00290                 if hpt.meta_type == 'Document':
00291                     hpt.edit(text_format='structured-text', text=content)
00292                 else:
00293                     hpt.update(text=content)
00294                 hpt.setFormat('structured-text')
00295                 hpt.reindexObject()
00296                 # Grant Ownership and Owner role to Member
00297                 hpt.changeOwnership(user)
00298                 hpt.__ac_local_roles__ = None
00299                 hpt.manage_setLocalRoles(member_id, ['Owner'])
00300 
00301         ## Hook to allow doing other things after memberarea creation.
00302         notify_script = getattr(member_folder, 'notifyMemberAreaCreated', None)
00303         if notify_script is not None:
00304             notify_script()
00305 
     # deal with ridiculous API change in CMF

Here is the call graph for this function:

Here is the caller graph for this function:

deletes the Portait of a member.

Modified from CMFPlone version to URL-quote the member id.

Definition at line 343 of file membership.py.

00343 
00344     def deletePersonalPortrait(self, id=None):
00345         """deletes the Portait of a member.
00346 
00347         Modified from CMFPlone version to URL-quote the member id.
00348         """
00349         safe_id = self._getSafeMemberId(id)
00350         return BaseMembershipTool.deletePersonalPortrait(self, safe_id)
00351 

Here is the call graph for this function:

def PlonePAS.tools.membership.MembershipTool.getHomeFolder (   self,
  id = None,
  verifyPermission = 0 
)
Return a member's home folder object, or None.

Specially instrumented for URL-quoted-member-id folder
names.

Definition at line 324 of file membership.py.

00324 
00325     def getHomeFolder(self, id=None, verifyPermission=0):
00326         """ Return a member's home folder object, or None.
00327 
00328         Specially instrumented for URL-quoted-member-id folder
00329         names.
00330         """
00331         safe_id = self._getSafeMemberId(id)
00332         return BaseMembershipTool.getHomeFolder(self, safe_id, verifyPermission)
00333 

Here is the call graph for this function:

Here is the caller graph for this function:

def PlonePAS.tools.membership.MembershipTool.getPersonalPortrait (   self,
  id = None,
  verifyPermission = 0 
)
Return a members personal portait.

Modified from CMFPlone version to URL-quote the member id.

Definition at line 334 of file membership.py.

00334 
00335     def getPersonalPortrait(self, id=None, verifyPermission=0):
00336         """Return a members personal portait.
00337 
00338         Modified from CMFPlone version to URL-quote the member id.
00339         """
00340         safe_id = self._getSafeMemberId(id)
00341         return BaseMembershipTool.getPersonalPortrait(self, safe_id, verifyPermission)
00342 

Here is the call graph for this function:

def PlonePAS.tools.membership.MembershipTool.searchForMembers (   self,
  REQUEST = None,
  kw 
)
Hacked up version of Plone searchForMembers.

The following properties can be provided:
- name
- email
- last_login_time
- before_specified_time
- roles (any role will cause a match)
- groupname

This is an 'AND' request.

When it takes 'name' as keyword (or in REQUEST) it  searches on
Full name and id.

Simple name searches are "fast".

Definition at line 75 of file membership.py.

00075 
00076     def searchForMembers(self, REQUEST=None, **kw):
00077         """Hacked up version of Plone searchForMembers.
00078 
00079         The following properties can be provided:
00080         - name
00081         - email
00082         - last_login_time
00083         - before_specified_time
00084         - roles (any role will cause a match)
00085         - groupname
00086 
00087         This is an 'AND' request.
00088 
00089         When it takes 'name' as keyword (or in REQUEST) it  searches on
00090         Full name and id.
00091 
00092         Simple name searches are "fast".
00093         """
00094         logger.debug('searchForMembers: started.')
00095 
00096         acl_users = getToolByName(self, "acl_users")
00097         md = getToolByName(self, "portal_memberdata")
00098         groups_tool = getToolByName(self, "portal_groups")
00099 
00100         if REQUEST is not None:
00101             searchmap = REQUEST
00102         else:
00103             searchmap = kw
00104 
00105         # While the parameter is called name it is actually used to search a
00106         # users name, which is stored in the fullname property. We need to fix
00107         # that here so the right name is used when calling into PAS plugins.
00108         if 'name' in searchmap:
00109             searchmap['fullname'] = searchmap['name']
00110             del searchmap['name']
00111 
00112         user_search = dict([ x for x in searchmap.items() 
00113                                 if x[0] in self.user_search_keywords and x[1]])
00114 
00115         fullname = searchmap.get('fullname', None)
00116         email = searchmap.get('email', None)
00117         roles = searchmap.get('roles', None)
00118         last_login_time = searchmap.get('last_login_time', None)
00119         before_specified_time = searchmap.get('before_specified_time', None)
00120         groupname = searchmap.get('groupname', '').strip()
00121         is_manager = self.checkPermission('Manage portal', self)
00122 
00123         if fullname:
00124             fullname = fullname.strip().lower()
00125         if not fullname:
00126             fullname = None
00127         if email:
00128             email = email.strip().lower()
00129         if not email:
00130             email = None
00131 
00132         uf_users = []
00133 
00134         logger.debug(
00135             'searchForMembers: searching PAS '
00136             'with arguments %r.' % user_search)
00137         for user in acl_users.searchUsers(**user_search):
00138             uid = user['userid']
00139             uf_users.append(uid)
00140 
00141         if not uf_users:
00142             return []
00143 
00144         wrap = self.wrapUser
00145         getUserById = acl_users.getUserById
00146 
00147         members = [ getUserById(userid) for userid in set(uf_users)]
00148         members = [ member for member in members if member is not None ]
00149 
00150         if (not email and
00151             not fullname and
00152             not roles and
00153             not groupname and
00154             not last_login_time):
00155             logger.debug(
00156                 'searchForMembers: searching users '
00157                 'with no extra filter, immediate return.')
00158             return members
00159 
00160 
00161         # Now perform individual checks on each user
00162         res = []
00163         portal = getToolByName(self, 'portal_url').getPortalObject()
00164 
00165         for member in members:
00166             if groupname and groupname not in member.getGroupIds():
00167                 continue
00168 
00169             if not (member.getProperty('listed', False) or is_manager):
00170                 continue
00171 
00172             if roles:
00173                 user_roles = member.getRoles()
00174                 found = 0
00175                 for r in roles:
00176                     if r in user_roles:
00177                         found = 1
00178                         break
00179                 if not found:
00180                     continue
00181 
00182             if last_login_time:
00183                 last_login = member.getProperty('last_login_time', '')
00184 
00185                 if isinstance(last_login, basestring):
00186                     # value is a string when member hasn't yet logged in
00187                    last_login = DateTime(last_login or '2000/01/01')
00188                    
00189                 if before_specified_time:
00190                     if last_login >= last_login_time:
00191                         continue
00192                 elif last_login < last_login_time:
00193                     continue
00194 
00195             res.append(member)
00196 
00197         logger.debug('searchForMembers: finished.')
00198         return res

Here is the call graph for this function:


Member Data Documentation

Initial value:
(getattr(BaseMembershipTool, '_properties', ()) +
                   ({'id': 'user_search_keywords',
                     'type': 'lines',
                     'mode': 'rw',
                     },))

Definition at line 50 of file membership.py.

Definition at line 307 of file membership.py.

string PlonePAS.tools.membership.MembershipTool.meta_type = "PlonePAS Membership Tool" [static]

Definition at line 43 of file membership.py.

tuple PlonePAS.tools.membership.MembershipTool.security = ClassSecurityInfo() [static]

Definition at line 45 of file membership.py.

Definition at line 44 of file membership.py.

Initial value:
('login', 'fullname', 'email', 'exact_match',
                            'sort_by', 'max_results')

Definition at line 47 of file membership.py.


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