diff --git a/docbow_project/docbow/views.py b/docbow_project/docbow/views.py index 69e1703..cf82552 100644 --- a/docbow_project/docbow/views.py +++ b/docbow_project/docbow/views.py @@ -177,27 +177,23 @@ def try_automatic_fowarding(document, logger, base_url): rules = AutomaticForwarding.objects.filter(filetypes=document.filetype, originaly_to_user__in=list(document.to())) if rules: - try: - sender = User.objects.get( - username=settings.AUTOMATIC_FORWARDING_USER) - except User.DoesNotExist: - logger.error('settings.AUTOMATIC_FORWARDING_USER set to %s ' - 'which does not exist, unable to make an automatic forward') - else: - for rule in rules: - try: - notification_count = forward_document(document, sender, - rule.forward_to_user.all(), - rule.forward_to_list.all(), logger, base_url, - automatic=True) - except Exception: - logger.exception('Unhandled exception during ' - 'application of automatic forwarding') - else: - if not notification_count: - logger.error('automatic forwarding failed ' - 'because we were unable to send ' - 'some notifications') + for rule in rules: + # choose a new sender + matching_recipients = rule.originaly_to_user.distinct() & document.to() + first_matching_recipient = matching_recipients[0] + try: + notification_count = forward_document(document, first_matching_recipient, + rule.forward_to_user.all(), + rule.forward_to_list.all(), logger, base_url, + automatic=True) + except Exception: + logger.exception('Unhandled exception during ' + 'application of automatic forwarding') + else: + if not notification_count: + logger.error('automatic forwarding failed ' + 'because we were unable to send ' + 'some notifications') @login_required def send_file(request):