def getProperty(self, id, default=_marker): """PAS-specific method to fetch a user's properties. Looks through the ordered property sheets. """ sheets = None if not IPluggableAuthService.providedBy(self.acl_users): return BaseMemberData.getProperty(self, id) else: # It's a PAS! Whee! user = self.getUser() sheets = getattr(user, 'getOrderedPropertySheets', lambda: None)() # we won't always have PlonePAS users, due to acquisition, # nor are guaranteed property sheets if not sheets: return BaseMemberData.getProperty(self, id, default) # If we made this far, we found a PAS and some property sheets. for sheet in sheets: if sheet.hasProperty(id): # Return the first one that has the property. value = sheet.getProperty(id) if isinstance(value, unicode): # XXX Temporarily work around the fact that # property sheets blindly store and return # unicode. This is sub-optimal and should be # dealed with at the property sheets level by # using Zope's converters. return value.encode('utf-8') return value # Couldn't find the property in the property sheets. Try to # delegate back to the base implementation. return BaseMemberData.getProperty(self, id, default)
def setMemberProperties(self, mapping): """ Sets the properties of the member. """ acl = self.acl_users ldap_schemakeys = [x[0] for x in acl.getLDAPSchema()] if isinstance(mapping, HTTPRequest): mapping = mapping.form # back conversion of mapped attributes mapped_attrs = acl.getMappedUserAttrs() for mapped_attr in mapped_attrs: if ( not mapping.has_key(mapped_attr[0]) and mapping.has_key(mapped_attr[1]) ): mapping[mapped_attr[0]] = mapping[mapped_attr[1]] # Special-case a couple keys which are pretty much "hard-coded" # in CMF if mapping.has_key('email') and not mapping.has_key('mail'): mapping['mail'] = mapping['email'] change_vals = filter( None , map( lambda x, lsk=ldap_schemakeys: x in lsk , mapping.keys() ) ) try: if change_vals: user_obj = self.getUser() rdn_attr = acl.getProperty('_rdnattr') if not mapping.has_key(rdn_attr): mapping[rdn_attr] = user_obj.getUserName() acl.manage_editUser( user_obj.getUserDN() , kwargs=mapping ) except: pass # Before we hand this over to the default MemberData implementation, # purge out all keys we have already set via LDAP so that we never # shadow a LDAP value on the member data wrapper # We want to hand over the "default" stuff like listed status or # the skin selection. consumed_attributes = [x[0] for x in mapped_attrs] consumed_attributes.extend(ldap_schemakeys) for key in consumed_attributes: if mapping.has_key(key): del mapping[key] MemberData.setMemberProperties(self, mapping)
def setMemberProperties(self, mapping, force_local=0): """ PAS-specific method to set the properties of a member. Ignores 'force_local', which is not reliably present. """ sheets = None # We could pay attention to force_local here... if not IPluggableAuthService.providedBy(self.acl_users): # Defer to base impl in absence of PAS, a PAS user, or # property sheets return BaseMemberData.setMemberProperties(self, mapping) else: # It's a PAS! Whee! user = self.getUser() sheets = getattr(user, 'getOrderedPropertySheets', lambda: None)() # We won't always have PlonePAS users, due to acquisition, # nor are guaranteed property sheets if not sheets: # Defer to base impl if we have a PAS but no property # sheets. return BaseMemberData.setMemberProperties(self, mapping) # If we got this far, we have a PAS and some property sheets. # XXX track values set to defer to default impl # property routing? modified = False for k, v in mapping.items(): if v is None: continue for sheet in sheets: if not sheet.hasProperty(k): continue if IMutablePropertySheet.providedBy(sheet): sheet.setProperty(user, k, v) modified = True else: break # raise RuntimeError, ("Mutable property provider " # "shadowed by read only provider") if modified: self.notifyModified() # Genweb: Updated by patch notify(PropertiesUpdated(user, mapping))
def setMemberProperties(self, mapping, force_local=0): """PAS-specific method to set the properties of a member. Ignores 'force_local', which is not reliably present. """ sheets = None # We could pay attention to force_local here... if not IPluggableAuthService.providedBy(self.acl_users): # Defer to base impl in absence of PAS, a PAS user, or # property sheets return BaseMemberData.setMemberProperties(self, mapping) else: # It's a PAS! Whee! user = self.getUser() sheets = getattr(user, 'getOrderedPropertySheets', lambda: None)() # We won't always have PlonePAS users, due to acquisition, # nor are guaranteed property sheets if not sheets: # Defer to base impl if we have a PAS but no property # sheets. return BaseMemberData.setMemberProperties(self, mapping) # If we got this far, we have a PAS and some property sheets. # XXX track values set to defer to default impl # property routing? modified = False for k, v in mapping.items(): if v == None: continue for sheet in sheets: if not sheet.hasProperty(k): continue if IMutablePropertySheet.providedBy(sheet): sheet.setProperty(user, k, v) modified = True else: break # raise RuntimeError, ("Mutable property provider " # "shadowed by read only provider") if modified: self.notifyModified() # Genweb: Updated by patch notify(PropertiesUpdated(user, mapping))
def setMemberProperties(self, mapping, force_local=0, force_empty=False): """PAS-specific method to set the properties of a member. Ignores 'force_local', which is not reliably present. """ sheets = None # We could pay attention to force_local here... if not IPluggableAuthService.providedBy(self.acl_users): # Defer to base impl in absence of PAS, a PAS user, or # property sheets return BaseMemberData.setMemberProperties(self, mapping) else: # It's a PAS! Whee! user = self.getUser() sheets = getattr(user, 'getOrderedPropertySheets', lambda: None)() # We won't always have PlonePAS users, due to acquisition, # nor are guaranteed property sheets if not sheets: # Defer to base impl if we have a PAS but no property # sheets. return BaseMemberData.setMemberProperties(self, mapping) # If we got this far, we have a PAS and some property sheets. # XXX track values set to defer to default impl # property routing? modified = False for k, v in mapping.items(): if v is None and not force_empty: continue for sheet in sheets: if not sheet.hasProperty(k): continue if IMutablePropertySheet.providedBy(sheet): sheet.setProperty(user, k, v) modified = True else: break if modified: self.notifyModified() # Trigger PropertiesUpdated event when member properties are updated, # excluding user login events if not set(mapping.keys()) & set(('login_time', 'last_login_time')): notify(PropertiesUpdated(self, mapping))
def test_setSecurityProfile(self): mdtool = DummyMemberDataTool() aclu = DummyUserFolder() user = DummyUser('bob', 'pw', ['Role'], ['domain']) aclu._addUser(user) user = user.__of__(aclu) member = MemberData(None, 'bob').__of__(mdtool).__of__(user) member.setSecurityProfile(password='******') self.assertEqual(user.__, 'newpw') self.assertEqual(list(user.roles), ['Role']) self.assertEqual(list(user.domains), ['domain']) member.setSecurityProfile(roles=['NewRole']) self.assertEqual(user.__, 'newpw') self.assertEqual(list(user.roles), ['NewRole']) self.assertEqual(list(user.domains), ['domain']) member.setSecurityProfile(domains=['newdomain']) self.assertEqual(user.__, 'newpw') self.assertEqual(list(user.roles), ['NewRole']) self.assertEqual(list(user.domains), ['newdomain'])
def _makeOne(self, *args, **kw): from Products.CMFCore.MemberDataTool import MemberData return MemberData(*args, **kw)