Back to index

plone3  3.1.7
Functions | Variables
GroupUserFolder.PloneFeaturePreview Namespace Reference

Functions

def searchForMembers
def listAllowedMembers
def _getPortrait
def setLocalRoles
def deleteLocalRoles

Variables

string __version__ = "$Revision: $"
 GroupUserFolder Copyright (C)2006 Ingeniweb.
string __docformat__ = 'restructuredtext'

Function Documentation

def GroupUserFolder.PloneFeaturePreview._getPortrait (   self,
  member_id 
) [private]
return member_id's portrait if you can.
If it's not possible, just try to fetch a 'portait' property from the underlying user source,
then create a portrait from it.

Definition at line 185 of file PloneFeaturePreview.py.

00185 
00186 def _getPortrait(self, member_id):
00187     """
00188     return member_id's portrait if you can.
00189     If it's not possible, just try to fetch a 'portait' property from the underlying user source,
00190     then create a portrait from it.
00191     """
00192     # fetch the 'portrait' property
00193     Log(LOG_DEBUG, "trying to fetch the portrait for the given member id")
00194     portrait = self._former_getPortrait(member_id)
00195     if portrait:
00196         Log(LOG_DEBUG, "Returning the old-style portrait:", portrait, "for", member_id)
00197         return portrait
00198 
00199     # Try to find a portrait in the user source
00200     member = self.portal_membership.getMemberById(member_id)
00201     portrait = member.getUser().getProperty('portrait', None)
00202     if not portrait:
00203         Log(LOG_DEBUG, "No portrait available in the user source for", member_id)
00204         return None
00205 
00206     # Convert the user-source portrait into a plone-complyant one
00207     Log(LOG_DEBUG, "Converting the portrait", type(portrait))
00208     portrait = Image(id=member_id, file=portrait, title='')
00209     membertool = self.portal_memberdata
00210     membertool._setPortrait(portrait, member_id)
00211 
00212     # Re-call ourself to retreive the real portrait
00213     Log(LOG_DEBUG, "Returning the real portrait")
00214     return self._former_getPortrait(member_id)
00215 

Here is the call graph for this function:

def GroupUserFolder.PloneFeaturePreview.deleteLocalRoles (   self,
  obj,
  member_ids,
  reindex = 1 
)
Delete local roles for members member_ids 

Definition at line 240 of file PloneFeaturePreview.py.

00240 
00241 def deleteLocalRoles( self, obj, member_ids, reindex=1 ):
00242     """ Delete local roles for members member_ids """
00243     member = self.getAuthenticatedMember()
00244     my_roles = member.getRolesInContext( obj )
00245     gruf = self.acl_users
00246     member_ids = [
00247         u.getUserId() for u in [
00248             gruf.getUserById(u) or gruf.getGroupByName(u) for u in member_ids
00249             ] if u
00250         ]
00251 
00252     if 'Manager' in my_roles or 'Owner' in my_roles:
00253         obj.manage_delLocalRoles( userids=member_ids )
00254 
00255     if reindex:
00256         obj.reindexObjectSecurity()
00257 
# Monkeypatch it !

Here is the call graph for this function:

listAllowedMembers => list only members which belong
to the same groups/roles as the calling user.

Definition at line 169 of file PloneFeaturePreview.py.

00169 
00170 def listAllowedMembers(self,):
00171     """listAllowedMembers => list only members which belong
00172     to the same groups/roles as the calling user.
00173     """
00174     user = self.REQUEST['AUTHENTICATED_USER']
00175     caller_roles = user.getRoles()              # Have to provide a hook for admins
00176     current_members = self.listMembers()
00177     allowed_members =[]
00178     for member in current_members:
00179         for role in caller_roles:
00180             if role in member.getRoles():
00181                 allowed_members.append(member)
00182                 break
00183     return allowed_members
00184 

def GroupUserFolder.PloneFeaturePreview.searchForMembers (   self,
  REQUEST = None,
  kw 
)
searchForMembers(self, REQUEST=None, **kw) => normal or fast search method.

The following properties can be provided:
- name
- email
- last_login_time
- roles

This is an 'AND' request.

If name is provided, then a _fast_ search is performed with GRUF's
searchUsersByName() method. This will improve performance.

In any other case, a regular (possibly _slow_) search is performed.
As it uses the listMembers() method, which is itself based on gruf.getUsers(),
this can return partial results. This may change in the future.

Definition at line 54 of file PloneFeaturePreview.py.

