# HG changeset patch # User Lennard de Rijk # Date 1240152322 0 # Node ID 0326d394dce55b452303c38b55535f8be7ec2421 # Parent 5e5b7f5d9a898bd5040e9f0a307f7e7f553e7e28 getDefaultMailSender now properly handles users who are logged in but not registered. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed diff -r 5e5b7f5d9a89 -r 0326d394dce5 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())