@@ -734,9 +734,23 @@ def update(self, instance, validated_data):
734734
735735 instance = super (TaggitSerializer , self ).update (instance , validated_data )
736736
737+ # Allow setting or clearing the mitigation date based upon the state of is_Mitigated.
738+ mitigation_change = False
739+ if instance .is_Mitigated and instance .mitigated is None :
740+ mitigation_change = True
741+ instance .mitigated = datetime .datetime .now ()
742+ instance .mitigated_by = self .context ['request' ].user
743+ if settings .USE_TZ :
744+ instance .mitigated = timezone .make_aware (instance .mitigated , timezone .get_default_timezone ())
745+ elif not instance .is_Mitigated and instance .mitigated is not None :
746+ mitigation_change = True
747+ instance .mitigated = None
748+ instance .mitigated_by = None
749+
737750 # If we need to push to JIRA, an extra save call is needed.
751+ # Also if we need to update the mitigation date of the finding.
738752 # TODO try to combine create and save, but for now I'm just fixing a bug and don't want to change to much
739- if push_to_jira :
753+ if push_to_jira or mitigation_change :
740754 instance .save (push_to_jira = push_to_jira )
741755
742756 # not sure why we are returning a tag_object, but don't want to change too much now as we're just fixing a bug
@@ -817,9 +831,16 @@ def create(self, validated_data):
817831 # TODO: JIRA can we remove this is_push_all_issues, already checked in apiv2 viewset?
818832 push_to_jira = push_to_jira or jira_helper .is_push_all_issues (new_finding )
819833
834+ # Allow setting the mitigation date based upon the state of is_Mitigated.
835+ if new_finding .is_Mitigated :
836+ new_finding .mitigated = datetime .datetime .now ()
837+ new_finding .mitigated_by = self .context ['request' ].user
838+ if settings .USE_TZ :
839+ new_finding .mitigated = timezone .make_aware (new_finding .mitigated , timezone .get_default_timezone ())
840+
820841 # If we need to push to JIRA, an extra save call is needed.
821842 # TODO try to combine create and save, but for now I'm just fixing a bug and don't want to change to much
822- if push_to_jira :
843+ if push_to_jira or new_finding . is_Mitigated :
823844 new_finding .save (push_to_jira = push_to_jira )
824845
825846 # not sure why we are returning a tag_object, but don't want to change too much now as we're just fixing a bug
0 commit comments