app/soc/logic/accounts.py
changeset 724 b26295df0d9a
parent 592 be98a2f5d8a2
child 749 134d9954f4dc
equal deleted inserted replaced
723:69e5130e4a0a 724:b26295df0d9a
    29 
    29 
    30 import soc.models.user
    30 import soc.models.user
    31 import soc.logic.models.user
    31 import soc.logic.models.user
    32 
    32 
    33 
    33 
    34 def isDeveloper(account=None):
    34 def isDeveloper(account=None, user=None):
    35   """Returns True if a Google Account is a Developer with special privileges.
    35   """Returns True if a Google Account is a Developer with special privileges.
    36   
    36   
    37   Since it only works on the current logged-in user, if account matches the
    37   Since it only works on the current logged-in user, if account matches the
    38   current logged-in Google Account, the App Engine Users API function
    38   current logged-in Google Account, the App Engine Users API function
    39   user.is_current_user_admin() is checked.  If that returns False, or
    39   user.is_current_user_admin() is checked.  If that returns False, or
    45   
    45   
    46   Args:
    46   Args:
    47     account: a Google Account (users.User) object; if not supplied,
    47     account: a Google Account (users.User) object; if not supplied,
    48       the current logged-in user is checked
    48       the current logged-in user is checked
    49   """
    49   """
       
    50 
       
    51   if user and (not account):
       
    52     account = user.account
    50 
    53 
    51   # Get the currently logged in user
    54   # Get the currently logged in user
    52   current = users.get_current_user()
    55   current = users.get_current_user()
    53 
    56 
    54   if not (account or current):
    57   if not (account or current):
    63     return True
    66     return True
    64 
    67 
    65   if not account:
    68   if not account:
    66     account = current
    69     account = current
    67 
    70 
    68   user = models.user.logic.getForFields({'account': account}, unique=True)
    71   if not user:
       
    72     user = models.user.logic.getForFields({'account': account}, unique=True)
    69 
    73 
    70   if not user:
    74   if not user:
    71     # no User entity for this Google Account, and account is not the
    75     # no User entity for this Google Account, and account is not the
    72     # currently logged-in user, so there is no conclusive way to check the
    76     # currently logged-in user, so there is no conclusive way to check the
    73     # Administration->Developers list in the App Engine console
    77     # Administration->Developers list in the App Engine console