changeset 4332:609e06b6c52f

mail: only bother admins when that really is the intention - not when there just not happens to be other recipients
author Mads Kiilerich <madski@unity3d.com>
date Tue, 10 Dec 2013 19:30:37 +0100
parents 2655b2d46055
children c597adba8459
files kallithea/lib/celerylib/tasks.py kallithea/model/notification.py
diffstat 2 files changed, 13 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/celerylib/tasks.py	Tue Dec 10 19:30:37 2013 +0100
+++ b/kallithea/lib/celerylib/tasks.py	Tue Dec 10 19:30:37 2013 +0100
@@ -261,8 +261,8 @@
     """
     Sends an email with defined parameters from the .ini files.
 
-    :param recipients: list of recipients, it this is empty the defined email
-        address from field 'email_to' is used instead
+    :param recipients: list of recipients, if this is None, the defined email
+        address from field 'email_to' and all admins is used instead
     :param subject: subject of the mail
     :param body: body of the mail
     :param html_body: html version of body
@@ -272,13 +272,18 @@
     assert isinstance(recipients, list), recipients
 
     email_config = config
-    subject = "%s %s" % (email_config.get('email_prefix', ''), subject)
-    if not recipients:
+    email_prefix = email_config.get('email_prefix', '')
+    if email_prefix:
+        subject = "%s %s" % (email_prefix, subject)
+    if recipients is None:
         # if recipients are not defined we send to email_config + all admins
         admins = [u.email for u in User.query()
                   .filter(User.admin == True).all()]
         recipients = [email_config.get('email_to')] + admins
         log.warning("recipients not specified for '%s' - sending to admins %s", subject, ' '.join(recipients))
+    elif not recipients:
+        log.error("No recipients specified")
+        return False
 
     mail_from = email_config.get('app_email_from', 'Kallithea')
     user = email_config.get('smtp_username')
--- a/kallithea/model/notification.py	Tue Dec 10 19:30:37 2013 +0100
+++ b/kallithea/model/notification.py	Tue Dec 10 19:30:37 2013 +0100
@@ -82,8 +82,8 @@
 
         created_by_obj = self._get_user(created_by)
 
+        recipients_objs = []
         if recipients:
-            recipients_objs = []
             for u in recipients:
                 obj = self._get_user(u)
                 if obj:
@@ -95,12 +95,14 @@
             log.debug('sending notifications %s to %s' % (
                 type_, recipients_objs)
             )
-        else:
+        elif recipients is None:
             # empty recipients means to all admins
             recipients_objs = User.query().filter(User.admin == True).all()
             log.debug('sending notifications %s to admins: %s' % (
                 type_, recipients_objs)
             )
+        #else: silently skip notification mails?
+
         # TODO: inform user who are notified
         notif = Notification.create(
             created_by=created_by_obj, subject=subject,