00054 
00055 def searchForMembers( self, REQUEST=None, **kw ):
00056     """
00057     searchForMembers(self, REQUEST=None, **kw) => normal or fast search method.
00058 
00059     The following properties can be provided:
00060     - name
00061     - email
00062     - last_login_time
00063     - roles
00064 
00065     This is an 'AND' request.
00066 
00067     If name is provided, then a _fast_ search is performed with GRUF's
00068     searchUsersByName() method. This will improve performance.
00069 
00070     In any other case, a regular (possibly _slow_) search is performed.
00071     As it uses the listMembers() method, which is itself based on gruf.getUsers(),
00072     this can return partial results. This may change in the future.
00073     """
00074     md = self.portal_memberdata
00075     mt = self.portal_membership
00076     if REQUEST:
00077         dict = REQUEST
00078     else:
00079         dict = kw
00080 
00081     # Attributes retreiving & mangling
00082     name = dict.get('name', None)
00083     email = dict.get('email', None)
00084     roles = dict.get('roles', None)
00085     last_login_time = dict.get('last_login_time', None)
00086     is_manager = mt.checkPermission('Manage portal', self)
00087     if name:
00088         name = name.strip().lower()
00089     if email:
00090         email = email.strip().lower()
00091 
00092 
00093     # We want 'name' request to be handled properly with large user folders.
00094     # So we have to check both the fullname and loginname, without scanning all
00095     # possible users.
00096     md_users = None
00097     uf_users = None
00098     if name:
00099         # We first find in MemberDataTool users whose _full_ name match what we want.
00100         lst = md.searchMemberDataContents('fullname', name)
00101         md_users = [ x['username'] for x in lst ]
00102 
00103         # Fast search management if the underlying acl_users support it.
00104         # This will allow us to retreive users by their _id_ (not name).
00105         acl_users = self.acl_users
00106         meth = getattr(acl_users, "searchUsersByName", None)
00107         if meth:
00108             uf_users = meth(name)           # gruf search
00109 
00110     # Now we have to merge both lists to get a nice users set.
00111     # This is possible only if both lists are filled (or we may miss users else).
00112     Log(LOG_DEBUG, md_users, uf_users, )
00113     members = []
00114     if md_users is not None and uf_users is not None:
00115         names_checked = 1
00116         wrap = mt.wrapUser
00117         getUser = acl_users.getUser
00118         for userid in md_users:
00119             members.append(wrap(getUser(userid)))
00120         for userid in uf_users:
00121             if userid in md_users:
00122                 continue             # Kill dupes
00123             usr = getUser(userid)
00124             if usr is not None:
00125                 members.append(wrap(usr))
00126 
00127         # Optimization trick
00128         if not email and \
00129                not roles and \
00130                not last_login_time:
00131             return members          
00132     else:
00133         # If the lists are not available, we just stupidly get the members list
00134         members = self.listMembers()
00135         names_checked = 0
00136 
00137     # Now perform individual checks on each user
00138     res = []
00139     portal = self.portal_url.getPortalObject()
00140 
00141     for member in members:
00142         #user = md.wrapUser(u)
00143         u = member.getUser()
00144         if not (member.listed or is_manager):
00145             continue
00146         if name and not names_checked:
00147             if (u.getUserName().lower().find(name) == -1 and
00148                 member.getProperty('fullname').lower().find(name) == -1):
00149                 continue
00150         if email:
00151             if member.getProperty('email').lower().find(email) == -1:
00152                 continue
00153         if roles:
00154             user_roles = member.getRoles()
00155             found = 0
00156             for r in roles:
00157                 if r in user_roles:
00158                     found = 1
00159                     break
00160             if not found:
00161                 continue
00162         if last_login_time:
00163             if member.last_login_time < last_login_time:
00164                 continue
00165         res.append(member)
00166     Log(LOG_DEBUG, res)
00167     return res
00168 

Here is the call graph for this function:

def GroupUserFolder.PloneFeaturePreview.setLocalRoles (   self,
  obj,
  member_ids,
  member_role,
  reindex = 1 
)
Set local roles on an item 

Definition at line 216 of file PloneFeaturePreview.py.

00216 
00217 def setLocalRoles( self, obj, member_ids, member_role, reindex=1 ):
00218     """ Set local roles on an item """
00219     member = self.getAuthenticatedMember()
00220     gruf = self.acl_users
00221     my_roles = member.getRolesInContext( obj )
00222 
00223     if 'Manager' in my_roles or member_role in my_roles:
00224         for member_id in member_ids:
00225             u = gruf.getUserById(member_id) or gruf.getGroupByName(member_id)
00226             if not u:
00227                 continue
00228             member_id = u.getUserId()
00229             roles = list(obj.get_local_roles_for_userid( userid=member_id ))
00230 
00231             if member_role not in roles:
00232                 roles.append( member_role )
00233                 obj.manage_setLocalRoles( member_id, roles )
00234 
00235     if reindex:
00236         # It is assumed that all objects have the method
00237         # reindexObjectSecurity, which is in CMFCatalogAware and
00238         # thus PortalContent and PortalFolder.
00239         obj.reindexObjectSecurity()


Variable Documentation

Definition at line 37 of file PloneFeaturePreview.py.

GroupUserFolder Copyright (C)2006 Ingeniweb.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

Definition at line 34 of file PloneFeaturePreview.py.