getDefaultMailSender now properly handles users who are logged in but not registered.
authorLennard de Rijk <ljvderijk@gmail.com>
Sun, 19 Apr 2009 14:45:22 +0000
changeset 2242 0326d394dce5
parent 2241 5e5b7f5d9a89
child 2243 c61f9dd5e325
getDefaultMailSender now properly handles users who are logged in but not registered. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
app/soc/logic/mail_dispatcher.py
--- a/app/soc/logic/mail_dispatcher.py	Sun Apr 19 14:35:31 2009 +0000
+++ b/app/soc/logic/mail_dispatcher.py	Sun Apr 19 14:45:22 2009 +0000
@@ -124,12 +124,12 @@
 
 def getDefaultMailSender():
   """Returns the sender that currently can be used to send emails.
-  
+
   Returns:
     - A tuple containing (sender_name, sender_address)
     Consisting of:
     - If available the site name and noreply address from the site singleton
-    - Or the public name and email address of the current logged in User
+    - Or the (public) name and email address of the current logged in User
     - None if there is no address to return
   """
 
@@ -148,12 +148,15 @@
   # use the email address of the current logged in user
   account = accounts.getCurrentAccount(normalize=False)
 
+  if not account:
+    logging.warning('Non-Authenticated user triggered getDefaultMailSender '
+                    'please set a no-reply address in Site settings')
+    return None
+
   # we need to retrieve account separately, as user_logic normalizes it
   # and the GAE admin API is case sensitive
   user_entity = user_logic.logic.getForAccount(account)
 
-  if not (account and user_entity):
-    logging.warning('Non-Authenticated user triggered getDefaultMailSender')
-    return None
+  name = user_entity.name if user_entity else account.nickname()
 
-  return (user_entity.name, account.email())
+  return (name, account.email())