Example #1
0
def forCurrentUserId():
    """Retrieves the user entity for the currently logged in user id.

  If there is no user logged in, or they have no valid associated User
  entity, None is returned.
  """
    user_id = accounts.getCurrentUserId()

    if not user_id:
        return None

    user_ent = forUserId(user_id)

    current_account = accounts.getCurrentAccount()
    if user_ent and (str(user_ent.account) != str(current_account)):
        # The account of the user has changed, we use this account to send system
        # emails to.
        try:
            user_ent.account = current_account
            user_ent.put()
        except apiproxy_errors.CapabilityDisabledError:
            # readonly mode, that's fine
            pass

    return user_ent
Example #2
0
def forCurrentUserId():
  """Retrieves the user entity for the currently logged in user id.

  If there is no user logged in, or they have no valid associated User
  entity, None is returned.
  """
  user_id = accounts.getCurrentUserId()

  if not user_id:
    return None

  user_ent = forUserId(user_id)

  current_account = accounts.getCurrentAccount()
  if user_ent and (str(user_ent.account) != str(current_account)):
    # The account of the user has changed, we use this account to send system
    # emails to.
    try:
      user_ent.account = current_account
      user_ent.put()
    except apiproxy_errors.CapabilityDisabledError:
      # readonly mode, that's fine
      pass

  return user_ent
Example #3
0
  def testGetCurrentUserId(self):
    """Tests if correct user id is returned.
    """
    default_user_id = os.environ.get('USER_ID', None)
    try:
      os.environ['USER_ID'] = expected_user_id = '42'
      self.assertEqual(accounts.getCurrentUserId(), expected_user_id)
    finally:
      if default_user_id is None:
        del os.environ['USER_ID']
      else:
        os.environ['USER_ID'] = default_user_id

    try:
      os.environ['USER_ID'] = ''
      expected_user_id = None
      self.assertEqual(accounts.getCurrentUserId(), expected_user_id)
    finally:
      if default_user_id is None:
        del os.environ['USER_ID']
      else:
        os.environ['USER_ID'] = default_user_id
Example #4
0
  def getForCurrentUserId(self):
    """Retrieves the user entity for the currently logged in user id.

    If there is no user logged in, or they have no valid associated User
    entity, None is returned.
    """

    user_id = accounts.getCurrentUserId()

    if not user_id:
      return None

    return self.getForUserId(user_id)
Example #5
0
  def _getForCurrentUserId(self):
    """Retrieves the user entity for the currently logged in user id.

    If there is no user logged in, or they have no valid associated User
    entity, None is returned.
    """

    user_id = accounts.getCurrentUserId()

    if not user_id:
      return None

    user = self.getForUserId(user_id)

    current_account = accounts.getCurrentAccount()
    if user and (str(user.account) != str(current_account)):
      # The account of the user has changed, we use this account to send system
      # emails to.
      self.updateEntityProperties(user, {'account': current_account})

    return user