src/pyams_ldap/plugin.py
changeset 23 acd4a4eef95d
parent 20 68b5251b9687
child 38 0cde6357775d
equal deleted inserted replaced
22:216ba0fca6c5 23:acd4a4eef95d
   101         user = self.context
   101         user = self.context
   102         plugin = user.plugin
   102         plugin = user.plugin
   103 
   103 
   104         mail = user.attributes.get(plugin.mail_attribute)
   104         mail = user.attributes.get(plugin.mail_attribute)
   105         if mail:
   105         if mail:
   106             return {(plugin.title_format.format(**user.attributes), mail[0])}
   106             return {(plugin.title_format.format(**user.attributes),
       
   107                      mail[0] if isinstance(mail, (list, tuple)) else mail)}
   107         else:
   108         else:
   108             return set()
   109             return set()
   109 
   110 
   110 
   111 
   111 @implementer(ILDAPGroupInfo)
   112 @implementer(ILDAPGroupInfo)
   141 
   142 
   142         elif plugin.group_mail_mode == 'internal':
   143         elif plugin.group_mail_mode == 'internal':
   143             # use group internal attribute
   144             # use group internal attribute
   144             mail = group.attributes.get(plugin.group_mail_attribute)
   145             mail = group.attributes.get(plugin.group_mail_attribute)
   145             if mail:
   146             if mail:
   146                 yield plugin.group_title_format(**group.attributes), mail[0]
   147                 yield plugin.group_title_format(**group.attributes), \
       
   148                       mail[0] if isinstance(mail, (list, tuple)) else mail
   147 
   149 
   148         else:
   150         else:
   149             # redirect: use internal attribute of another group
   151             # redirect: use internal attribute of another group
   150             source, target = plugin.group_replace_expression.split('|')
   152             source, target = plugin.group_replace_expression.split('|')
   151             target_dn = group.dn.replace(source, target)
   153             target_dn = group.dn.replace(source, target)
   156             if not result or len(result) > 1:
   158             if not result or len(result) > 1:
   157                 raise StopIteration
   159                 raise StopIteration
   158             target_dn, attrs = result[0]
   160             target_dn, attrs = result[0]
   159             mail = attrs.get(plugin.group_mail_attribute)
   161             mail = attrs.get(plugin.group_mail_attribute)
   160             if mail:
   162             if mail:
   161                 yield plugin.group_title_format(**attrs), mail[0]
   163                 yield plugin.group_title_format(**attrs), \
       
   164                       mail[0] if isinstance(mail, (list, tuple)) else mail
   162 
   165 
   163 
   166 
   164 @implementer(ILDAPPlugin)
   167 @implementer(ILDAPPlugin)
   165 class LDAPPlugin(Persistent, Contained):
   168 class LDAPPlugin(Persistent, Contained):
   166     """LDAP authentication plug-in"""
   169     """LDAP authentication plug-in"""