Skip to content

Commit

Permalink
Fix is incident part of campaign bug (#27787)
Browse files Browse the repository at this point in the history
* fix

* update RN

* comment corrections

* pre-commit

* update RN

* add UT
  • Loading branch information
israelpoli authored Jun 28, 2023
1 parent 77f4906 commit 12f6a44
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
7 changes: 7 additions & 0 deletions Packs/Campaign/ReleaseNotes/3_3_2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

#### Scripts

##### IsIncidentPartOfCampaign
- Updated the Docker image to: *demisto/python3:3.10.12.63474*.

- Fixed an issue where the script failed when checking for a closed incident.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Iterable, Set
from collections.abc import Iterable

import demistomock as demisto # noqa: F401
from CommonServerPython import * # noqa: F401
Expand Down Expand Up @@ -39,7 +39,7 @@ def get_incidents_ids_by_type(incident_type: str) -> Iterable[str]:
''' COMMAND FUNCTION '''


def check_incidents_ids_in_campaign(campaign_id: str, incidents_ids_set: Set[str]) -> bool:
def check_incidents_ids_in_campaign(campaign_id: str, incidents_ids_set: set[str]) -> bool:
"""
Check for each incident in the campaigns_ids_list if any of the ids in incidents_ids_set is linked.
Args:
Expand All @@ -49,15 +49,16 @@ def check_incidents_ids_in_campaign(campaign_id: str, incidents_ids_set: Set[str
Returns:
True if at least one id from the incidents_ids_set is linked to the campaign incident, otherwise False.
"""
campaign_context = execute_command("getContext", {'id': campaign_id})['context']

connected_incidents_list = demisto.get(campaign_context, 'EmailCampaign.incidents')
if connected_incidents_list:
connected_campaign_incidents_ids = {incident.get('id') for incident in connected_incidents_list}
is_incidents_in_campaign = bool(incidents_ids_set & connected_campaign_incidents_ids)
if is_incidents_in_campaign:
return True
try:
campaign_context = execute_command("getContext", {'id': campaign_id})['context']

if (connected_incidents_list := demisto.get(campaign_context, 'EmailCampaign.incidents')):
connected_campaign_incidents_ids = {incident.get('id') for incident in connected_incidents_list}
is_incidents_in_campaign = bool(incidents_ids_set & connected_campaign_incidents_ids)
if is_incidents_in_campaign:
return True
except Exception as e:
demisto.info(f"skipping for incident {campaign_id}, reason: {e}")
return False


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ outputs:
scripttarget: 0
subtype: python3
runonce: false
dockerimage: demisto/python3:3.10.11.54132
dockerimage: demisto/python3:3.10.12.63474
fromversion: 5.5.0
tests:
- No tests (auto formatted)
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ def test_check_incidents_ids_in_campaign(mocker, incidents_ids_set, result):
assert result == check_incidents_ids_in_campaign('1', incidents_ids_set)


def test_check_incidents_ids_in_campaign_for_closed_incident(mocker):
mocker.patch.object(demisto, 'executeCommand',
side_effect=Exception("Item not found"))
assert not check_incidents_ids_in_campaign('1', {"11"})


def test_check_incidents_ids_in_campaign_no_incidents():
assert check_incidents_ids_in_campaign([], {'11', '12'}) is False

Expand Down
2 changes: 1 addition & 1 deletion Packs/Campaign/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Phishing Campaign",
"description": "This pack can help you find related phishing, spam or other types of email incidents and characterize campaigns.",
"support": "xsoar",
"currentVersion": "3.3.1",
"currentVersion": "3.3.2",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down

0 comments on commit 12f6a44

Please sign in to comment.