When applying an automatic forwarding rule, select the new sender among the original recipients who matched the rule
This commit is contained in:
parent
fcdb9660b7
commit
55e17ac3fc
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue