Changeset 912b9a in indico


Ignore:
Timestamp:
06/07/10 18:31:06 (3 years ago)
Author:
Pedro Ferreira <jose.pedro.ferreira@…>
Branches:
master, burotel, hello-world-walkthrough, ipv6, new-webex, v0.97-series, v0.98-series, v0.98.2, v0.98.3, v0.98b1, v0.98b2, v0.99, 051b2622c51afb171a1dedb46a0df4fbb0cbd02e, d9941f8582b36b24821a11ea5ba16fda6a457fb1
Children:
971b24
Parents:
390c35
git-author:
Pedro Ferreira <jose.pedro.ferreira@…> (06/01/10 11:37:25)
git-committer:
Pedro Ferreira <jose.pedro.ferreira@…> (06/07/10 18:31:06)
Message:

[FIX] Vidyo: Auth manager - simplified code

  • Clearer and simpler;
Location:
indico/MaKaC
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • indico/MaKaC/authentication/AuthenticationMgr.py

    rbd5b82 r912b9a  
    7878        return None 
    7979 
    80     def getAvatarByLogin(self, login, authenticator = None): 
     80    def getAvatarByLogin(self, login, auth = None): 
    8181        """ Returns an Avatar object based on the person's login. 
    82             If authenticator is set, we will only look in the given authenticator. 
    83             If not set, we will look in all autheticators. 
     82            If authList is set, we will only look in the given authenticators. 
     83            If not set, we will look in all authenticators. 
    8484            If we find this login in more than one authenticator, and there is at least 2 
    8585            different Avatar objects, we will return a dictionary authenticatorName:Avatar object. 
     
    8989            :type login: str 
    9090 
    91             :param login: the name of an authenticator to use, or a list of authenticator names, or None 
    92             :type login: str, list or NoneType 
     91            :param auth: a list of names of the authenticators to use, or None 
     92            :type auth: str, list or NoneType 
    9393        """ 
    9494 
    95         if type(authenticator) is str: 
    96             #only one authenticator 
    97             auth = self.getById(authenticator) 
     95        if auth == None: 
     96            # search all authenticators 
     97            authList = self.AuthenticatorList 
     98        else: 
     99            # get the actual Authenticator objects 
     100            authList = list(self.getById(a) for a in auth) 
     101 
     102        # we search for Avatars in each authenticator 
     103        foundAvatars = {} 
     104        for auth in authList: 
    98105            try: 
    99                 return auth.getAvatarByLogin(login) 
     106                avatar = auth.getAvatarByLogin(login) 
     107                foundAvatars[auth.getId().strip()] = avatar 
    100108            except KeyError: 
    101                 return None 
     109                pass 
    102110 
    103         else: 
    104             #multiple authenticators, we build a list of authenticators 
    105             if type(authenticator) is list: 
    106                 authenticatorList = [] 
    107                 for authName in authenticator: 
    108                     authenticatorList.append(self.getById(authName)) 
    109             else: 
    110                 authenticatorList = self.AuthenticatorList 
    111  
    112             #we search for Avatars in each authenticator 
    113             foundAvatars = {} 
    114             avatarIdsFound = set() 
    115             for auth in authenticatorList: 
    116                 try: 
    117                     avatar = auth.getAvatarByLogin(login) 
    118                     foundAvatars[auth.getId().strip()] = avatar 
    119                     avatarIdsFound.add(avatar.getId()) 
    120                 except KeyError: 
    121                     pass 
    122  
    123             if foundAvatars: 
    124                 if len(foundAvatars) == 1 or len(avatarIdsFound) == 1: 
    125                     #there's only one different avatar 
    126                     return foundAvatars.values()[0] 
    127                 else: 
    128                     #there's more than 1 avatar, we return a dictionary 
    129                     return foundAvatars 
    130             else: 
    131                 #we found nothing, we return None 
    132                 return None 
    133  
     111        return foundAvatars 
    134112 
    135113    def isLoginFree( self, login): 
  • indico/MaKaC/plugins/Collaboration/Vidyo/common.py

    rc18126 r912b9a  
    146146    @classmethod 
    147147    def getAvatarByAccountName(cls, accountName): 
    148         authenticatorsToUse = getVidyoOptionValue("authenticatorList") 
    149  
    150         foundAvatar = AuthenticatorMgr().getAvatarByLogin(accountName, authenticatorsToUse) 
    151         if foundAvatar: 
    152             if type(foundAvatar) is dict: 
    153                 for authenticatorName in authenticatorsToUse: 
    154                     if authenticatorName in foundAvatar: 
    155                         foundAvatar = foundAvatar[authenticatorName] 
    156                         break 
    157             return foundAvatar 
     148        """ 
     149        Retrieves the first avatar found using the authenticators in the 
     150        authenticatorList option (order is respected) 
     151        """ 
     152        availableAuths = getVidyoOptionValue("authenticatorList") 
     153        foundAvatarDict = AuthenticatorMgr().getAvatarByLogin(accountName, availableAuths) 
     154 
     155        for authName in availableAuths: 
     156            foundAvatar = foundAvatarDict.get(authName, None) 
     157            if foundAvatar: 
     158                return foundAvatar 
    158159        else: 
    159160            return None 
Note: See TracChangeset for help on using the changeset viewer.