From 6e6825a1d8f4f5448c0ee7dd98cf7c2a1a4bc392 Mon Sep 17 00:00:00 2001 From: Moritz Schlarb Date: Wed, 15 Dec 2021 12:13:48 +0100 Subject: [PATCH] Fix collaboration notice sending (Closes: #5062) By setting `to_user = contact_email`, the timestamp `collaborate_last_emailed_time` gets set for the contact email instead of the username, but that is getting used initially for querying the last emailed timestamps. This leads to notification emails getting sent every time the email sending job runs. This change makes it more in sync with send_file_updates.py, too. --- .../management/commands/send_notices.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/seahub/notifications/management/commands/send_notices.py b/seahub/notifications/management/commands/send_notices.py index 5996030f93..6ad0e57a1d 100644 --- a/seahub/notifications/management/commands/send_notices.py +++ b/seahub/notifications/management/commands/send_notices.py @@ -323,9 +323,8 @@ class Command(BaseCommand): continue user_name = email2nickname(to_user) contact_email = Profile.objects.get_contact_email_by_user(to_user) - to_user = contact_email # use contact email if any c = { - 'to_user': to_user, + 'to_user': contact_email, 'notice_count': len(notices), 'notices': notices, 'user_name': user_name, @@ -334,15 +333,15 @@ class Command(BaseCommand): try: send_html_email(_('New notice on %s') % get_site_name(), 'notifications/notice_email.html', c, - None, [to_user]) + None, [contact_email]) # set new last_emailed_time UserOptions.objects.set_collaborate_last_emailed_time( to_user, now) - logger.info('Successfully sent email to %s' % to_user) - self.stdout.write('[%s] Successfully sent email to %s' % (str(datetime.datetime.now()), to_user)) + logger.info('Successfully sent email to %s' % contact_email) + self.stdout.write('[%s] Successfully sent email to %s' % (str(datetime.datetime.now()), contact_email)) except Exception as e: - logger.error('Failed to send email to %s, error detail: %s' % (to_user, e)) - self.stderr.write('[%s] Failed to send email to %s, error detail: %s' % (str(datetime.datetime.now()), to_user, e)) + logger.error('Failed to send email to %s, error detail: %s' % (contact_email, e)) + self.stderr.write('[%s] Failed to send email to %s, error detail: %s' % (str(datetime.datetime.now()), contact_email, e)) # restore current language translation.activate(cur_language)