Changeset bd5b82 in indico


Ignore:
Timestamp:
06/07/10 18:31:02 (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, 0da0c1403bae8e51d8229f460181c71b9e6dda72
Children:
083c31
Parents:
0360f4
git-author:
David Martín Clavo <david.martin.clavo@…> (04/06/10 15:06:58)
git-committer:
Pedro Ferreira <jose.pedro.ferreira@…> (06/07/10 18:31:02)
Message:

[IMP] Avatar / Authenticator / Identity new funcs

  • new getIdentityByAuthenticatorName for Avatar class
  • comments on Avatar methods related to identities
  • new getAvatarByLogin methods for authenticators and AuthenticatorMgr?
Location:
indico/MaKaC
Files:
3 edited

Legend:

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

    rbdd862 rbd5b82  
    2727 
    2828class AuthenticatorMgr: 
    29      
     29 
    3030    def __init__(self): 
    31          
     31 
    3232        self.AuthenticatorList = [] 
    3333        config = Config.getInstance() 
     
    3939                self.AuthenticatorList.append( NiceAuthenticator() ) 
    4040        self.create = True 
    41      
    42      
     41 
     42 
    4343    def add( self, newId): 
    4444        auth = self.getById( newId.getAuthenticatorTag() ) 
     
    7777                            return user 
    7878        return None 
    79      
     79 
     80    def getAvatarByLogin(self, login, authenticator = None): 
     81        """ 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. 
     84            If we find this login in more than one authenticator, and there is at least 2 
     85            different Avatar objects, we will return a dictionary authenticatorName:Avatar object. 
     86            If nothing is found, we will return None 
     87 
     88            :param login: the user login 
     89            :type login: str 
     90 
     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 
     93        """ 
     94 
     95        if type(authenticator) is str: 
     96            #only one authenticator 
     97            auth = self.getById(authenticator) 
     98            try: 
     99                return auth.getAvatarByLogin(login) 
     100            except KeyError: 
     101                return None 
     102 
     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 
     134 
    80135    def isLoginFree( self, login): 
    81136        for au in self.AuthenticatorList: 
     
    86141                pass 
    87142        return True 
    88      
     143 
    89144    def _getDefaultAuthenticator( self ): 
    90         return self.AuthenticatorList[0]     
    91      
     145        return self.AuthenticatorList[0] 
     146 
    92147    def getList(self): 
    93148        return self.AuthenticatorList 
     
    98153            auth = self._getDefaultAuthenticator() 
    99154        return auth.createIdentity(li, avatar) 
    100      
     155 
    101156    def removeIdentity( self, Id): 
    102157        #check if there is almost another one identity 
     
    104159            auth = self.getById(Id.getAuthenticatorTag()) 
    105160            auth.remove(Id) 
    106      
     161 
    107162    def getIdentityById(self, id): 
    108163        for auth in self.AuthenticatorList: 
     
    124179                return av 
    125180        return None 
    126      
     181 
    127182    def autoLogout(self, rh): 
    128183        authId = rh._getSession().getVar("autoLogin") 
     
    132187            return auth.autoLogout(rh) 
    133188 
    134      
     189 
  • indico/MaKaC/authentication/baseAuthentication.py

    rbdd862 rbd5b82  
    3939 
    4040    def getAvatar( self, li ): 
    41          
     41        """ Returns an Avatar object, checking that the password is right. 
     42 
     43            :param li: a LoginInfo object with the person's login string and password 
     44            :type li: MaKaC.user.LoginInfo 
     45        """ 
     46 
    4247        identity = self.getById( li.getLogin() ) 
    4348        return identity.authenticate( li ) 
     
    4752        #    return None 
    4853        #return identity.authenticate( li ) 
    49      
     54 
     55    def getAvatarByLogin(self, login): 
     56        """ Returns an Avatar object, WITHOUT checking the password! 
     57            Will throw KeyError if not found. 
     58 
     59            :param login: the person's login string 
     60            :type login: str 
     61        """ 
     62        return self.getById(login).getUser() 
     63 
    5064    def getIdx(self): 
    5165        return self._getIdx() 
    52      
     66 
    5367    def getId(self): 
    5468        return self.id 
    5569    getId = classmethod( getId ) 
    56      
     70 
    5771    def getName(self): 
    5872        return self.name 
    59      
     73 
    6074    def getDescription(self): 
    6175        return self.description 
    62      
     76 
    6377    def getUserCreator(self): 
    6478        return self.UserCreator 
    65      
     79 
    6680    def autoLogin(self, rh): 
    6781        return None 
    68      
     82 
    6983    def autoLogout(self, rh): 
    7084        return None 
     
    7488 
    7589class PIdentity(Persistent): 
    76      
     90 
    7791    def __init__(self, login, user): 
    7892        self.setLogin( login ) 
     
    88102    def getUser(self): 
    89103        return self.user 
    90      
     104 
    91105    def setLogin(self, newLogin): 
    92106        self.login = newLogin.strip() 
  • indico/MaKaC/user.py

    r2adefc rbd5b82  
    11011101 
    11021102    def addIdentity(self, newId): 
     1103        """ Adds a new identity to this Avatar. 
     1104            :param newId: a new PIdentity or inheriting object 
     1105            :type newId: PIdentity 
     1106        """ 
    11031107        if newId != None and (newId not in self.identities): 
    11041108            self.identities.append( newId ) 
     
    11061110 
    11071111    def removeIdentity(self, Id): 
     1112        """ Removed an identity from this Avatar. 
     1113            :param newId: a PIdentity or inheriting object 
     1114            :type newId: PIdentity 
     1115        """ 
    11081116        if Id in self.identities: 
    11091117            self.identities.remove(Id) 
     
    11111119 
    11121120    def getIdentityList( self ): 
     1121        """ Returns a list of identities for this Avatar. 
     1122            Each identity will be a PIdentity or inheriting object 
     1123        """ 
    11131124        return self.identities 
    11141125 
     1126    def getIdentityByAuthenticatorName(self, authenticatorName): 
     1127        """ Return a list of PIdentity objects given an authenticator name 
     1128            :param authenticatorName: the name of an authenticator, e.g. 'Local', 'Nice', etc 
     1129            :type authenticatorName: str 
     1130        """ 
     1131        result = [] 
     1132        for identity in self.identities: 
     1133            if identity.getAuthenticatorTag() == authenticatorName: 
     1134                result.append(identity) 
     1135        return result 
     1136 
     1137 
    11151138    def getIdentityById(self, id, tag): 
     1139        """ Returns a PIdentity object given an authenticator name and the identity's login 
     1140            :param id: the login string for this identity 
     1141            :type id: str 
     1142            :param tag: the name of an authenticator, e.g. 'Local', 'Nice', etc 
     1143            :type tag: str 
     1144        """ 
     1145 
    11161146        for Id in self.identities: 
    11171147            if Id.getAuthenticatorTag() == tag and Id.getLogin() == id: 
Note: See TracChangeset for help on using the changeset viewer.