From ae8e6f70303d13b686dbe0e96b06375bdc7c592b Mon Sep 17 00:00:00 2001 From: Israel Lappe <79846863+ilappe@users.noreply.github.com> Date: Mon, 10 Jun 2024 23:16:39 +0300 Subject: [PATCH] MyToDoTasksWidget: fix broken link (#34768) * fix broken link * Bump pack from version CommonWidgets to 1.2.51. * Update Packs/CommonWidgets/ReleaseNotes/1_2_51.md Co-authored-by: Dean Arbel --------- Co-authored-by: Content Bot Co-authored-by: Dean Arbel --- Packs/CommonWidgets/ReleaseNotes/1_2_51.md | 7 +++++++ .../MyToDoTasksWidget/MyToDoTasksWidget.py | 11 ++++++++--- .../MyToDoTasksWidget/MyToDoTasksWidget.yml | 2 +- .../MyToDoTasksWidget_test.py | 18 +++++++++++++++++- Packs/CommonWidgets/pack_metadata.json | 2 +- 5 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 Packs/CommonWidgets/ReleaseNotes/1_2_51.md diff --git a/Packs/CommonWidgets/ReleaseNotes/1_2_51.md b/Packs/CommonWidgets/ReleaseNotes/1_2_51.md new file mode 100644 index 000000000000..619e37f18ef8 --- /dev/null +++ b/Packs/CommonWidgets/ReleaseNotes/1_2_51.md @@ -0,0 +1,7 @@ + +#### Scripts + +##### MyToDoTasksWidget + +- Fixed an issue where the incident link was broken in SaaS platforms. +- Updated the Docker image to: *demisto/python3:3.10.14.97100*. diff --git a/Packs/CommonWidgets/Scripts/MyToDoTasksWidget/MyToDoTasksWidget.py b/Packs/CommonWidgets/Scripts/MyToDoTasksWidget/MyToDoTasksWidget.py index 02a6f104a9d8..22a86f0e1d33 100644 --- a/Packs/CommonWidgets/Scripts/MyToDoTasksWidget/MyToDoTasksWidget.py +++ b/Packs/CommonWidgets/Scripts/MyToDoTasksWidget/MyToDoTasksWidget.py @@ -5,6 +5,13 @@ MAX_ENTRIES = 30 +def get_clickable_incident_id(incident_id): + incident_id_url = os.path.join("Custom/caseinfoid", incident_id) + if not is_xsiam_or_xsoar_saas(): + incident_id_url = f'#/{incident_id_url}' + return f'[{incident_id}]({incident_id_url})' + + def get_open_to_do_tasks_of_current_user() -> List[Dict]: body = { "dataType": "todos", @@ -28,8 +35,6 @@ def get_open_to_do_tasks_of_current_user() -> List[Dict]: title = task.get('title', '') description = task.get('description', '') task_id = task.get('id', '') - incident_id = task.get('incidentId', '') - clickable_incident_id = f'[{incident_id}]({os.path.join("#/Custom/caseinfoid", incident_id)})' if sla := task.get('dueDate', ''): sla_dt = parse(sla) assert sla_dt is not None, f'could not parse {sla}' @@ -41,7 +46,7 @@ def get_open_to_do_tasks_of_current_user() -> List[Dict]: 'Task ID': task_id, 'SLA': sla, 'Opened By': opened_by, - 'Incident ID': clickable_incident_id + 'Incident ID': get_clickable_incident_id(incident_id=task.get('incidentId', '')) }) else: demisto.error(f'Failed running POST query to /v2/statistics/widgets/query.\n{str(todo_tasks_query_res)}') diff --git a/Packs/CommonWidgets/Scripts/MyToDoTasksWidget/MyToDoTasksWidget.yml b/Packs/CommonWidgets/Scripts/MyToDoTasksWidget/MyToDoTasksWidget.yml index 3800bfec00f9..3c0fcc694ef5 100644 --- a/Packs/CommonWidgets/Scripts/MyToDoTasksWidget/MyToDoTasksWidget.yml +++ b/Packs/CommonWidgets/Scripts/MyToDoTasksWidget/MyToDoTasksWidget.yml @@ -9,7 +9,7 @@ tags: timeout: '0' type: python subtype: python3 -dockerimage: demisto/python3:3.10.13.83255 +dockerimage: demisto/python3:3.10.14.97100 fromversion: 6.1.0 tests: - No test diff --git a/Packs/CommonWidgets/Scripts/MyToDoTasksWidget/MyToDoTasksWidget_test.py b/Packs/CommonWidgets/Scripts/MyToDoTasksWidget/MyToDoTasksWidget_test.py index 6e90c90ebba5..6b346f64d177 100644 --- a/Packs/CommonWidgets/Scripts/MyToDoTasksWidget/MyToDoTasksWidget_test.py +++ b/Packs/CommonWidgets/Scripts/MyToDoTasksWidget/MyToDoTasksWidget_test.py @@ -1,7 +1,8 @@ import json import demistomock as demisto -from MyToDoTasksWidget import get_open_to_do_tasks_of_current_user +from MyToDoTasksWidget import get_open_to_do_tasks_of_current_user, get_clickable_incident_id +import pytest def test_open_to_do_tasks_of_current_user(mocker): @@ -91,3 +92,18 @@ def test_no_open_to_do_tasks(mocker): table = get_open_to_do_tasks_of_current_user() assert len(table) == 0 + + +@pytest.mark.parametrize('is_xsoar_8_or_xsiam', [True, False]) +def test_clickable_incident_id(mocker, is_xsoar_8_or_xsiam): + ''' + Given: + - incident id to create clickable_incident_id + When: + - Running clickable_incident_id in XSIAM/XSOAR 8 and XSOAR 6 + Then: + - Ensure '#/' is in the created link only in XSOAR 6. + ''' + import MyToDoTasksWidget + mocker.patch.object(MyToDoTasksWidget, 'is_xsiam_or_xsoar_saas', return_value=is_xsoar_8_or_xsiam) + assert ('#/' in get_clickable_incident_id('1234')) == (not is_xsoar_8_or_xsiam) diff --git a/Packs/CommonWidgets/pack_metadata.json b/Packs/CommonWidgets/pack_metadata.json index afa0813db697..0ca859d3be24 100644 --- a/Packs/CommonWidgets/pack_metadata.json +++ b/Packs/CommonWidgets/pack_metadata.json @@ -2,7 +2,7 @@ "name": "Common Widgets", "description": "Frequently used widgets pack.", "support": "xsoar", - "currentVersion": "1.2.50", + "currentVersion": "1.2.51", "author": "Cortex XSOAR", "url": "https://www.paloaltonetworks.com/cortex", "email": "",