@@ -424,10 +424,15 @@ def create(self, validated_data):
424424 dref_assessment_report = super ().create (validated_data )
425425 dref_assessment_report .needs_identified .clear ()
426426 return dref_assessment_report
427+ if 'users' in validated_data :
428+ to = {u .email for u in validated_data ['users' ]}
429+ else :
430+ to = None
427431 dref = super ().create (validated_data )
428- transaction .on_commit (
429- lambda : send_dref_email .delay (dref .id , 'New' )
430- )
432+ if to :
433+ transaction .on_commit (
434+ lambda : send_dref_email .delay (dref .id , list (to ), 'New' )
435+ )
431436 return dref
432437
433438 def update (self , instance , validated_data ):
@@ -458,10 +463,17 @@ def update(self, instance, validated_data):
458463 dref_assessment_report = super ().update (instance , validated_data )
459464 dref_assessment_report .needs_identified .clear ()
460465 return dref_assessment_report
466+ # we don't send notification again to the already notified users:
467+ if 'users' in validated_data :
468+ to = {u .email for u in validated_data ['users' ]
469+ if u .email not in {t .email for t in instance .users .iterator ()}}
470+ else :
471+ to = None
461472 dref = super ().update (instance , validated_data )
462- transaction .on_commit (
463- lambda : send_dref_email .delay (dref .id , 'Updated' )
464- )
473+ if to :
474+ transaction .on_commit (
475+ lambda : send_dref_email .delay (dref .id , list (to ), 'Updated' )
476+ )
465477 return dref
466478
467479
0 commit comments