##// END OF EJS Templates
mail: only bother admins when that really is the intention - not when there just not happens to be other recipients
Mads Kiilerich -
r4332:609e06b6 default
parent child Browse files
Show More
@@ -261,8 +261,8 b' def send_email(recipients, subject, body'
261 """
261 """
262 Sends an email with defined parameters from the .ini files.
262 Sends an email with defined parameters from the .ini files.
263
263
264 :param recipients: list of recipients, it this is empty the defined email
264 :param recipients: list of recipients, if this is None, the defined email
265 address from field 'email_to' is used instead
265 address from field 'email_to' and all admins is used instead
266 :param subject: subject of the mail
266 :param subject: subject of the mail
267 :param body: body of the mail
267 :param body: body of the mail
268 :param html_body: html version of body
268 :param html_body: html version of body
@@ -272,13 +272,18 b' def send_email(recipients, subject, body'
272 assert isinstance(recipients, list), recipients
272 assert isinstance(recipients, list), recipients
273
273
274 email_config = config
274 email_config = config
275 subject = "%s %s" % (email_config.get('email_prefix', ''), subject)
275 email_prefix = email_config.get('email_prefix', '')
276 if not recipients:
276 if email_prefix:
277 subject = "%s %s" % (email_prefix, subject)
278 if recipients is None:
277 # if recipients are not defined we send to email_config + all admins
279 # if recipients are not defined we send to email_config + all admins
278 admins = [u.email for u in User.query()
280 admins = [u.email for u in User.query()
279 .filter(User.admin == True).all()]
281 .filter(User.admin == True).all()]
280 recipients = [email_config.get('email_to')] + admins
282 recipients = [email_config.get('email_to')] + admins
281 log.warning("recipients not specified for '%s' - sending to admins %s", subject, ' '.join(recipients))
283 log.warning("recipients not specified for '%s' - sending to admins %s", subject, ' '.join(recipients))
284 elif not recipients:
285 log.error("No recipients specified")
286 return False
282
287
283 mail_from = email_config.get('app_email_from', 'Kallithea')
288 mail_from = email_config.get('app_email_from', 'Kallithea')
284 user = email_config.get('smtp_username')
289 user = email_config.get('smtp_username')
@@ -82,8 +82,8 b' class NotificationModel(BaseModel):'
82
82
83 created_by_obj = self._get_user(created_by)
83 created_by_obj = self._get_user(created_by)
84
84
85 recipients_objs = []
85 if recipients:
86 if recipients:
86 recipients_objs = []
87 for u in recipients:
87 for u in recipients:
88 obj = self._get_user(u)
88 obj = self._get_user(u)
89 if obj:
89 if obj:
@@ -95,12 +95,14 b' class NotificationModel(BaseModel):'
95 log.debug('sending notifications %s to %s' % (
95 log.debug('sending notifications %s to %s' % (
96 type_, recipients_objs)
96 type_, recipients_objs)
97 )
97 )
98 else:
98 elif recipients is None:
99 # empty recipients means to all admins
99 # empty recipients means to all admins
100 recipients_objs = User.query().filter(User.admin == True).all()
100 recipients_objs = User.query().filter(User.admin == True).all()
101 log.debug('sending notifications %s to admins: %s' % (
101 log.debug('sending notifications %s to admins: %s' % (
102 type_, recipients_objs)
102 type_, recipients_objs)
103 )
103 )
104 #else: silently skip notification mails?
105
104 # TODO: inform user who are notified
106 # TODO: inform user who are notified
105 notif = Notification.create(
107 notif = Notification.create(
106 created_by=created_by_obj, subject=subject,
108 created_by=created_by_obj, subject=subject,
General Comments 0
You need to be logged in to leave comments. Login now